def rclone_cmd(cmd, p1=None, p2=None, options=None, linenum=0): for x in range(maxTries): process_args = [rclone, cmd] if p1 is not None: process_args.append(p1) if p2 is not None: process_args.append(p2) if options is not None: process_args.extend(options) # print (process_args) # if not subprocess.call(process_args): # Prior implementation, replaced with Popen call below - v2.5. # return 0 try: if platform.system() is "Windows" and sys.version_info[0] < 3: # On Windows and Python 2.7, the subprocess module only support ASCII in the process_args # argument. The win_subprocess mdoule supports extended characters (UTF-8), which is needed # when file and directory names contain extended characters. However, win_subprocess # requires both shell=True and valid output files. with io.open(workdir + "deleteme.txt", "wt") as of: p = win_subprocess.Popen(process_args, stdout=of, stderr=of, shell=True) else: p = subprocess.Popen(process_args) p.wait() if p.returncode == 0: return 0 except Exception as e: logging.warning(print_msg(u"WARNING", "rclone {} try {} failed.".format(cmd, x+1), p1)) logging.error("message: <{}>".format(e)) logging.error(print_msg(u"ERROR", "rclone {} failed. (Line {})".format(cmd, linenum), p1)) return 1
def rclone_lsl(path, ofile, options=None, linenum=0): for x in range(MAXTRIES): with io.open(ofile, "wt", encoding='utf8') as of: process_args = [rclone, "lsl", path, "--config", rcconfig] if options is not None: process_args.extend(options) if args.rclone_args is not None: process_args.extend(args.rclone_args) if is_Windows_Py27: p = win_subprocess.Popen(process_args, stdout=of, shell=True) out, err = p.communicate() if not err: return (0) else: if not subprocess.call(process_args, stdout=of): return 0 logging.info( print_msg("WARNING", "rclone lsl try {} failed.".format(x + 1))) logging.error( print_msg( "ERROR", "rclone lsl failed. Specified path invalid? (Line {})". format(linenum))) return 1
def rclone_cmd(cmd, p1=None, p2=None, options=None, linenum=0): process_args = [rclone, cmd, "--config", rcconfig] if p1 is not None: process_args.append(p1) if p2 is not None: process_args.append(p2) if options is not None: process_args.extend(options) if args.rclone_args is not None: process_args.extend(args.rclone_args) logging.debug(" rclone command: {}".format(process_args)) for x in range(MAXTRIES): try: if is_Windows_Py27: # On Windows and Python 2.7, the subprocess module only support ASCII in the process_args # argument. The win_subprocess mdoule supports extended characters (UTF-8), which is needed # when file and directory names contain extended characters. However, win_subprocess # requires both shell=True and valid output files. with io.open(workdir + "deleteme.txt", "wt") as of: p = win_subprocess.Popen(process_args, stdout=of, stderr=of, shell=True) else: p = subprocess.Popen(process_args) p.wait() if p.returncode == 0: return 0 except Exception as e: # logging.warning(print_msg("WARNING", "rclone {} try {} failed.".format(cmd, x+1), p1)) logging.info( print_msg("WARNING", "rclone {} try {} failed.".format(cmd, x + 1), p1)) logging.info("message: <{}>".format(e)) logging.error( print_msg("ERROR", "rclone {} failed. (Line {})".format(cmd, linenum), p1)) return 1