class BasicTestCase(unittest.TestCase): """ Class for Basic Test for piwigotools """ def setUp(self): self.url = "http://mygallery.piwigo.com/" self.usertest = 'USERTEST' self.passwordtest = 'xxxxxx' self.piwigo = Piwigo(self.url) def test_basic(self): self.assertTrue(self.piwigo.pwg.getVersion()) def test_checkLogin(self): self.assertTrue(self.piwigo.login(self.usertest, self.passwordtest)) self.assertTrue(self.piwigo.logout()) self.assertRaises(LoginException, self.piwigo.mkdir) self.assertRaises(LoginException, self.piwigo.makedirs) self.assertRaises(LoginException, self.piwigo.upload) def test_createCategory(self): self.piwigo.login(self.usertest, self.passwordtest) self.assertTrue(self.piwigo.mkdir('level')) self.assertTrue(self.piwigo.mkdir('level / sublevel')) self.assertTrue(self.piwigo.makedirs('level2 / sublevel2')) self.piwigo.removedirs('level2') self.piwigo.removedirs('level') self.piwigo.logout() def test_checkpath(self): self.piwigo.login(self.usertest, self.passwordtest) self.piwigo.mkdir('level') self.assertTrue(self.piwigo.iscategory('level')) self.assertTrue(self.piwigo.iscategory('level /')) self.piwigo.removedirs('level') self.piwigo.logout() def test_removeCategory(self): self.piwigo.login(self.usertest, self.passwordtest) self.piwigo.makedirs('level2 / sublevel2') self.assertTrue(self.piwigo.removedirs('level2')) self.assertFalse(self.piwigo.iscategory('level2')) self.piwigo.logout() def test_uploadImage(self): self.piwigo.login(self.usertest, self.passwordtest) self.piwigo.mkdir('level') img = os.path.join(os.path.dirname(os.path.abspath(__file__)),'samplepiwigotools.jpg') id = self.piwigo.upload(image=img, path="level") self.assertTrue(id) self.assertTrue(self.piwigo.isimage('level / samplepiwigotools.jpg')) self.piwigo.pwg.images.delete(image_id=id, pwg_token=self.piwigo.token) self.piwigo.removedirs('level') self.piwigo.logout() def test_removeImage(self): self.piwigo.login(self.usertest, self.passwordtest) self.piwigo.mkdir('level') img = os.path.join(os.path.dirname(os.path.abspath(__file__)),'samplepiwigotools.jpg') id = self.piwigo.upload(image=img, path="level") self.assertTrue(self.piwigo.remove('level / samplepiwigotools.jpg')) self.assertFalse(self.piwigo.isimage('level / samplepiwigotools.jpg')) self.piwigo.removedirs('level') self.piwigo.logout() def test_sublevel(self): self.piwigo.login(self.usertest, self.passwordtest) self.piwigo.makedirs('level2 / sublevel2') self.assertTrue(len(self.piwigo.sublevels('level2'))) self.piwigo.removedirs('level2') self.piwigo.logout() def test_downloadImage(self): self.piwigo.login(self.usertest, self.passwordtest) self.piwigo.mkdir('level') img = os.path.join(os.path.dirname(os.path.abspath(__file__)),'samplepiwigotools.jpg') id = self.piwigo.upload(image=img, path="level") imgdst = os.path.join(os.path.dirname(os.path.abspath(__file__)),'download.jpg') self.assertTrue(self.piwigo.download("level / samplepiwigotools.jpg",imgdst)) os.remove(imgdst) self.piwigo.remove('level / samplepiwigotools.jpg') self.piwigo.removedirs('level') self.piwigo.logout()
class BasicTestCase(unittest.TestCase): """ Class for Basic Test for piwigotools """ def setUp(self): self.url = "http://mygallery.piwigo.com/" self.usertest = 'USERTEST' self.passwordtest = 'xxxxxx' self.piwigo = Piwigo(self.url) def test_basic(self): self.assertTrue(self.piwigo.pwg.getVersion()) def test_checkLogin(self): self.assertTrue(self.piwigo.login(self.usertest, self.passwordtest)) self.assertTrue(self.piwigo.logout()) self.assertRaises(LoginException, self.piwigo.mkdir) self.assertRaises(LoginException, self.piwigo.makedirs) self.assertRaises(LoginException, self.piwigo.upload) def test_createCategory(self): self.piwigo.login(self.usertest, self.passwordtest) self.assertTrue(self.piwigo.mkdir('level')) self.assertTrue(self.piwigo.mkdir('level / sublevel')) self.assertTrue(self.piwigo.makedirs('level2 / sublevel2')) self.piwigo.removedirs('level2') self.piwigo.removedirs('level') self.piwigo.logout() def test_checkpath(self): self.piwigo.login(self.usertest, self.passwordtest) self.piwigo.mkdir('level') self.assertTrue(self.piwigo.iscategory('level')) self.assertTrue(self.piwigo.iscategory('level /')) self.piwigo.removedirs('level') self.piwigo.logout() def test_removeCategory(self): self.piwigo.login(self.usertest, self.passwordtest) self.piwigo.makedirs('level2 / sublevel2') self.assertTrue(self.piwigo.removedirs('level2')) self.assertFalse(self.piwigo.iscategory('level2')) self.piwigo.logout() def test_uploadImage(self): self.piwigo.login(self.usertest, self.passwordtest) self.piwigo.mkdir('level') img = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'samplepiwigotools.jpg') id = self.piwigo.upload(image=img, path="level") self.assertTrue(id) self.assertTrue(self.piwigo.isimage('level / samplepiwigotools.jpg')) self.piwigo.pwg.images.delete(image_id=id, pwg_token=self.piwigo.token) self.piwigo.removedirs('level') self.piwigo.logout() def test_removeImage(self): self.piwigo.login(self.usertest, self.passwordtest) self.piwigo.mkdir('level') img = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'samplepiwigotools.jpg') id = self.piwigo.upload(image=img, path="level") self.assertTrue(self.piwigo.remove('level / samplepiwigotools.jpg')) self.assertFalse(self.piwigo.isimage('level / samplepiwigotools.jpg')) self.piwigo.removedirs('level') self.piwigo.logout() def test_sublevel(self): self.piwigo.login(self.usertest, self.passwordtest) self.piwigo.makedirs('level2 / sublevel2') self.assertTrue(len(self.piwigo.sublevels('level2'))) self.piwigo.removedirs('level2') self.piwigo.logout() def test_downloadImage(self): self.piwigo.login(self.usertest, self.passwordtest) self.piwigo.mkdir('level') img = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'samplepiwigotools.jpg') id = self.piwigo.upload(image=img, path="level") imgdst = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'download.jpg') self.assertTrue( self.piwigo.download("level / samplepiwigotools.jpg", imgdst)) os.remove(imgdst) self.piwigo.remove('level / samplepiwigotools.jpg') self.piwigo.removedirs('level') self.piwigo.logout()
def main(): usage = USAGE parser = OptionParser(version="%s %s" % (PROG,VERSION), usage=usage) parser.description= DESCRIPTION parser.epilog = AUTHOR try: add_dynamic_option(parser) (options, args) = parser.parse_args() verb = args[0] if verb == 'ws': piwigo = Piwigo(url=options.url) if 'user' and 'password' in options.__dict__: piwigo.login(options.user, options.password) kw = purge_kw(options.__dict__,('user','password','url')) pp = pprint.PrettyPrinter(indent=4) pp.pprint(Ws(piwigo, options.method)(**kw)) if piwigo.islogged: piwigo.logout() if verb == "download": ana = Analyse('Analyze') ana.start() try: piwigo = Piwigo(url=options.url) piwigo.login(options.user, options.password) # check if not os.path.isdir(options.dest): os.makedirs(options.dest) options.dest = os.path.abspath(options.dest) piwigo.iscategory(options.category) if options.category[-2:] == ' /' : options.category = options.category[:-2] # treatment run = Run(verb, options.thread) kw = purge_kw(options.__dict__,('user','password','url','dest','category','thread')) for img in piwigo.images(options.category, **kw): run.add(piwigo.download, ["%s / %s" % (options.category, str(img)), "%s%s%s" % (options.dest, os.path.sep, str(img))], kw) except Exception as e: ana.stop() raise e ana.stop() run.start() piwigo.logout() if run.error: parser.error(run.strerror) if verb == "upload": ana = Analyse('Analyze') ana.start() try: piwigo = Piwigo(url=options.url) piwigo.login(options.user, options.password) # check piwigo.makedirs(options.category) # treatment run = Run(verb, options.thread) kw = purge_kw(options.__dict__,('user','password','url','source','category','thread')) for img in glob.glob(options.source): run.add(piwigo.upload, [os.path.abspath(img), options.category], kw) ana.stop() except Exception as e: ana.stop() raise e run.start() piwigo.logout() if run.error: parser.error(run.strerror) if verb == "sync-up": 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) if len(options.category) and options.category[-1] != '/' and options.category[:-3] != ' / ': options.category = options.category+ ' / ' # treatment run = Run(verb, options.thread) kw = purge_kw(options.__dict__,('user','password','url','source','category','thread')) # local -> piwigo for root, dirnames, filenames in os.walk(options.source): filtering = fnmatch.filter(filenames, options.extension.split(',')[0]) for ext in options.extension.split(',')[1:]: filtering = filtering + fnmatch.filter(filenames, ext) for filename in filtering: pathrel = os.path.abspath(os.path.join(root, filename))[len(options.source)+1:] pathabs = os.path.abspath(os.path.join(root, filename)) category = options.category + ' / '.join(pathrel.split(os.sep)[:-1]) if not piwigo.isimage(category + ' / ' + filename): run.add(piwigo.makedirs,[category,], kw) run.add(piwigo.upload,[pathabs, category], kw) ana.stop() except Exception as e: ana.stop() raise e run.start() piwigo.logout() if run.error: parser.error(run.strerror) if verb == "sync-down": 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) if len(options.category) and options.category[-1] != '/' and options.category[:-3] != ' / ': options.category = options.category+ ' / ' # treatment run = Run(verb, options.thread) kw = purge_kw(options.__dict__,('user','password','url','source','category','thread')) # piwigo -> local for category, item in piwigo.plan.iteritems(): if options.category == category[0:len(options.category)]: path = os.path.join(options.source, *category[len(options.category):].split(' / ')) if not os.path.exists(path): os.makedirs(path) for img in piwigo.images(category): pathimg = os.path.join(path, img) if not os.path.exists(pathimg): run.add(piwigo.download, ["%s / %s" % (category, str(img)), pathimg], kw) 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)
def main(): usage = USAGE parser = OptionParser(version="%s %s" % (PROG, VERSION), usage=usage) parser.description = DESCRIPTION parser.epilog = AUTHOR try: add_dynamic_option(parser) (options, args) = parser.parse_args() verb = args[0] if verb == 'ws': piwigo = Piwigo(url=options.url) if 'user' and 'password' in options.__dict__: piwigo.login(options.user, options.password) kw = purge_kw(options.__dict__, ('user', 'password', 'url')) pp = pprint.PrettyPrinter(indent=4) pp.pprint(Ws(piwigo, options.method)(**kw)) if piwigo.islogged: piwigo.logout() if verb == "download": ana = Analyse('Analyze') ana.start() try: piwigo = Piwigo(url=options.url) piwigo.login(options.user, options.password) # check if not os.path.isdir(options.dest): os.makedirs(options.dest) options.dest = os.path.abspath(options.dest) piwigo.iscategory(options.category) if options.category[-2:] == ' /': options.category = options.category[:-2] # treatment run = Run(verb, options.thread) kw = purge_kw( options.__dict__, ('user', 'password', 'url', 'dest', 'category', 'thread')) for img in piwigo.images(options.category, **kw): run.add(piwigo.download, [ "%s / %s" % (options.category, str(img)), "%s%s%s" % (options.dest, os.path.sep, str(img)) ], kw) except Exception as e: ana.stop() raise e ana.stop() run.start() piwigo.logout() if run.error: parser.error(run.strerror) if verb == "upload": ana = Analyse('Analyze') ana.start() try: piwigo = Piwigo(url=options.url) piwigo.login(options.user, options.password) # check piwigo.makedirs(options.category) # treatment run = Run(verb, options.thread) kw = purge_kw(options.__dict__, ('user', 'password', 'url', 'source', 'category', 'thread')) for img in glob.glob(options.source): run.add(piwigo.upload, [os.path.abspath(img), options.category], kw) ana.stop() except Exception as e: ana.stop() raise e run.start() piwigo.logout() if run.error: parser.error(run.strerror) if verb == "sync-up": 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) if len(options.category) and options.category[ -1] != '/' and options.category[:-3] != ' / ': options.category = options.category + ' / ' # treatment run = Run(verb, options.thread) kw = purge_kw(options.__dict__, ('user', 'password', 'url', 'source', 'category', 'thread')) # local -> piwigo for root, dirnames, filenames in os.walk(options.source): filtering = fnmatch.filter(filenames, options.extension.split(',')[0]) for ext in options.extension.split(',')[1:]: filtering = filtering + fnmatch.filter(filenames, ext) for filename in filtering: pathrel = os.path.abspath(os.path.join( root, filename))[len(options.source) + 1:] pathabs = os.path.abspath(os.path.join(root, filename)) category = options.category + ' / '.join( pathrel.split(os.sep)[:-1]) if not piwigo.isimage(category + ' / ' + filename): run.add(piwigo.makedirs, [ category, ], kw) run.add(piwigo.upload, [pathabs, category], kw) ana.stop() except Exception as e: ana.stop() raise e run.start() piwigo.logout() if run.error: parser.error(run.strerror) if verb == "sync-down": 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) if len(options.category) and options.category[ -1] != '/' and options.category[:-3] != ' / ': options.category = options.category + ' / ' # treatment run = Run(verb, options.thread) kw = purge_kw(options.__dict__, ('user', 'password', 'url', 'source', 'category', 'thread')) # piwigo -> local for category, item in piwigo.plan.iteritems(): if options.category == category[0:len(options.category)]: path = os.path.join( options.source, *category[len(options.category):].split(' / ')) if not os.path.exists(path): os.makedirs(path) for img in piwigo.images(category): pathimg = os.path.join(path, img) if not os.path.exists(pathimg): run.add(piwigo.download, [ "%s / %s" % (category, str(img)), pathimg ], kw) 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)