Ejemplo n.º 1
0
class TvShowWatch():
	def __init__(self, debug = False):
		self.debug = debug != False
		self.auth = False
		self.m = TSWmachine(True,False)
			
	def openFiles(self,conffile = myConstants.CONFIG_FILE, serielist = myConstants.SERIES_FILE):
		self.conffile = conffile
		self.serielist = serielist
		return self.m.openFiles(conffile, serielist)
			
	def setAuth(self,auth=True):
		if self.auth != auth:
			self.auth = auth

	def isAuth(self):
		return self.auth

	def __exec_cmd(self,cmd,method="unknown",json_rtn=True):
		try:
			result = subprocess.check_output(cmd,stderr=subprocess.STDOUT)
		except subprocess.CalledProcessError as e:
			raise e
		except:
			if self.debug:
				print cmd
			raise Exception(method)
		if self.debug:
			print cmd
			print result
		if json_rtn:
			return json.loads(result)
		else:
			return result
		
	def getConf(self):
		return self.m.getConf()

	def setConf(self,conf):
		return self.m.setConf(conf)

	def createConf(self,filename,conf):
		return self.m.createConf(filename,conf)

	def getSeries(self,load_tvdb=False):
		return self.m.getSeries('all',json_c=True,load_tvdb=load_tvdb)

	def getSerie(self,id):
		return self.m.getSeries(int(id),json_c=True,load_tvdb=False)

	def getEpisode(self,serie_id,season,episode,lang='en'):
		return self.m.getEpisode(int(serie_id),int(season),int(episode))
		
	def setSerie(self,id,param):
		arg = {"status": 15}
		for (key,value) in param.items():
			if key == "emails" and len(value) > 0:
				arg['emails'] = value
			elif key == "emails" and len(value) < 1:
				arg['emails'] = []
			elif key == "keywords" and len(value) > 0:
				arg['keywords'] = value
			elif key == "keywords" and len(value) < 1:
				arg['keywords'] = []
			else:
				arg[str(key)] = str(value)
		return self.m.setSerie(int(id),arg,json_c=True)
	
	def addemail(self,id,email):
		serie = self.getSerie(id)
		emails = serie['result']['emails']
		if email not in emails:
			emails.append(email)
		return self.setSerie(id,{"emails":emails})

	def delemail(self,id,email):
		serie = self.getSerie(id)
		emails = serie['result']['emails']
		if email in emails:
			emails.remove(email)
		return self.setSerie(id,{"emails":emails})

	def delSerie(self,id):
		return self.m.delSerie(int(id))

	def addSerie(self,id):
		return self.m.addSeries(int(id),[])

	def resetSerieKeywords(self,id):
		return self.m.resetKeywords(int(id))

	def resetAllKeywords(self):
		return self.m.resetAllKeywords()

	def search(self,pattern):
		if pattern is None or len(pattern) < 1:
			return {'rtn':415,'error':'Blank search'}
		return self.m.search(pattern)

	def testRunning(self):
		cmd = [myConstants.START_STOP_FILE,'status']
		try:
			return self.__exec_cmd(cmd,"testRunning",json_rtn=False).replace('tvShowWatch is ','')
		except subprocess.CalledProcessError as e:
			return "Not running..."

	def push(self,serie_id,destination):
		return self.m.pushTorrent(int(serie_id),destination)

	def run(self):
		cmd = ["date"]
		print self.__exec_cmd(cmd,"date",json_rtn=False)
		self.m.run()

	def logs(self):
		return self.m.logs(json_c=True)
Ejemplo n.º 2
0
	def __init__(self, debug = False):
		self.debug = debug != False
		self.auth = False
		self.m = TSWmachine(True,False)
Ejemplo n.º 3
0
def main():
    # Get input parameters
    parser = argparse.ArgumentParser()
    parser.add_argument(
            "-a",
            "--action",
            default='run',
            choices=['run', 'list', 'init', 'add','config','getconf','del','edit'],
            help='action triggered by the script'
        )
    parser.add_argument(
            "-c",
            "--config",
            default=myConstants.CONFIG_FILE,
            help='indicates the configuration file location. By default:'+myConstants.CONFIG_FILE
        )
    parser.add_argument(
            "-s",
            "--seriefile",
            default=myConstants.SERIES_FILE,
            help='indicates the series list file location. By default:'+myConstants.SERIES_FILE
        )
    parser.add_argument(
            "-v",
            "--verbosity",
            action="store_true",
            help='maximum output verbosity'
        )
    parser.add_argument(
            "--arg",
            default='',
            help='arguments for bash execution'
        )
    args = parser.parse_args()

    # Manage verbosity level
    if args.verbosity:
        logging.basicConfig(level=logging.DEBUG)
        verbose = True
    else:
        verbose = False
    logging.info('SERIES started in verbosity mode')

    global arg;
    if args.arg != '':
        Prompt.arg = args.arg.split(',')
	migrateFiles.migrate()

    # Initialize more data
    m = TSWmachine(True,verbose)
    if args.action != 'init':
		logging.debug('Loading of conffile: %s', args.config)
		logging.debug('Loading of seriefile: %s', args.seriefile)
		result = m.openFiles(args.config, args.seriefile)
		if result['rtn']!='200':
			logging.debug('Fail loading config file: %s', result['error'])
			print("Please first use tvShowWatch --action init")
			sys.exit()
    else:
        result = m.createConf(args.config)
        if result['rtn']!='200':
            print('Error during creation of the configuration file: '+result['error'])
            sys.exit()

    action_fct = {
            'list':action_list,
            'run':action_run,
            'add':action_add,
            'init':action_reset,
            'config':action_config,
            'del':action_del,
            'edit':action_edit,
            'getconf':action_getconf
        }

    # Call for action
    logging.debug('Action from the parameter: %s', args.action)
    
    fct = action_fct[args.action]
    logging.debug('Action function: %s', fct)
    fct(m)
Ejemplo n.º 4
0
def main():
    # Get input parameters
    parser = argparse.ArgumentParser()
    parser.add_argument("-a",
                        "--action",
                        default='',
                        choices=[
                            'run', 'list', 'init', 'add', 'config', 'getconf',
                            'del', 'update', 'getEpisode', 'resetKeywords',
                            'resetAllKeywords', 'search', 'push', 'logs'
                        ],
                        help='action triggered by the script')
    parser.add_argument(
        "-c",
        "--config",
        default=myConstants.CONFIG_FILE,
        help='indicates the configuration file location. By default:' +
        myConstants.CONFIG_FILE)
    parser.add_argument(
        "-s",
        "--seriefile",
        default=myConstants.SERIES_FILE,
        help='indicates the series list file location. By default:' +
        myConstants.SERIES_FILE)
    parser.add_argument("-v",
                        "--verbosity",
                        action="store_true",
                        help='maximum output verbosity')
    parser.add_argument("--admin", action="store_true", help='admin mode')
    parser.add_argument("--arg",
                        default='',
                        help='arguments for bash execution')
    args = parser.parse_args()

    # Manage verbosity level
    if args.verbosity:
        logging.basicConfig(level=logging.DEBUG)
    logging.info('TSW started in verbosity mode')

    # Parse arguments
    if args.arg != '':
        try:
            arg = json.loads(args.arg)
        except:
            print(
                json.dumps({
                    'rtn': '415',
                    'error': messages.returnCode['415']
                }))
            sys.exit()
    else:
        arg = {}

    # Initialize more data
    migrateFiles.migrate()
    m = TSWmachine(args.admin, args.verbosity)
    if args.admin:
        logging.info('TSW loaded in admin mode')

    if args.action != 'init':
        logging.debug('Loading of conffile: %s', args.config)
        logging.debug('Loading of seriefile: %s', args.seriefile)
        result = m.openFiles(args.config, args.seriefile)
        if result['rtn'] != '200':
            print(json.dumps(result))
            sys.exit()

    if args.action == 'init':
        result = m.createConf(args.config, arg['conf'])
        print(json.dumps(result))
        sys.exit()

    if args.action == 'run':
        m.run()
        sys.exit()

    if args.action == 'list':
        if 'ids' not in arg.keys():
            arg['ids'] = 'all'
        if 'load_tvdb' not in arg.keys():
            arg['load_tvdb'] = False
        print(
            json.dumps(
                m.getSeries(arg['ids'],
                            json_c=True,
                            load_tvdb=arg['load_tvdb'])))
        sys.exit()

    if args.action == 'add':
        if 'emails' not in arg.keys():
            arg['emails'] = []
        print(json.dumps(m.addSeries(arg['id'], arg['emails'])))
        sys.exit()

    if args.action == 'search':
        if 'pattern' not in arg.keys():
            print(json.dumps({'rtn': 415, 'error': 'Blank search'}))
            sys.exit()
        print(json.dumps(m.search(arg['pattern'])))
        sys.exit()

    if args.action == 'update':
        if 'param' not in arg.keys():
            arg['param'] = {}
        print(json.dumps(m.setSerie(arg['id'], arg['param'], json_c=True)))
        sys.exit()

    if args.action == 'resetKeywords':
        print(json.dumps(m.resetKeywords(arg['id'])))
        sys.exit()

    if args.action == 'resetAllKeywords':
        print(json.dumps(m.resetAllKeywords()))
        sys.exit()

    if args.action == 'config':
        result = m.setConf(arg['conf'])
        if (result['rtn'] != '200'):
            print(json.dumps(result))
        else:
            print(json.dumps(m.getConf()))
        sys.exit()

    if args.action == 'getconf':
        if 'arg' not in locals():
            arg = {}
        if 'conf' not in arg.keys():
            arg['conf'] = 'all'
        print(json.dumps(m.getConf(arg['conf'])))
        sys.exit()

    if args.action == 'del':
        print(json.dumps(m.delSerie(arg['id'])))
        sys.exit()

    if args.action == 'getEpisode':
        print(
            json.dumps(m.getEpisode(arg['id'], arg['season'], arg['episode'])))
        sys.exit()

    if args.action == 'push':
        print(json.dumps(m.pushTorrent(arg['id'], arg['filepath'])))
        sys.exit()

    if args.action == 'logs':
        print(json.dumps(m.logs(json_c=True)))
        sys.exit()

    print(
        json.dumps({
            'rtn': '400',
            'error': messages.returnCode['400'].format(args.action)
        }))
    sys.exit()
Ejemplo n.º 5
0
def main():
	# Get input parameters
	parser = argparse.ArgumentParser()
	parser.add_argument(
		"-a",
		"--action",
		default='',
		choices=['run', 'list', 'init', 'add','config','getconf','del','update','getEpisode','resetKeywords','resetAllKeywords','search','push','logs'],
		help='action triggered by the script'
		)
	parser.add_argument(
		"-c",
		"--config",
		default=myConstants.CONFIG_FILE,
		help='indicates the configuration file location. By default:'+myConstants.CONFIG_FILE
		)
	parser.add_argument(
		"-s",
		"--seriefile",
		default=myConstants.SERIES_FILE,
		help='indicates the series list file location. By default:'+myConstants.SERIES_FILE
		)
	parser.add_argument(
		"-v",
		"--verbosity",
		action="store_true",
		help='maximum output verbosity'
		)
	parser.add_argument(
		"--admin",
		action="store_true",
		help='admin mode'
		)
	parser.add_argument(
		"--arg",
		default='',
		help='arguments for bash execution'
		)
	args = parser.parse_args()

	# Manage verbosity level
	if args.verbosity:
		logging.basicConfig(level=logging.DEBUG)
	logging.info('TSW started in verbosity mode')
	
	# Parse arguments
	if args.arg != '':
		try:
			arg = json.loads(args.arg)
		except:
			print(json.dumps({'rtn':'415','error':messages.returnCode['415']}))
			sys.exit()
	else:
		arg = {}

	# Initialize more data
	migrateFiles.migrate()
	m = TSWmachine(args.admin,args.verbosity)
	if args.admin:
		logging.info('TSW loaded in admin mode')

	if args.action != 'init':
		logging.debug('Loading of conffile: %s', args.config)
		logging.debug('Loading of seriefile: %s', args.seriefile)
		result = m.openFiles(args.config, args.seriefile)
		if result['rtn']!='200':
			print(json.dumps(result))
			sys.exit()

	if args.action == 'init':
		result = m.createConf(args.config,arg['conf'])
		print(json.dumps(result))
		sys.exit()

	if args.action == 'run':
		m.run()
		sys.exit()

	if args.action == 'list':
		if 'ids' not in arg.keys():
			arg['ids'] = 'all'
		if 'load_tvdb' not in arg.keys():
			arg['load_tvdb'] = False
		print(json.dumps(m.getSeries(arg['ids'],json_c=True,load_tvdb=arg['load_tvdb'])))
		sys.exit()

	if args.action == 'add':
		if 'emails' not in arg.keys():
			arg['emails'] = []
		print(json.dumps(m.addSeries(arg['id'],arg['emails'])))
		sys.exit()

	if args.action == 'search':
		if 'pattern' not in arg.keys():
			print(json.dumps({'rtn':415,'error':'Blank search'}))
			sys.exit()
		print(json.dumps(m.search(arg['pattern'])))
		sys.exit()

	if args.action == 'update':
		if 'param' not in arg.keys():
			arg['param'] = {}
		print(json.dumps(m.setSerie(arg['id'],arg['param'],json_c=True)))
		sys.exit()

	if args.action == 'resetKeywords':
		print(json.dumps(m.resetKeywords(arg['id'])))
		sys.exit()

	if args.action == 'resetAllKeywords':
		print(json.dumps(m.resetAllKeywords()))
		sys.exit()

	if args.action == 'config':
		result = m.setConf(arg['conf'])
		if (result['rtn'] != '200'):
			print(json.dumps(result))
		else:
			print(json.dumps(m.getConf()))
		sys.exit()

	if args.action == 'getconf':
                if 'arg' not in locals():                                                
                        arg = {}
                if 'conf' not in arg.keys():
                        arg['conf'] = 'all'
		print(json.dumps(m.getConf(arg['conf'])))
		sys.exit()

	if args.action == 'del':
		print(json.dumps(m.delSerie(arg['id'])))
		sys.exit()

	if args.action == 'getEpisode':
		print(json.dumps(m.getEpisode(arg['id'],arg['season'],arg['episode'])))
		sys.exit()

	if args.action == 'push':
		print(json.dumps(m.pushTorrent(arg['id'],arg['filepath'])))
		sys.exit()

	if args.action == 'logs':
		print(json.dumps(m.logs(json_c=True)))
		sys.exit()

	print(json.dumps({'rtn':'400','error':messages.returnCode['400'].format(args.action)}))
	sys.exit()
Ejemplo n.º 6
0
 def __init__(self, debug=False):
     self.debug = debug != False
     self.auth = False
     self.m = TSWmachine(True, False)
Ejemplo n.º 7
0
class TvShowWatch():
    def __init__(self, debug=False):
        self.debug = debug != False
        self.auth = False
        self.m = TSWmachine(True, False)

    def openFiles(self,
                  conffile=myConstants.CONFIG_FILE,
                  serielist=myConstants.SERIES_FILE):
        self.conffile = conffile
        self.serielist = serielist
        return self.m.openFiles(conffile, serielist)

    def setAuth(self, auth=True):
        if self.auth != auth:
            self.auth = auth

    def isAuth(self):
        return self.auth

    def __exec_cmd(self, cmd, method="unknown", json_rtn=True):
        try:
            result = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
        except subprocess.CalledProcessError as e:
            raise e
        except:
            if self.debug:
                print cmd
            raise Exception(method)
        if self.debug:
            print cmd
            print result
        if json_rtn:
            return json.loads(result)
        else:
            return result

    def getConf(self):
        return self.m.getConf()

    def setConf(self, conf):
        return self.m.setConf(conf)

    def createConf(self, filename, conf):
        return self.m.createConf(filename, conf)

    def getSeries(self, load_tvdb=False):
        return self.m.getSeries('all', json_c=True, load_tvdb=load_tvdb)

    def getSerie(self, id):
        return self.m.getSeries(int(id), json_c=True, load_tvdb=False)

    def getEpisode(self, serie_id, season, episode, lang='en'):
        return self.m.getEpisode(int(serie_id), int(season), int(episode))

    def setSerie(self, id, param):
        arg = {"status": 15}
        for (key, value) in param.items():
            if key == "emails" and len(value) > 0:
                arg['emails'] = value
            elif key == "emails" and len(value) < 1:
                arg['emails'] = []
            elif key == "keywords" and len(value) > 0:
                arg['keywords'] = value
            elif key == "keywords" and len(value) < 1:
                arg['keywords'] = []
            else:
                arg[str(key)] = str(value)
        return self.m.setSerie(int(id), arg, json_c=True)

    def addemail(self, id, email):
        serie = self.getSerie(id)
        emails = serie['result']['emails']
        if email not in emails:
            emails.append(email)
        return self.setSerie(id, {"emails": emails})

    def delemail(self, id, email):
        serie = self.getSerie(id)
        emails = serie['result']['emails']
        if email in emails:
            emails.remove(email)
        return self.setSerie(id, {"emails": emails})

    def delSerie(self, id):
        return self.m.delSerie(int(id))

    def addSerie(self, id):
        return self.m.addSeries(int(id), [])

    def resetSerieKeywords(self, id):
        return self.m.resetKeywords(int(id))

    def resetAllKeywords(self):
        return self.m.resetAllKeywords()

    def search(self, pattern):
        if pattern is None or len(pattern) < 1:
            return {'rtn': 415, 'error': 'Blank search'}
        return self.m.search(pattern)

    def testRunning(self):
        cmd = [myConstants.START_STOP_FILE, 'status']
        try:
            return self.__exec_cmd(cmd, "testRunning", json_rtn=False).replace(
                'tvShowWatch is ', '')
        except subprocess.CalledProcessError as e:
            return "Not running..."

    def push(self, serie_id, destination):
        return self.m.pushTorrent(int(serie_id), destination)

    def run(self):
        cmd = ["date"]
        print self.__exec_cmd(cmd, "date", json_rtn=False)
        self.m.run()

    def logs(self):
        return self.m.logs(json_c=True)