]> gitweb.fluxo.info Git - ckandumper.git/commitdiff
Record argument and duration
authorSilvio Rhatto <rhatto@riseup.net>
Wed, 22 May 2019 17:35:33 +0000 (14:35 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Wed, 22 May 2019 17:35:33 +0000 (14:35 -0300)
ckandumper

index 48967becc492f2d32f80eadf8e280b047e351422..928e11a04928624e5bbad8273b5dc54d7ab2c457 100755 (executable)
@@ -164,7 +164,7 @@ class CkanDumper:
 
     def __init__(self, args):
         self.url          = args.url[0]
-        self.dest         = args.dest[0]
+        self.dest         = ''.join(args.dest)
         self.package_list = '/api/3/action/package_list'
         self.package_show = '/api/3/action/package_show?'
         self.group_list   = '/api/3/action/group_list'
@@ -352,13 +352,29 @@ if __name__ == "__main__":
     try:
         start_time = time.time()
 
+        # Initialize our dumper
         ckan = CkanDumper(args)
+
+        # Record date and invocation
+        logs = ''.join(args.dest) + os.sep + 'logs' + os.sep
+        ckan.download.ensuredir(logs)
+        invocation = open(logs + 'ckandumper.args', 'a')
+        invocation.write(str(datetime.datetime.now()) + '\t' + ' '.join(sys.argv) + '\n')
+        invocation.close()
+
+        # Download everything we can
         ckan.dump()
 
-        interval = round(time.time() - start_time)
+        # Calculate runtime
+        end_time = time.time()
+        interval = round(end_time - start_time)
         duration = str(datetime.timedelta(seconds=interval))
 
+        # Record duration
         print(f'Done. Elapsed time: {duration}')
+        elapsed = open(logs + 'ckandumper.duration', 'a')
+        elapsed.write(str(start_time) + '\t' + str(end_time) + '\t' + duration)
+        elapsed.close()
     except (FileNotFoundError, KeyboardInterrupt, subprocess.CalledProcessError) as e:
         print(e)
         exit(1)