Esempio n. 1
0
def cmd_autostop(*args):
	'''turn on/off automatic stop on completion
....$autostop [on|off]'''
	if len(args) == 0:
		return 'Autostop on completion is ' + dynamics.get('autostop', 'not set')
	elif len(args) == 1 and args[0].lower() in ['on', 'off']:
		dynamics['autostop'] = args[0].lower()
		dynamics.sync()
		return "Automatic stop on completion has been turned " + args[0].lower()
	else:
		return "Oops, invalid arguments, type $help for more"
Esempio n. 2
0
def cmd_notify(*args):
	'''turn on/off notification on completion or feed updates
....$notify [on|off]'''
	if len(args) == 0:
		return 'Notify is ' + dynamics.get('notify', 'not set')
	elif len(args) == 1 and args[0].lower() in ['on', 'off']:
		dynamics['notify'] = args[0].lower()
		dynamics.sync()
		return "Notify has been turned " + args[0].lower()
	else:
		return "Oops, invalid arguments, type $help for more"
Esempio n. 3
0
def cmd_config(*args):
	"""manage dynamic configurations
....$config dump
....$config load '<json_string>'"""
	if len(args) not in [1,2]:
		return "Oops, wrong number of arguments, type $help for more"	

	if len(args) == 1 and args[0].lower() == 'dump':
		return dynamics.dumps()
	elif len(args) == 2 and args[0].lower() == 'load':
		try:
			dynamics.loads(args[1])
			dynamics.sync()
			return 'Configuration loaded successfully'
		except:
			return 'JSON format error'
	else:
		return "Invalid arguments, type $help for more"
Esempio n. 4
0
def cmd_queue(*args):
	'''manage item queue discovered from subscribed feeds  	
....$queue list
....$queue download <ids>|all
....$queue remove <ids>|all'''

	if len(args) not in [1,2]:
		return "Oops, wrong number of arguments, type $help for more"	

	resp = ''
	if len(args) == 1 and args[0].lower() == 'list':
		resp += 'ID  Published  Title\n'
		if dynamics.get('queue', {}) == {}:
			return 'Queue is empty'
		
		#when json loaded to dict, it's not sorted by key
		sorted_ids = [int(x) for x in dynamics['queue'].keys()]
		sorted_ids.sort()
		for k in sorted_ids:
			v = dynamics['queue'][str(k)]
			resp += "%s  %-s  %-s\n" %(k, v['published'], v['title'])
		
		return resp

	elif len(args) == 2 and args[0].lower() == 'download':
		if dynamics.get('queue', {}) == {}:
			return 'Queue is empty'
				
		if args[1].lower() == 'all':
			ids_to_dl = dynamics['queue'].keys()
		else:
			ids_to_dl = args[1].split(',')

		ids_downloading = []
		for _id in ids_to_dl:
			if dynamics['queue'].has_key(_id):
				TransmissionClient.add_uri(dynamics['queue'][_id]['torrent_uri'])
				ids_downloading.append(_id)
				del dynamics['queue'][_id]

		dynamics.sync()

		if ids_downloading:
			return "Started downloading item %s" % (','.join(sort_as_int(ids_downloading)))
		else:
			return "No download started"

	elif len(args) == 2 and args[0].lower() == 'remove':
		if dynamics.get('queue', {}) == {}:
			return 'Queue is empty'
				
		if args[1].lower() == 'all':
			ids_to_rm = dynamics['queue'].keys()
		else:
			ids_to_rm = args[1].split(',')

		ids_removed = []
		for _id in ids_to_rm:
			if dynamics['queue'].has_key(_id):
				ids_removed.append(_id)
				del dynamics['queue'][_id]

		dynamics.sync()

		if ids_removed:
			return "Removed item %s" % (','.join(sort_as_int(ids_removed)))
		else:
			return "No item removed"

	else:
		return "Oops, invalid arguments, type $help for more"
Esempio n. 5
0
def cmd_feed(*args):
	'''manage subscriptions of bittorrent feeds 	
....$feed list
....$feed subscribe <feed_url>
....$feed unsubscribe <ids>|all
....$feed enable|disable <ids>|all'''

	if len(args) not in [1,2]:
		return "Oops, wrong number of arguments, type $help for more"	

	resp = ''
	if len(args) == 1 and args[0].lower() == 'list':
		resp += 'ID  Status  Title  LastPublished  URL\n'
		if dynamics.get('feeds', {}) == {}:
			return 'No feeds yet'
		
		#when json loaded to dict, it's not sorted by key
		sorted_ids = [int(x) for x in dynamics['feeds'].keys()]
		sorted_ids.sort()
		for k in sorted_ids:
			v = dynamics['feeds'][str(k)]
			resp += "%s  %s  %s  %s  %s\n" %(k, v['status'], v['title'], v['last_published'], v['url'])
		
		return resp

	elif len(args) == 2 and args[0].lower() == 'subscribe':
		maxid = 0
		url = args[1]
		if not dynamics.has_key('feeds'):
			dynamics['feeds'] = {}
		elif dynamics['feeds'].keys():
			maxid = max([int(x) for x in dynamics['feeds'].keys()])	

		info, f = feed.fetch_feed(url)
		dynamics['feeds'][str(maxid+1)] = {	'title':info['title'],
											'status': 'enabled',
								 	  		'last_published': feed.encode_time(info['last_published']),
								 	  		'etag':info['etag'],
								 	  		'modified':info['modified'],
								 	  		'url':url }
		dynamics.sync()
		return "Feed '%s' subscribed successfully" % (info['title'])

	elif len(args) == 2 and args[0].lower() == 'unsubscribe':
		if dynamics.get('feeds', {}) == {}:
			return 'Feed list is empty'
				
		if args[1].lower() == 'all':
			ids_to_delete = dynamics['feeds'].keys()
		else:
			ids_to_delete = args[1].split(',')

		ids_deleted = []
		for _id in ids_to_delete:
			if dynamics['feeds'].has_key(_id):
				del dynamics['feeds'][_id]
				ids_deleted.append(_id)

		dynamics.sync()

		if ids_deleted:
			return "Feed %s unsubscribed" % (','.join(sort_as_int(ids_deleted)))
		else:
			return "Feed list is empty"
	elif len(args) == 2 and args[0].lower() in ('enable','disable'):
		stat = args[0].lower() + 'd'
		if dynamics.get('feeds', {}) == {}:
			return 'No feeds yet'
		if args[1].lower() == 'all':
			ids_to_op = dynamics['feeds'].keys()
		else:
			ids_to_op = args[1].split(',')

		ids_done = []
		for _id in ids_to_op:
			if dynamics['feeds'].has_key(_id):
				dynamics['feeds'][_id]['status'] = stat
				ids_done.append(_id)

		dynamics.sync()

		if ids_done:
			return "Feed %s %s" % (','.join(sort_as_int(ids_done)), stat)
		else:
			return "Feed list is empty"	
	else:
		return "Oops, invalid arguments, type $help for more"