def main() : (cli_parser, config_dict, argv_list) = config.partialParser(sys.argv[1:], description="Show the difference between two torrent files") config.addArguments(cli_parser, config.ARG_TIMEOUT, config.ARG_CLIENT, config.ARG_CLIENT_URL, config.ARG_NO_COLORS, config.ARG_USE_COLORS, config.ARG_FORCE_COLORS, config.ARG_NO_FORCE_COLORS, ) cli_parser.add_argument("torrents_list", type=str, nargs=2, metavar="<path/hash>") cli_options = cli_parser.parse_args(argv_list) config.syncParsers(config.SECTION_RTDIFF, cli_options, config_dict) socket.setdefaulttimeout(cli_options.socket_timeout) client = None if not cli_options.client_name is None : client_class = clients.CLIENTS_MAP[cli_options.client_name] client = client_class(cli_options.client_url) hash_regexp = re.compile(r"[\da-fA-F]{40}") for count in xrange(2) : item = cli_options.torrents_list[count] if os.path.exists(item) : cli_options.torrents_list[count] = tfile.Torrent(item).files() elif hash_regexp.match(item) : if client is None : raise RuntimeError("Required client for hash: %s" % (item)) cli_options.torrents_list[count] = client.files(item) else : raise RuntimeError("Invalid file or hash: %s" % (item)) tfile.printDiff(tfile.diff(*cli_options.torrents_list), " ", use_colors_flag=(not cli_options.no_colors_flag), force_colors_flag=cli_options.force_colors_flag, )
def update(fetchers_list, client, src_dir_path, backup_dir_path, names_filter, save_customs_list, skip_unknown_flag, pass_failed_login_flag, show_passed_flag, show_diff_flag, real_update_flag, no_colors_flag, force_colors_flag, ) : invalid_count = 0 not_in_client_count = 0 unknown_count = 0 passed_count = 0 updated_count = 0 error_count = 0 torrents_list = torrents(src_dir_path, names_filter) hashes_list = ( client.hashes() if not client is None else [] ) if not no_colors_flag : colored = ( lambda codes_list, text : ulib.tools.term.colored(codes_list, text, force_colors_flag) ) else : colored = ( lambda codes_list, text : text ) make_fail = ( lambda text : (colored(31, "!"), colored(31, text)) ) for (count, (torrent_file_name, torrent)) in enumerate(torrents_list) : status_line = "[%%s] %s %%s %s" % (tools.fmt.formatProgress(count + 1, len(torrents_list)), torrent_file_name) if torrent is None : tools.cli.newLine(status_line % (make_fail("INVALID_TORRENT"))) invalid_count += 1 continue status_line += " --- %s" % (torrent.comment() or "") if not client is None and not torrent.hash() in hashes_list : tools.cli.newLine(status_line % (make_fail("NOT_IN_CLIENT"))) not_in_client_count += 1 continue fetcher = fetcherlib.selectFetcher(torrent, fetchers_list) if fetcher is None : unknown_count += 1 if not skip_unknown_flag : tools.cli.newLine(status_line % (make_fail("UNKNOWN"))) continue status_line = status_line % ("%s", fetcher.plugin()) try : if not fetcher.loggedIn() : tools.cli.newLine(status_line % (colored(33, "?"))) error_count += 1 continue if not fetcher.torrentChanged(torrent) : tools.cli.oneLine(status_line % (" "), not show_passed_flag) passed_count += 1 continue diff_tuple = updateTorrent(torrent, fetcher, backup_dir_path, client, save_customs_list, real_update_flag) tools.cli.newLine(status_line % (colored(32, "+"))) if show_diff_flag : tfile.printDiff(diff_tuple, "\t", use_colors_flag=(not no_colors_flag), force_colors_flag=force_colors_flag) updated_count += 1 except fetcherlib.CommonFetcherError, err : tools.cli.newLine((status_line + " :: %s(%s)") % (colored(31, "-"), type(err).__name__, str(err))) error_count += 1 except Exception, err : tools.cli.newLine(status_line % ("-")) tools.cli.printTraceback("\t") error_count += 1