From a58e060d8ade23d04f5563105baec440c2e39ab2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Thu, 8 Sep 2016 17:16:56 +0800 Subject: [PATCH] Changed the argument order so that no argument is required for simplest situation. Library name is taken from the directory name in such a case. Added -r in additional to --run. Fixed to load the library first before checking out the modules. --- oobsync.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/oobsync.py b/oobsync.py index a626aa0..806bf99 100755 --- a/oobsync.py +++ b/oobsync.py @@ -33,19 +33,25 @@ def parse_args(): global args parser = argparse.ArgumentParser(description="Synchronize the local Basic scripts with OpenOffice Basic.") - parser.add_argument("library", metavar="Library", - help="The Library to upload/download the macros.") parser.add_argument("projdir", metavar="dir", nargs="?", default=os.getcwd(), help="The project source directory (default to the current directory).") + parser.add_argument("library", metavar="Library", nargs="?", + help="The Library to upload/download the macros (default to the name of the directory).") parser.add_argument("--get", action="store_true", help="Downloads the macros instead of upload.") - parser.add_argument("--run", metavar="Module.Macro", + parser.add_argument("-r", "--run", metavar="Module.Macro", help="The macro to run after the upload, if any.") parser.add_argument("-v", "--version", - action="version", version="%(prog)s 1.0") + action="version", version="%(prog)s 0.1") args = parser.parse_args() + # Obtains the absolute path + args.projdir = os.path.abspath(args.projdir) + # Obtains the library name from the path + if args.library == None: + args.library = os.path.basename(args.projdir) + return def sync_macros(oo): @@ -125,6 +131,7 @@ def read_basic_modules(libraries, libname): modules = {} if not libraries.hasByName(libname): return modules + libraries.loadLibrary(libname) library = libraries.getByName(libname) for modname in library.getElementNames(): modules[modname] = library.getByName(modname).encode("utf-8") @@ -140,6 +147,7 @@ def update_basic_modules(libraries, libname, modules): library.insertByName(modname, modules[modname]) print >> sys.stderr, "Module " + modname + " added." else: + libraries.loadLibrary(libname) library = libraries.getByName(libname) curmods = sorted(library.getElementNames()) for modname in sorted(modules.keys()):