コード例 #1
0
ファイル: TSWmachine.py プロジェクト: kavod/TvShowWatch
    def __init__(self, admin=False, log=False):
        if log:
            logging.basicConfig(level=logging.DEBUG)
        self.admin = admin
        self.confFilename = None
        self.confData = None

        self.seriefile = SerieList()
        self.verbosity = log
        try:
            self.confschema = jsonConfigParser.loadParserFromFile(
                myConstants.CONFIG_SCHEMA)
        except:
            raise Exception(messages.returnCode['423'].format(
                myConstants.CONFIG_SCHEMA))
コード例 #2
0
ファイル: TSWmachine.py プロジェクト: kavod/TvShowWatch
	def __init__(self,admin=False,log=False):
		if log:
			logging.basicConfig(level=logging.DEBUG)
		self.admin = admin
		self.confFilename = None
		self.confData = None
		
		self.seriefile = SerieList()
		self.verbosity = log
		try:
			self.confschema = jsonConfigParser.loadParserFromFile(myConstants.CONFIG_SCHEMA)
		except:
			raise Exception(messages.returnCode['423'].format(myConstants.CONFIG_SCHEMA))
コード例 #3
0
ファイル: TSWmachine.py プロジェクト: kavod/TvShowWatch
class TSWmachine:
    def __init__(self, admin=False, log=False):
        if log:
            logging.basicConfig(level=logging.DEBUG)
        self.admin = admin
        self.confFilename = None
        self.confData = None

        self.seriefile = SerieList()
        self.verbosity = log
        try:
            self.confschema = jsonConfigParser.loadParserFromFile(
                myConstants.CONFIG_SCHEMA)
        except:
            raise Exception(messages.returnCode['423'].format(
                myConstants.CONFIG_SCHEMA))

    def getVerbosity(self):
        return self.verbosity

    def getAuth(self):
        logging.info('Get Auth :' + str(self.admin))
        return self.admin

    def openFiles(self,
                  conffile=myConstants.CONFIG_FILE,
                  seriefile=myConstants.SERIES_FILE):
        # conf file opening
        logging.info('OpenFile ' + str(conffile) + ' and ' + str(seriefile))
        try:
            self.confData = jsonConfigParser.jsonConfigValue(self.confschema,
                                                             value=None,
                                                             filename=conffile)
        except Exception as e:
            logging.info('Fail to open file:' + str(conffile))
            logging.debug(str(e))
            return {
                'rtn': '401',
                'tracker_conf': self.get_tracker_conf(),
                'error': messages.returnCode['401'].format(conffile)
            }
        self.confFilename = conffile

        # conf file parsing
        self.confData.load()
        try:
            self.confData.load()
        except Exception as e:
            logging.info('Fail to parse file:' + str(conffile))
            logging.debug(str(e))
            return {
                'rtn': '423',
                'tracker_conf': self.get_tracker_conf(),
                'error': messages.returnCode['423'].format(conffile)
            }

        logging.info('Conf file OK, opening Serie List')
        return self.seriefile.openFile(seriefile)

    def openedFiles(self, files=['conf', 'serie']):
        logging.info('OpenedFile')
        if 'conf' in files and self.confData is None:
            logging.info('Conf file not opened')
            return {
                'rtn': '403',
                'error':
                messages.returnCode['403'].format("Configuration file")
            }
        if 'serie' in files and self.seriefile.openedFile()['rtn'] != '200':
            logging.info('Serie file not opened')
            return self.seriefile.openedFile()
        return {'rtn': '200', 'error': messages.returnCode['200']}

    def createConf(self, filename, conf={}):
        logging.info('CreateConf ' + str(filename) + ' with ' + str(conf))
        if (not self.getAuth()):
            return {'rtn': '406', 'error': messages.returnCode['406']}
        confData = {"version": myConstants.CONFIG_VERSION}
        confData.update(conf)
        self.confFilename = filename
        try:
            self.confData = jsonConfigParser.jsonConfigValue(self.confschema,
                                                             value=None,
                                                             filename=filename)
        except:
            return {
                'rtn': '424',
                'error': messages.returnCode['424'].format(filename)
            }
        return {'rtn': '200', 'error': messages.returnCode['200']}

    def getConf(self, conf='all'):
        if (not self.openedFiles(['conf'])['rtn'] == '200'):
            result = self.openedFiles(['conf'])
            result['tracker_conf'] = self.get_tracker_conf()
            return result
        if conf == 'all':
            result = self.confData.getValue()
        else:
            result = self.confData.getValue(path=conf.split("_"))

        return {
            'rtn': '200',
            'result': result,
            'tracker_conf': self.get_tracker_conf()
        }

    def get_tracker_conf(self):
        return tracker.TRACKER_CONF

    def setConf(self, conf={}, save=True):
        if (not self.getAuth()):
            return {'rtn': '406', 'error': messages.returnCode['406']}
        if (not self.openedFiles(['conf'])['rtn'] == '200'):
            return {
                'rtn': '403',
                'error': messages.returnCode['403'].format('Configuration')
            }

        self.confData.update(conf)
        send = ('smtp' in conf.keys())
        if save:
            self.confData.save()
            result = self.testConf(send)
            if result['rtn'] == '200':
                if 'keywords' in conf.keys() and len(
                    [x for x in conf['keywords'] if x == '']) < 1:
                    return result
                else:
                    return {'rtn': '304', 'error': messages.returnCode['304']}
            return result
        else:
            return {'rtn': '200', 'error': messages.returnCode['200']}

    def testTracker(self):
        logging.info('testTracker')
        trackerConf = self.confData['tracker']
        try:
            provider = tracker.check_provider(trackerConf['id'])
            if 'username' in provider['param'] and trackerConf['user'] == '':
                return {
                    'rtn': '422',
                    'error':
                    messages.returnCode['422'].format(provider['name'])
                }
            mytracker = tracker.Tracker(
                trackerConf['id'], {
                    'username': trackerConf['user'],
                    'password': trackerConf['password']
                })
        except myExceptions.InputError as e:
            return {
                'rtn': '404',
                'error': messages.returnCode['404'].format('Tracker', e.expr)
            }
        except Exception, e:
            return {
                'rtn': '404',
                'error': messages.returnCode['404'].format('Tracker', e)
            }
        else:
コード例 #4
0
ファイル: TSWmachine.py プロジェクト: kavod/TvShowWatch
class TSWmachine:
	def __init__(self,admin=False,log=False):
		if log:
			logging.basicConfig(level=logging.DEBUG)
		self.admin = admin
		self.confFilename = None
		self.confData = None
		
		self.seriefile = SerieList()
		self.verbosity = log
		try:
			self.confschema = jsonConfigParser.loadParserFromFile(myConstants.CONFIG_SCHEMA)
		except:
			raise Exception(messages.returnCode['423'].format(myConstants.CONFIG_SCHEMA))
	
	def getVerbosity(self):
		return self.verbosity

	def getAuth(self):
		logging.info('Get Auth :'+ str(self.admin))
		return self.admin

	def openFiles(self,conffile=myConstants.CONFIG_FILE,seriefile=myConstants.SERIES_FILE):
		# conf file opening
		logging.info('OpenFile ' + str(conffile) + ' and '+ str(seriefile))
		try:
			self.confData = jsonConfigParser.jsonConfigValue(self.confschema,value=None,filename=conffile)
		except Exception as e:
			logging.info('Fail to open file:'+ str(conffile))
			logging.debug(str(e))
			return {'rtn':'401','tracker_conf':self.get_tracker_conf(),'error':messages.returnCode['401'].format(conffile)}
		self.confFilename = conffile
		
		# conf file parsing
		self.confData.load()
		try:
			self.confData.load()
		except Exception as e:
			logging.info('Fail to parse file:'+ str(conffile))
			logging.debug(str(e))
			return {'rtn':'423','tracker_conf':self.get_tracker_conf(),'error':messages.returnCode['423'].format(conffile)}
		
		logging.info('Conf file OK, opening Serie List')
		return self.seriefile.openFile(seriefile)

	def openedFiles(self,files=['conf','serie']):
		logging.info('OpenedFile')
		if 'conf' in files and self.confData is None:
			logging.info('Conf file not opened')
			return {'rtn':'403','error':messages.returnCode['403'].format("Configuration file")}
		if 'serie' in files and self.seriefile.openedFile()['rtn']!='200':
			logging.info('Serie file not opened')
			return self.seriefile.openedFile()
		return {'rtn':'200','error':messages.returnCode['200']}

	def createConf(self,filename,conf={}):
		logging.info('CreateConf ' + str(filename) + ' with '+ str(conf))
		if (not self.getAuth()):
			return {'rtn':'406','error':messages.returnCode['406']}
		confData = {"version":myConstants.CONFIG_VERSION}
		confData.update(conf)
		self.confFilename = filename
		try:
			self.confData = jsonConfigParser.jsonConfigValue(self.confschema,value=None,filename=filename)
		except:
			return {'rtn':'424','error':messages.returnCode['424'].format(filename)}
		return {'rtn':'200','error':messages.returnCode['200']}

	def getConf(self,conf='all'):
		if (not self.openedFiles(['conf'])['rtn']=='200'):
			result = self.openedFiles(['conf'])
			result['tracker_conf'] = self.get_tracker_conf()
			return result
		if conf=='all':
			result = self.confData.getValue()
		else:
			result = self.confData.getValue(path=conf.split("_"))
				
		return {'rtn':'200','result':result,'tracker_conf':self.get_tracker_conf()}
		
	def get_tracker_conf(self):
		return tracker.TRACKER_CONF

	def setConf(self,conf={},save=True):
		if (not self.getAuth()):
			return {'rtn':'406','error':messages.returnCode['406']}
		if (not self.openedFiles(['conf'])['rtn']=='200'):
			return {'rtn':'403','error':messages.returnCode['403'].format('Configuration')}

		self.confData.update(conf)
		send = ('smtp' in conf.keys())
		if save:
			self.confData.save()
			result = self.testConf(send)
			if result['rtn'] == '200':
				if 'keywords' in conf.keys() and len([x for x in conf['keywords'] if x == ''])<1:
					return result
				else:
					return {'rtn':'304','error':messages.returnCode['304']}
			return result
		else:	
			return {'rtn':'200','error':messages.returnCode['200']}

	def testTracker(self):
		logging.info('testTracker')
		trackerConf = self.confData['tracker']
		try:
			provider = tracker.check_provider(trackerConf['id'])
			if 'username' in provider['param'] and trackerConf['user'] == '':
				return {'rtn':'422','error':messages.returnCode['422'].format(provider['name'])}
			mytracker = tracker.Tracker(trackerConf['id'],{'username':trackerConf['user'],'password':trackerConf['password']})
		except myExceptions.InputError as e:
			return {'rtn':'404','error':messages.returnCode['404'].format('Tracker',e.expr)}
		except Exception,e:
			return {'rtn':'404','error':messages.returnCode['404'].format('Tracker',e)}
		else: