diff --git a/import_export_canalblog.py b/import_export_canalblog.py index a0552ee..86ffde7 100644 --- a/import_export_canalblog.py +++ b/import_export_canalblog.py @@ -129,7 +129,6 @@ def importDirectory(name_thread, max_thread, directory, logger, parser, wordpres if __name__ == '__main__': - TMP = "/tmp/import_export_canablog" parser = argparse.ArgumentParser() parser.add_argument("--debug", help="Verbosity", action="store_true") parser.add_argument("--logfile", help="Log file", default="") @@ -138,6 +137,7 @@ if __name__ == '__main__': parser.add_argument("--parallel", help="Define number thread (default : 1)", default=1) parser.add_argument("--no-ssl", help="No ssl for canalblog and/or wordpress (example wordpress,canalblog)", dest="ssl", default="") parser.add_argument("--revert", help="Restart a work from stopping work", action="store_true") + parser.add_argument("--tmp", help="directory tmp", default="/tmp/import_export_canablog") subparsers = parser.add_subparsers(dest="command") @@ -191,9 +191,6 @@ if __name__ == '__main__': default="", help="File") - - if not os.path.exists(TMP): - os.mkdir(TMP) args = parser.parse_args() @@ -229,6 +226,8 @@ if __name__ == '__main__': fileHandler.setFormatter(formatter) logger.addHandler(fileHandler) + os.makedirs(args.tmp, exist_ok=True) + if args.command == "import" or args.command == "remove": password = args.password if len(args.password) == 0: @@ -262,14 +261,16 @@ if __name__ == '__main__': wait_for = [ ex.submit(remove, i, args.parallel, args, basic, logger, ssl_wordpress) for i in range(0, int(args.parallel)) ] wait(wait_for, return_when=ALL_COMPLETED) if args.revert is True: - files_tmp = glob.glob("{0}/*.json".format(tmp)) - if len(files_tmp) > 0: - if len(files_tmp) != args.parallel: - for file_r in files_tmp: - os.remove(file_r) + files_tmp = glob.glob("{0}/*.json".format(args.tmp)) + if len(files_tmp) == 0: + logger.error("Error revert, because files not found") + exit(1) + if len(files_tmp) != int(args.parallel): + for file_r in files_tmp: + os.remove(file_r) wait_for = [ - ex.submit(importUrl, i, int(args.parallel), args.canalblog, logger, args.parser, args.wordpress, basic, args.serial, ssl_wordpress, ssl_canalblog, args.create, args.update, args.image, args.revert, TMP) + ex.submit(importUrl, i, int(args.parallel), args.canalblog, logger, args.parser, args.wordpress, basic, args.serial, ssl_wordpress, ssl_canalblog, args.create, args.update, args.image, args.revert, args.tmp) for i in range(0, int(args.parallel)) ] @@ -307,7 +308,7 @@ if __name__ == '__main__': try: with futures.ThreadPoolExecutor(max_workers=int(args.parallel)) as ex: wait_for = [ - ex.submit(download, i, int(args.parallel), url, logger, args.parser, args.directory, args.html, args.img, ssl_canalblog, args.revert, TMP) + ex.submit(download, i, int(args.parallel), url, logger, args.parser, args.directory, args.html, args.img, ssl_canalblog, args.revert, args.tmp) for i in range(0, int(args.parallel)) ] except Exception as err: