From c59f2ee1d419344b7a1bedf94fbd466b23982983 Mon Sep 17 00:00:00 2001
From: Yngve Levinsen <yngve.levinsen@ess.eu>
Date: Tue, 3 Mar 2020 12:06:53 +0100
Subject: [PATCH] syntax check of script

---
 scripts/tracewin | 70 +++++++++++++++++-------------------------------
 1 file changed, 25 insertions(+), 45 deletions(-)

diff --git a/scripts/tracewin b/scripts/tracewin
index 8545565..634be6f 100644
--- a/scripts/tracewin
+++ b/scripts/tracewin
@@ -4,7 +4,6 @@ from __future__ import print_function
 import argparse
 import os
 import shutil
-import subprocess
 
 # This script simply runs TraceWin CLI version.
 # Provides a better CLI than going through the manual
@@ -12,44 +11,29 @@ import subprocess
 
 parser = argparse.ArgumentParser(description="Creates a TraceWin batch command")
 
-parser.add_argument('-p', '--project', dest='project',
-        help="Project file", required=True)
-parser.add_argument('-r', dest='run', action='store_const',
-        help="Run TraceWin (default just print command)", const=True, default=False)
+parser.add_argument("-p", "--project", dest="project", help="Project file", required=True)
+parser.add_argument("-r", dest="run", action="store_const", help="Run TraceWin (default just print command)", const=True, default=False)
 # path_cal
-parser.add_argument('-o', '--output', dest='outpath',
-        help="Path to calculation directory")
+parser.add_argument("-o", "--output", dest="outpath", help="Path to calculation directory")
 # dat_file
-parser.add_argument('-l', '--lattice', dest='lattice',
-        help="Lattice/structure file (.dat) to use")
+parser.add_argument("-l", "--lattice", dest="lattice", help="Lattice/structure file (.dat) to use")
 # dst_file
-parser.add_argument('--dst_file', dest='dst_file1',
-        help="Input distribution file of main beam")
-parser.add_argument('--dst_file2', dest='dst_file2',
-        help="Input distribution file of secondary beam")
+parser.add_argument("--dst_file", dest="dst_file1", help="Input distribution file of main beam")
+parser.add_argument("--dst_file2", dest="dst_file2", help="Input distribution file of secondary beam")
 # current
-parser.add_argument('-c', '--current', dest='current1',
-        help="Beam Current of beam 1 [mA]")
-parser.add_argument('--current2', dest='current2',
-        help="Beam Current of beam 2 [mA]")
+parser.add_argument("-c", "--current", dest="current1", help="Beam Current of beam 1 [mA]")
+parser.add_argument("--current2", dest="current2", help="Beam Current of beam 2 [mA]")
 # nbr_part
-parser.add_argument('-np', dest='nbr_part1',
-        help="Number of particles in beam 1")
-parser.add_argument('-np2', dest='nbr_part2',
-        help="Number of particles in beam 2")
+parser.add_argument("-np", dest="nbr_part1", help="Number of particles in beam 1")
+parser.add_argument("-np2", dest="nbr_part2", help="Number of particles in beam 2")
 # energy
-parser.add_argument('-e', '--energy', dest='energy1',
-        help="Input beam energy for beam 1 [MeV]")
-parser.add_argument('-e2', dest='energy2',
-        help="Input beam energy for beam 2 [MeV]")
-# freq 
-parser.add_argument('-f', dest='freq1',
-        help="Bunch Frequency of beam 1 [MHz]")
-parser.add_argument('-f2', dest='freq2',
-        help="Bunch Frequency of beam 2 [MHz]")
+parser.add_argument("-e", "--energy", dest="energy1", help="Input beam energy for beam 1 [MeV]")
+parser.add_argument("-e2", dest="energy2", help="Input beam energy for beam 2 [MeV]")
+# freq
+parser.add_argument("-f", dest="freq1", help="Bunch Frequency of beam 1 [MHz]")
+parser.add_argument("-f2", dest="freq2", help="Bunch Frequency of beam 2 [MHz]")
 
-parser.add_argument('-s', '--seed', dest='seed',
-        help="Initial random seed", type=int)
+parser.add_argument("-s", "--seed", dest="seed", help="Initial random seed", type=int)
 
 args = parser.parse_args()
 
@@ -65,30 +49,26 @@ cmd = [binary, f"'{args.project}'", "hide_esc"]
 
 # Check that project path exist:
 if not os.path.isfile(args.project):
-    raise ValueError('Project file does not exist')
+    raise ValueError("Project file does not exist")
 
 if args.lattice:
-    cmd.append("dat_file="+args.lattice)
+    cmd.append("dat_file=" + args.lattice)
 
-for arg in ['dst_file1', 'dst_file2',
-            'current1', 'current2',
-            'nbr_part1', 'nbr_part2',
-            'energy1', 'energy2',
-            'freq1', 'freq2']:
-    attr=getattr(args,arg)
+for arg in ["dst_file1", "dst_file2", "current1", "current2", "nbr_part1", "nbr_part2", "energy1", "energy2", "freq1", "freq2"]:
+    attr = getattr(args, arg)
     if attr:
-        cmd.append(arg+"="+attr)
+        cmd.append(arg + "=" + attr)
 
 if args.outpath:
     if not os.path.isdir(args.outpath):
         print("WARNING: output directory does not exist, creating..")
         os.makedirs(args.outpath)
-    cmd.append("path_cal='"+os.path.abspath(args.outpath)+"'")
+    cmd.append("path_cal='" + os.path.abspath(args.outpath) + "'")
 if args.seed:
-    cmd.append("random_seed="+str(args.seed))
+    cmd.append("random_seed=" + str(args.seed))
 
-print(' '.join(cmd))
+print(" ".join(cmd))
 if args.run:
     # TraceWin gives error when using subprocess.call (both for shell equals True and False)
-    #subprocess.call(cmd)
+    # subprocess.call(cmd)
     os.system(" ".join(cmd))
-- 
GitLab