diff Resources/Samples/Python/AutoClassify.py @ 2075:bec08e9236f5

more robust AutoClassify.py sample
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 16 Aug 2016 12:49:38 +0200
parents 7e6afa0beaf6
children a3a65de1840f
line wrap: on
line diff
--- a/Resources/Samples/Python/AutoClassify.py	Tue Aug 16 11:28:31 2016 +0200
+++ b/Resources/Samples/Python/AutoClassify.py	Tue Aug 16 12:49:38 2016 +0200
@@ -110,13 +110,17 @@
         if change['ChangeType'] == 'NewInstance':
             try:
                 ClassifyInstance(change['ID'])
+
+                # If requested, remove the instance once it has been
+                # properly handled by "ClassifyInstance()". Thanks to
+                # the "try/except" block, the instance is not removed
+                # if the "ClassifyInstance()" function fails.
+                if args.remove:
+                    RestToolbox.DoDelete('%s/instances/%s' % (URL, change['ID']))
+
             except:
                 print('Unable to write instance %s to the disk' % change['ID'])
 
-            # If requested, remove the instance once it has been copied
-            if args.remove:
-                RestToolbox.DoDelete('%s/instances/%s' % (URL, change['ID']))
-
     current = r['Last']
 
     if r['Done']: