Beispiel #1
0
def main() :
	(cli_parser, config_dict, argv_list) = config.partialParser(sys.argv[1:], description="Add torrent to the data model \"t.data\"")
	config.addArguments(cli_parser,
		config.ARG_MKDIR_MODE,
		config.ARG_DATA_DIR,
		config.ARG_SOURCE_DIR,
		config.ARG_TIMEOUT,
		config.ARG_CLIENT,
		config.ARG_CLIENT_URL,
		config.ARG_SET_CUSTOMS,
	)
	cli_parser.add_argument("--link-to", dest="link_to_path", action="store", default=None, metavar="<path>")
	cli_parser.add_argument("torrents_list", type=str, nargs="+")
	cli_options = cli_parser.parse_args(argv_list)
	config.syncParsers(config.SECTION_RTLOAD, cli_options, config_dict)

	if len(cli_options.torrents_list) > 1 and not cli_options.link_to_path is None :
		print >> sys.stderr, "Option -l/--link-to be used with only one torrent"
		sys.exit(1)
	if cli_options.client_name is None :
		print >> sys.stderr, "Required client"
		sys.exit(1)

	socket.setdefaulttimeout(cli_options.socket_timeout)

	client = clientlib.initClient(
		clients.CLIENTS_MAP[cli_options.client_name],
		cli_options.client_url,
		set_customs_dict=cli_options.set_customs_dict
	)

	loadTorrent(client,
		cli_options.src_dir_path,
		cli_options.torrents_list,
		cli_options.data_dir_path,
		cli_options.link_to_path,
		cli_options.mkdir_mode,
		cli_options.set_customs_dict,
	)
Beispiel #2
0
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,
	)
Beispiel #3
0
def main() :
	(cli_parser, config_dict, argv_list) = config.partialParser(sys.argv[1:], description="Show torrents metadata")
	print_options_list = []
	for (print_option, print_dest, print_method) in (
			("--path",                 "print_path_flag",                 lambda torrent : torrent.path()),
			("--name",                 "print_name_flag",                 lambda torrent : torrent.name()),
			("--hash",                 "print_hash_flag",                 lambda torrent : torrent.hash()),
			("--comment",              "print_comment_flag",              formatComment),
			("--size",                 "print_size_flag",                 lambda torrent : str(torrent.size())),
			("--size-pretty",          "print_size_pretty_flag",          formatSizePretty),
			("--announce",             "print_announce_flag",             formatAnnounce),
			("--announce-list",        "print_announce_list_flag",        formatAnnounceList),
			("--announce-list-pretty", "print_announce_list_pretty_flag", formatAnnounceListPretty),
			("--creation-date",        "print_creation_date_flag",        formatCreationDate),
			("--creation-date-pretty", "print_creation_date_pretty_flag", formatCreationDatePretty),
			("--created-by",           "print_created_by_flag",           formatCreatedBy),
			("--provides",             "print_provides_flag",             formatProvides),
			("--is-private",           "print_is_private_flag",           formatIsPrivate),
			("--is-private-pretty",    "print_is_private_pretty_flag",    formatIsPrivatePretty),
			("--client-path",          "print_client_path_flag",          lambda torrent : formatClientPath(torrent, client)),
			("--make-magnet",          "print_magnet_flag",               lambda torrent : torrent.magnet(cli_options.magnet_fields_list)),
		) :
		print_options_list.append((
				cli_parser.add_argument(print_option, dest=print_dest, action="store_true"),
				print_method,
			))
	cli_parser.add_argument("--without-headers", dest="without_headers_flag", action="store_true")
	cli_parser.add_argument("--magnet-fields",   dest="magnet_fields_list",   nargs="+",      default=None, metavar="<fields>", choices=tfile.ALL_MAGNET_FIELDS_TUPLE)
	config.addArguments(cli_parser,
		config.ARG_TIMEOUT,
		config.ARG_CLIENT,
		config.ARG_CLIENT_URL,
	)
	cli_parser.add_argument("torrents_list", type=str, nargs="+")
	cli_options = cli_parser.parse_args(argv_list)
	config.syncParsers(config.SECTION_RTFILE, cli_options, config_dict)

	socket.setdefaulttimeout(cli_options.socket_timeout)

	torrents_list = [ tfile.Torrent(item) for item in cli_options.torrents_list ]

	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)

	to_print_list = [
		(print_option.option_strings[0][2:], print_method)
		for (print_option, print_method) in print_options_list
		if getattr(cli_options, print_option.dest)
	]
	for torrent in torrents_list :
		if len(to_print_list) == 0 :
			printPrettyMeta(torrent, client)
		else :
			for (header, print_method) in to_print_list :
				prefix = ( "" if cli_options.without_headers_flag else header + ": " )
				retval = print_method(torrent)
				if isinstance(retval, (list, tuple)) :
					for item in retval :
						print prefix + item
				else :
					print prefix + retval
		if len(torrents_list) > 1 :
			print
Beispiel #4
0
def main() :
	(cli_parser, config_dict, argv_list) = config.partialParser(sys.argv[1:], description="Update rtorrent files from popular trackers")
	config.addArguments(cli_parser,
		config.ARG_SOURCE_DIR,
		config.ARG_BACKUP_DIR,
		config.ARG_NAMES_FILTER,
		config.ARG_ONLY_FETCHERS,
		config.ARG_TIMEOUT,
		config.ARG_INTERACTIVE,
		config.ARG_NO_INTERACTIVE,
		config.ARG_SKIP_UNKNOWN,
		config.ARG_NO_SKIP_UNKNOWN,
		config.ARG_PASS_FAILED_LOGIN,
		config.ARG_NO_PASS_FAILED_LOGIN,
		config.ARG_SHOW_PASSED,
		config.ARG_NO_SHOW_PASSED,
		config.ARG_SHOW_DIFF,
		config.ARG_NO_SHOW_DIFF,
		config.ARG_CHECK_VERSIONS,
		config.ARG_NO_CHECK_VERSIONS,
		config.ARG_REAL_UPDATE,
		config.ARG_NO_REAL_UPDATE,
		config.ARG_URL_RETRIES,
		config.ARG_URL_SLEEP_TIME,
		config.ARG_PROXY_URL,
		config.ARG_CLIENT,
		config.ARG_CLIENT_URL,
		config.ARG_SAVE_CUSTOMS,
		config.ARG_NO_COLORS,
		config.ARG_USE_COLORS,
		config.ARG_FORCE_COLORS,
		config.ARG_NO_FORCE_COLORS,
	)
	cli_options = cli_parser.parse_args(argv_list)
	config.syncParsers(config.SECTION_RTFETCH, cli_options, config_dict, (
			# For fetchers: validate this options later
			config.OPTION_LOGIN,
			config.OPTION_PASSWD,
			config.OPTION_URL_RETRIES,
			config.OPTION_URL_SLEEP_TIME,
			config.OPTION_PROXY_URL,
			config.OPTION_INTERACTIVE,
		))


	socket.setdefaulttimeout(cli_options.socket_timeout)

	fetchers_list = initFetchers(config_dict,
		cli_options.url_retries,
		cli_options.url_sleep_time,
		cli_options.proxy_url,
		cli_options.interactive_flag,
		cli_options.only_fetchers_list,
		cli_options.pass_failed_login_flag,
	)
	if len(fetchers_list) == 0 :
		print >> sys.stderr, "No available fetchers in config"
		sys.exit(1)
	if len(fetchers_list) != len(fetchers.FETCHERS_MAP) :
		cli_options.skip_unknown_flag = True

	if cli_options.check_versions_flag and not fetcherlib.checkVersions(fetchers_list) :
		sys.exit(1)

	print

	client = None
	if not cli_options.client_name is None :
		client = clientlib.initClient(
			clients.CLIENTS_MAP[cli_options.client_name],
			cli_options.client_url,
			save_customs_list=cli_options.save_customs_list,
		)

	update(fetchers_list, client,
		cli_options.src_dir_path,
		cli_options.backup_dir_path,
		cli_options.names_filter,
		cli_options.save_customs_list,
		cli_options.skip_unknown_flag,
		cli_options.pass_failed_login_flag,
		cli_options.show_passed_flag,
		cli_options.show_diff_flag,
		cli_options.real_update_flag,
		cli_options.no_colors_flag,
		cli_options.force_colors_flag,
	)