From 1f3728130e2c1741298cd467fbb31f99f61d3084 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ma=C3=ABl=20Madon?= <mael.madon@irit.fr>
Date: Thu, 3 Nov 2022 12:06:27 +0100
Subject: [PATCH] pretty printing and change .format to f-strings

---
 swf_to_batsim_split_by_user.py | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/swf_to_batsim_split_by_user.py b/swf_to_batsim_split_by_user.py
index 57a86a8..88fbbeb 100755
--- a/swf_to_batsim_split_by_user.py
+++ b/swf_to_batsim_split_by_user.py
@@ -62,7 +62,7 @@ def generate_workload(input_swf, output_folder,
                 submit_time = max(0, float(res.group(SwfField.SUBMIT_TIME.value)))
                 walltime = max(job_walltime_factor * run_time,
                             float(res.group(SwfField.REQUESTED_TIME.value)))
-                user_id = str(res.group(SwfField.USER_ID.value))
+                user_id = int(res.group(SwfField.USER_ID.value))
 
                 # nb_res may be changed by calling a user-given function
                 nb_res = eval(job_size_function_string)
@@ -119,19 +119,18 @@ def generate_workload(input_swf, output_folder,
             'version': version,
             'command': ' '.join(sys.argv[:]),
             'date': datetime.datetime.now().isoformat(' '),
-            'description': 'Workload for user {}'.format(user_id),
+            'description': f'Workload for user {user_id}',
             'nb_res': biggest_job,
             'jobs': djobs}
 
         try:
-            output_json = output_folder + "/user" + user_id + ".json"
-            outFile = open(output_json, 'w')
+            output_json = f"{output_folder}/user{user_id}.json"
+            out_file = open(output_json, 'w')
 
-            json.dump(data, outFile, indent=indent, sort_keys=True)
+            json.dump(data, out_file, indent=indent, sort_keys=True)
 
             if not quiet:
-                print('user {}:'.format(user_id))
-                print('   {} jobs had been created'.format(len(djobs)))
+                print(f"user{user_id:3d}: {len(djobs):10d} jobs")
 
 
         except IOError:
@@ -139,11 +138,11 @@ def generate_workload(input_swf, output_folder,
 
     if not quiet:
         print('-------------------')
-        print('Total {} jobs and {} users have been created.'.format(
-            sum([len(jobs) for jobs in users.values()]), len(users)))
-        print('{} out of {} lines in the file did not match the swf format'.format(
-            not_line_match_format, i))
-        print('{} jobs were not valid'.format(not_valid))
+        print(f"Total {sum([len(jobs) for jobs in users.values()])} jobs and "
+              f"{len(users)} users have been created.")
+        print(f"{not_line_match_format} out of {i} lines in the file did not "
+               "match the swf format")
+        print(f"{not_valid} jobs were not valid")
 
 
 def main():
-- 
GitLab