diff --git a/piwigotools/__init__.py b/piwigotools/__init__.py index c74e6e7..adf18f6 100644 --- a/piwigotools/__init__.py +++ b/piwigotools/__init__.py @@ -60,8 +60,9 @@ class Piwigo(piwigo.Piwigo): @property def plan(self): - return { i["name"] : i["id"] for i in self.pwg.categories.getList(recursive=True, fullname=True)['categories'] } - + plan = { i["name"] : i["id"] for i in self.pwg.categories.getList(recursive=True, fullname=True)['categories'] } + plan[""] = 0 + return plan def _checkarg(fn): def checking(self, *args, **kw): diff --git a/piwigotools/interface.py b/piwigotools/interface.py index dd377f2..86afc4e 100644 --- a/piwigotools/interface.py +++ b/piwigotools/interface.py @@ -70,11 +70,12 @@ class Run: ' ', progressbar.Timer()], maxval=self._qin.qsize()).start() - for thread in self._threads: - thread.start() - while not self._qout.full(): - time.sleep(0.1) # sleep 0.1s - pbar.update(self._qout.qsize()) + if self._qin.qsize(): + for thread in self._threads: + thread.start() + while not self._qout.full(): + time.sleep(0.1) # sleep 0.1s + pbar.update(self._qout.qsize()) pbar.finish() return self._qerr diff --git a/piwigotools/main.py b/piwigotools/main.py index 44d4eba..bfae269 100644 --- a/piwigotools/main.py +++ b/piwigotools/main.py @@ -35,7 +35,7 @@ VERBS = { "description" : "upload file in piwigo gallery", "arg" : { - "category" : {"type":"string", "default":"/", "help":"destination category of piwigo gallery"}, + "category" : {"type":"string", "default":"", "help":"destination category of piwigo gallery"}, "source" : {"type":"string", "default":"*.jpg", "help":"path of upload picture"}, "url" : {"type":"string", "default":"", "help":"url of piwigo gallery"}, "user" : {"type":"string", "default":"", "help":"user of piwigo gallery"}, @@ -49,7 +49,7 @@ VERBS = { "description" : "download image from piwigo gallery", "arg" : { - "category" : {"type":"string", "default":"/", "help":"source category of piwigo gallery"}, + "category" : {"type":"string", "default":"", "help":"source category of piwigo gallery"}, "dest" : {"type":"string", "default":".", "help":"path of destination"}, "url" : {"type":"string", "default":"", "help":"url of piwigo gallery"}, "user" : {"type":"string", "default":"", "help":"user of piwigo gallery"}, @@ -63,7 +63,7 @@ VERBS = { "description" : "synchronization between path and piwigo gallery", "arg" : { - "category" : {"type":"string", "default":"/", "help":"category of piwigo gallery"}, + "category" : {"type":"string", "default":"", "help":"category of piwigo gallery"}, "source" : {"type":"string", "default":".", "help":"path of picture"}, "url" : {"type":"string", "default":"", "help":"url of piwigo gallery"}, "user" : {"type":"string", "default":"", "help":"user of piwigo gallery"}, @@ -199,6 +199,28 @@ def main(): piwigo.logout() if run.error: parser.error(run.strerror) + if verb == "sync": + ana = Analyse('Analyze') + ana.start() + try: + piwigo = Piwigo(url=options.url) + piwigo.login(options.user, options.password) + # check + options.source = os.path.abspath(options.source) + if not os.path.isdir(options.source): + raise Exception("%s is not directory" % options.source) + piwigo.iscategory(options.category) + # treatment + run = Run(verb, options.thread) + kw = purge_kw(options.__dict__,('user','password','url','source','category','thread')) + ana.stop() + except Exception as e: + ana.stop() + raise e + run.start() + piwigo.logout() + if run.error: + parser.error(run.strerror) except Exception as e: parser.error(e) sys.exit(1)