Example #1
0
    def _walk_file_system(self, root):
        """
        From a give root of a tree this method will walk through ever branch
        and return a generator.
        """
        names = os.listdir(root)
        for name in names:
            try:
                file_stat = os.lstat(os.path.join(root, name))
            except os.error:
                continue

            if stat.S_ISDIR(file_stat.st_mode):
                # Check to make sure the file not in the ignore list
                ignore = False
                for ignore_re in self._ignore_regexs:
                    if ignore_re.match(name):
                        log.debug("[WalkDirectoryThread] ### Ignored %s ####", name)
                        ignore = True
                        break
                if ignore:
                    continue
                for (newroot, children) in self._walk_file_system(os.path.join(root, name)):
                    yield newroot, children
        yield root, names
def refactorDescription(org_, data):
    if CompiledRegexpReplaceChars:
        org = CompiledRegexpReplaceChars.sub("", org_)
        log.debug(" refactor desc", org_, org)
    else:
        org = org_
    if data:
        if (
            config.plugins.seriesplugin.pattern_description.value
            and not config.plugins.seriesplugin.pattern_description.value == "Off"
            and not config.plugins.seriesplugin.pattern_description.value == "Disabled"
        ):
            data["org"] = org
            cust_ = config.plugins.seriesplugin.pattern_description.value.strip().format(**data)
            cust = (
                cust_.replace("\n", " ")
                .replace("&", "&")
                .replace("'", "'")
                .replace(">", ">")
                .replace("&lt;", "<")
                .replace("&quot;", '"')
                .replace("  ", " ")
            )
            log.debug(" refactor desc", cust_, cust)
            return cust
        else:
            return org
    else:
        return org
Example #3
0
 def __init__(self, file_monitor, root, ignore_regexs):
     log.debug("[FileMonitor] WalkDirectoryThread Root: %s" % root)
     Thread.__init__(self)
     self._file_monitor = file_monitor
     self._root = root
     self._ignore_regexs = ignore_regexs
     self.start()
Example #4
0
 def validate(self, name):
     # Check to make sure the file not in the ignore list
     for ignore_re in self._ignore_regexs:
         if ignore_re.match(name):
             log.debug("[WalkDirectoryThread] ##### Ignored %s #####", name)
             return False
     return True
Example #5
0
	def __init__(self):
		log.debug("Main: Init")
		Modules.__init__(self)
		ChannelsBase.__init__(self)
		
		self.thread = SeriesPluginWorker(self.gotResult)
		
		# Because of the same XMLFile base class we intantiate a new object
		self.xmltv = XMLTVBase()
		
		self.serviceHandler = eServiceCenter.getInstance()
		
		#http://bugs.python.org/issue7980
		datetime.strptime('2012-01-01', '%Y-%m-%d')
		
		self.identifier_elapsed = self.instantiateModuleWithName( config.plugins.seriesplugin.identifier_elapsed.value )
		#log.debug(self.identifier_elapsed)
		
		self.identifier_today = self.instantiateModuleWithName( config.plugins.seriesplugin.identifier_today.value )
		#log.debug(self.identifier_today)
		
		self.identifier_future = self.instantiateModuleWithName( config.plugins.seriesplugin.identifier_future.value )
		#log.debug(self.identifier_future)
		
		pattern = config.plugins.seriesplugin.pattern_title.value
		pattern = pattern.replace("{org:s}", "(.+)")
		pattern = re.sub('{season:?\d*d?}', '\d+', pattern)
		pattern = re.sub('{episode:?\d*d?}', '\d+', pattern)
		pattern = re.sub('{rawseason:s}', '.+', pattern)
		pattern = re.sub('{rawseason:s}', '.+', pattern)
		pattern = pattern.replace("{title:s}", ".+")
		self.compiledRegexpSeries = re.compile(pattern)
	def setColorButtons(self):
		try:
			log.debug("event eit", self.event and self.event.getEventId())
			if self.service and self.data:
				
				if self.path and os.path.exists(self.path):
					# Record file exists
					self["key_red"].setText(_("Rename"))
					self.redButtonFunction = self.keyRename
				elif self.event and self.event.getEventId():
					# Event exists
					#if (not self.service.flags & eServiceReference.isGroup) and self.service.getPath() and self.service.getPath()[0] == '/'
					#for timer in self.session.nav.RecordTimer.timer_list:
					#	if timer.eit == eventid and timer.service_ref.ref.toString() == refstr:
					#		cb_func = lambda ret : not ret or self.removeTimer(timer)
					self["key_red"].setText(_("Record"))
					self.redButtonFunction = self.keyRecord
				else:
					self["key_red"].setText("")
					self.redButtonFunction = None
			else:
				self["key_red"].setText("")
				self.redButtonFunction = None
		except:
			# Screen already closed
			log.debug("exception:", str(e))
			pass
Example #7
0
	def run(self):
		
		while not self.__queue.empty():
			
			# NOTE: we have to check this here and not using the while to prevent the parser to be started on shutdown
			if not self.__running: break
			
			log.debug('Worker is processing')
			
			item = self.__queue.pop()
			
			result = None
			
			try:
				result = item.identifier.getEpisode(
					item.name, item.begin, item.end, item.service
				)
			except Exception, e:
				log.debug("Worker: Exception:", str(e))
				
				# Exception finish job with error
				result = str(e)
			
			config.plugins.seriesplugin.lookup_counter.value += 1
			
			self.__messages.push( (item.callback, normalizeResult(result)) )
			
			self.__pump.send(0)
	def getSeasonEpisode( self, name, webChannel, unixtime, max_time_drift ):
		result = None
		
		skipped = self.skip.get(name, None)
		if skipped:
			if ( time() - skipped ) < skip_expiration:
				#return _("Skipped")
				socket.setdefaulttimeout( reduced_timeout )
			else:
				del self.skip[name]
		
		try:
			result = self.sp.cache.getSeasonEpisode( name, webChannel, unixtime, max_time_drift )
			log.debug("SerienServer getSeasonEpisode result:", result)
		except Exception as e:
			msg = "Exception in xmlrpc: \n" + str(e) + ' - ' + str(result) + "\n\nfor" + name + " (" + webChannel + ")"
			if not config.plugins.seriesplugin.autotimer_independent.value:
				log.exception(msg)
			else:
				# The independant mode could have a lot of non series entries
				log.debug(msg)
			self.skip[name] = time()
			result = str(e)
		
		if skipped:
			timeout = config.plugins.seriesplugin.socket_timeout.value
			socket.setdefaulttimeout( float(timeout) )
		
		return result
	def loadModules(self, path, base):
		modules = {}
		
		if not os.path.exists(path):
			return
		
		# Import all subfolders to allow relative imports
		for root, dirs, files in os.walk(path):
			if root not in sys.path:
				sys.path.append(root)
		
		# Import PushService modules
		files = [fname[:-3] for fname in os.listdir(path) if fname.endswith(".py")]
		for name in files:
			module = None
			
			if name == "__init__":
				continue
			
			try:
				fp, pathname, description = imp.find_module(name, [path])
			except Exception, e:
				log.exception( ("PushService Find module exception: ") + str(e) )
				fp = None
			
			if not fp:
				log.debug( ("PushService No module found: ") + str(name) )
				continue
			
			try:
				module = imp.load_module( name, fp, pathname, description)
			except Exception, e:
				log.exception( ("PushService Load exception: ") + str(e) )
Example #10
0
def normalizeResult(result):
	if result and isinstance(result, dict):
		log.debug("normalize result")
		title_   = result['title'].strip()
		series_  = result['series'].strip()
		season_  = result['season']
		episode_ = result['episode']
		
		result['rawseason']  = season_  or config.plugins.seriesplugin.default_season.value
		result['rawepisode'] = episode_ or config.plugins.seriesplugin.default_episode.value
		if season_:
			result['season']  = int( CompiledRegexpNonDecimal.sub('', str(season_)) or config.plugins.seriesplugin.default_season.value or "0" )
		else:
			result['season']  = int(config.plugins.seriesplugin.default_season.value) or 0
		if episode_:
			result['episode'] = int( CompiledRegexpNonDecimal.sub('', str(episode_)) or config.plugins.seriesplugin.default_episode.value or "0" )
		else:
			result['episode'] = int(config.plugins.seriesplugin.default_episode.value) or 0
		
		if CompiledRegexpReplaceChars:
			title = CompiledRegexpReplaceChars.sub('', title_)
			#log.debug(" normalize title", title_, title)
			series = CompiledRegexpReplaceChars.sub('', series_)
			#log.debug(" normalize series", series_, series)
		else:
			title = title_
			series = series_
		result['title']  = title
		result['series'] = series
		result['date'] = strftime("%d.%m.%Y", localtime(result['begin']))
		result['time'] = strftime("%H:%M:%S", localtime(result['begin']))
		return result
	else:
		log.debug("normalize result failed", str(result))
		return result
	def keyRecord(self):
		log.debug("keyRecord")
		if self.event and self.service:
			event = self.event
			ref = self.service
			if event is None:
				return
			eventid = event.getEventId()
			eref = eServiceReference(str(ref))
			refstr = eref.toString()
			for timer in self.session.nav.RecordTimer.timer_list:
				if timer.eit == eventid and timer.service_ref.ref.toString() == refstr:
					cb_func = lambda ret : not ret or self.removeTimer(timer)
					self.session.openWithCallback(cb_func, MessageBox, _("Do you really want to delete %s?") % event.getEventName())
					break
			else:
				#newEntry = RecordTimerEntry(ServiceReference(ref), checkOldTimers = True, dirname = preferredTimerPath(), *parseEvent(self.event))
				begin, end, name, description, eit = parseEvent(self.event)
				
				from SeriesPlugin import refactorTitle, refactorDescription
				if self.data:
					name = refactorTitle(name, self.data)
					description = refactorDescription(description, self.data)
				
				#newEntry = RecordTimerEntry(ServiceReference(refstr), begin, end, name, description, eit, dirname = preferredTimerPath())
				newEntry = RecordTimerEntry(ServiceReference(str(ref)), begin, end, name, description, eit, dirname = preferredTimerPath())
				#newEntry = RecordTimerEntry(refstr, begin, end, name, description, eit, dirname = preferredTimerPath())
				self.session.openWithCallback(self.finishedAdd, TimerEntry, newEntry)
def buildSTBchannellist(BouquetName = None):
	chlist = None
	chlist = []
	mask = (eServiceReference.isMarker | eServiceReference.isDirectory)
	log.debug("SPC: read STB Channellist..")
	tvbouquets = getTVBouquets()
	log.debug("SPC: found %s bouquet: %s" % (len(tvbouquets), tvbouquets) )

	if not BouquetName:
		for bouquet in tvbouquets:
			bouquetlist = []
			bouquetlist = getServiceList(bouquet[0])
			for (serviceref, servicename) in bouquetlist:
				playable = not (eServiceReference(serviceref).flags & mask)
				if playable:
					chlist.append((servicename, re.sub('::.*', ':', serviceref), unifyChannel(servicename)))
	else:
		for bouquet in tvbouquets:
			if bouquet[1] == BouquetName:
				bouquetlist = []
				bouquetlist = getServiceList(bouquet[0])
				for (serviceref, servicename) in bouquetlist:
					playable = not (eServiceReference(serviceref).flags & mask)
					if playable:
						chlist.append((servicename, re.sub('::.*', ':', serviceref), unifyChannel(servicename)))
				break
	return chlist
def refactorDirectory(org, data):
    dir = org
    if data:
        if (
            config.plugins.seriesplugin.pattern_directory.value
            and not config.plugins.seriesplugin.pattern_directory.value == "Off"
            and not config.plugins.seriesplugin.pattern_directory.value == "Disabled"
        ):
            data["org"] = org
            cust_ = config.plugins.seriesplugin.pattern_directory.value.strip().format(**data)
            cust_ = (
                cust_.replace("\n", "")
                .replace("&amp;", "&")
                .replace("&apos;", "'")
                .replace("&gt;", ">")
                .replace("&lt;", "<")
                .replace("&quot;", '"')
                .replace("  ", " ")
                .replace("//", "/")
            )
            dir = CompiledRegexpReplaceDirChars.sub(" ", cust_)
            log.debug(" refactor dir", org, cust_, dir)
        if dir and not os.path.exists(dir):
            try:
                os.makedirs(dir)
            except:
                log.exception("makedirs exception", dir)
    return dir
Example #14
0
 def _reset_config(self):
     if self._config.get_value("USE_FILEBROWSER"):
         self._file_browser_checkbox.set_active(True)
     else:
         self._file_browser_checkbox.set_active(False)
     log.debug("[GeditOpenFileGui] IGNORE_FILE_FILETYPES = " + str(self._config.get_value("IGNORE_FILE_FILETYPES")))
     self._config_ignore_input.set_text(", ".join(self._config.get_value("IGNORE_FILE_FILETYPES")))
	def channelReset(self, answer):
		if answer:
			log.debug("channel-list reset...")
			self.resetChannels()
			self.stbChlist = []
			self.webChlist = []
			self.stbToWebChlist = []
			self.readChannels()
	def getWebChannels(self):
		
		log.debug("SerienServer getWebChannels()")
		
		result = self.server.getWebChannels()
		log.debug("SerienServer getWebChannels result:", result)
		
		return result
Example #17
0
 def root_path(self):
     root = "."
     if self.get_value("USE_FILEBROWSER"):
         root = self._get_root_from_filebrowser()
     else:
         root = self.get_value("ROOT_PATH")
     log.debug("[Config] ROOT: %s" % root)
     return urllib.unquote(root)
Example #18
0
 def _open_file(self, uri):
     log.debug("[GeditOpenFileGui] uri to open : %s" % uri)
     # Check to make sure file is not allready opened
     tab = self._window.get_tab_from_uri(uri)
     if not tab:
         # if not createa tab.
         tab = self._window.create_tab_from_uri(uri, self._encoding, 0, False, False)
     self._window.set_active_tab(tab)
def labelTimer(timer, *args, **kwargs):
	if config.plugins.seriesplugin.enabled.value:
		log.debug("SeriesPlugin labelTimer is deprecated - Update Your AutoTimer!")
		try:
			spt = SeriesPluginTimer()
			spt.getEpisode(timer)
		except Exception as e:
			log.exception(_("SeriesPlugin label exception ") + str(e))
	def close(self):
		log.debug("user close")
		
		global instance
		instance = None
		
		# Call baseclass function
		Screen.close(self)
	def keyCancel(self):
		self.help_window_was_shown = False
		log.debug("SPC keyCancel")
		#self.seriesPlugin.resetChannels()
		resetInstance()
		if self["config"].isChanged() or self.changesMade:
			self.session.openWithCallback(self.cancelConfirm, MessageBox, _("Really close without saving settings?"))
		else:
			self.close()
	def loadWebChannels(self):
		self.setTitle(_("Load Web channels for bouquet") + " " + self.bouquet)
		log.debug("Load Web channels")
		data = self.getWebChannels()
		if data:
			temp = [ (x,unifyChannel(x)) for x in data]
		else:
			self.setTitle(_("Problem during loading Webchannels"))
			temp = []
		self.webChlist = sorted(temp, key=lambda tup: tup[0])
Example #23
0
def compareChannels(ref, remote):
	log.debug("compareChannels", ref, remote)
	remote = remote.lower()
	if ref in ChannelsBase.channels:
		( name, alternatives ) = ChannelsBase.channels[ref]
		for altname in alternatives:
			if altname.lower() in remote or remote in altname.lower():
				return True
		
	return False
Example #24
0
	def stop(self):
		log.debug(" Main: stop")
		if self.thread:
			self.thread.stop()
		# NOTE: while we don't need to join the thread, we should do so in case it's currently parsing
		#self.thread.join()
		
		self.thread = None
		self.saveXML()
		self.xmltv.writeXMLTVConfig()
def getSeasonAndEpisode(timer, *args, **kwargs):
	result = None
	if config.plugins.seriesplugin.enabled.value:
		log.debug("SeriesPlugin getSeasonAndEpisode is deprecated - Update Your AutoTimer!")
		try:
			spt = SeriesPluginTimer()
			result = spt.getEpisode(timer, True)
		except Exception as e:
			log.exception(_("SeriesPlugin label exception ") + str(e))
	return result
	def keyRemove(self):
		check = self['list'].getCurrent()
		if check == None:
			log.debug("keyRemove list empty")
			return
		else:
			servicename, webSender, serviceref, state = check
			log.debug("keyRemove", servicename, webSender, serviceref, state)
			if serviceref:
				#TODO handle multiple links/alternatives - show a choicebox
				self.session.openWithCallback( boundFunction(self.removeConfirm, servicename, serviceref), MessageBox, _("Remove '%s'?") % servicename, MessageBox.TYPE_YESNO, default = False)
	def removeConfirm(self, servicename, serviceref, answer):
		if not answer:
			return
		if serviceref:
			idx = self.getIndexOfServiceref(serviceref)
			if idx is not False:
				log.debug("removeConfirm", servicename, serviceref, idx)
				self.setTitle(_("Channel '- %s -' removed.") % servicename)
				self.removeChannel(serviceref)
				self.stbToWebChlist[idx] = (servicename, "", serviceref, "0")
				self['list'].setList( self.stbToWebChlist )
Example #28
0
	def addChannel(self, ref, name, remote):
		log.debug("SP addChannel name remote", name, remote)
		
		if ref in ChannelsBase.channels:
			( name, alternatives ) = ChannelsBase.channels[ref]
			if remote not in alternatives:
				alternatives.append(remote)
				ChannelsBase.channels[ref] = ( name, alternatives )
		else:
			ChannelsBase.channels[ref] = ( name, [remote] )
		ChannelsBase.channels_changed = True
Example #29
0
    def _set_ignore_list(self):
        log.info("[FileMonitor] Set Regexs for Ignore List")

        ignore_res = []
        # Complie Ignore list in to a list of regexs
        for ignore in self._config.get_value("IGNORE_FILE_FILETYPES"):
            ignore = ignore.replace(".", "\.")
            ignore = ignore.replace("*", ".*")
            ignore = "^" + ignore + "$"
            log.debug("[FileMonitor] Ignore Regex = %s" % ignore)
            self._ignore_regexs.append(re.compile(ignore))
Example #30
0
def lookupChannelByReference(ref):
	if ref in ChannelsBase.channels:
		( name, alternatives ) = ChannelsBase.channels[ref]
		altnames = []
		for altname in alternatives:
			if altname:
				log.debug("lookupChannelByReference", ref, altname)
				altnames.append(altname)
		return altnames
	log.debug("lookupChannelByReference: Failed for", ref)
	return False
Example #31
0
	def setOptions(self, options):
		# Parse a list of key-value string tuples
		# [ (key, value) , ]
		# If something is missing, the last/default value is used
		for key, value in options:
			try:
				default = self.getValue(key)
				if type(default) is str:
					self.setValue(key, value)
				elif type(default) is bool:
					self.setValue(key, eval(value))
				elif type(default) is int:
					self.setValue(key, int(value))
			except:
				log.debug( ("PushService Module %s:\n") % ( self.getName() ) )
				log.debug( ("Skipping config option:") + str(key) + " " + str(value) )
				continue
Example #32
0
def normalizeResult(result):
    if result and isinstance(result, dict):
        log.debug("normalize result")
        title_ = result['title'].strip()
        series_ = result['series'].strip()
        season_ = result['season']
        episode_ = result['episode']

        if config.plugins.seriesplugin.cut_series_title.value and " - " in series_:
            series_, sub_series_title = series_.split(" - ", 1)
        result[
            'rawseason'] = season_ or config.plugins.seriesplugin.default_season.value
        result[
            'rawepisode'] = episode_ or config.plugins.seriesplugin.default_episode.value
        if season_:
            result['season'] = int(
                CompiledRegexpNonDecimal.sub('', str(season_))
                or config.plugins.seriesplugin.default_season.value or "0")
        else:
            result['season'] = int(
                config.plugins.seriesplugin.default_season.value) or 0
        if episode_:
            result['episode'] = int(
                CompiledRegexpNonDecimal.sub('', str(episode_))
                or config.plugins.seriesplugin.default_episode.value or "0")
        else:
            result['episode'] = int(
                config.plugins.seriesplugin.default_episode.value) or 0

        if CompiledRegexpReplaceChars:
            title = CompiledRegexpReplaceChars.sub('', title_)
            #log.debug(" normalize title", title_, title)
            series = CompiledRegexpReplaceChars.sub('', series_)
            #log.debug(" normalize series", series_, series)
        else:
            title = title_
            series = series_
        result['title'] = title
        result['series'] = series
        result['date'] = strftime("%d.%m.%Y", localtime(result['begin']))
        result['time'] = strftime("%H:%M:%S", localtime(result['begin']))
        return result
    else:
        log.debug("normalize result failed", str(result))
        return result
Example #33
0
    def __init__(self):

        self.epgimport = None
        self.epgimportversion = "0"
        self.xmltvimport = None
        self.xmltvimportversion = "0"

        # Check if xmltvimport exists
        if os.path.exists("/etc/epgimport"):
            log.debug("readXMLTV: Found epgimport")
            path = "/etc/epgimport/wunschliste.sources.xml"
            self.epgimport = XMLFile(path)

        # Check if xmltvimport exists
        elif os.path.exists("/etc/xmltvimport"):
            log.debug("readXMLTV: Found xmltvimport")
            path = "/etc/xmltvimport/wunschliste.sources.xml"
            self.xmltvimport = XMLFile(path)

        self.readXMLTVConfig()
Example #34
0
    def readXML(self):
        path = config.pushservice.xmlpath.value

        # Abort if no config found
        if not os.path.exists(path):
            log.debug("PushService No configuration file present")
            return None

        # Parse if mtime differs from whats saved
        mtime = os.path.getmtime(path)
        if mtime == self.mtime:
            # No changes in configuration, won't read again
            return self.cache

        # Parse XML
        try:
            etree = parse(path).getroot()
        except Exception, e:
            log.exception(("PushService Exception in readXML: ") + str(e))
            etree = None
            mtime = -1
Example #35
0
    def next(self, state=None):
        if state: self.state = state
        log.debug("PushService next", self.state)

        if self.state == PSBOOT:
            self.startTimer(int(config.pushservice.bootdelay.value), PSBOOTRUN)

        elif self.state == PSBOOTRUN \
         or self.state == PSFIRST:
            cltime = config.pushservice.time.value
            lotime = localtime()
            ltime = lotime[3] * 60 + lotime[4]
            ctime = cltime[0] * 60 + cltime[1]
            seconds = 60 * abs(ctime - ltime)
            self.startTimer(seconds, PSFIRSTRUN)

        elif self.state == PSFIRSTRUN \
         or self.state == PSCYCLE:
            period = int(config.pushservice.period.value)
            if period > 0:
                self.startTimer(period * 60 * 60, PSCYCLE)
Example #36
0
def getServicesOfBouquet(bouquet):
    bouquetlist = getServiceList(bouquet)
    chlist = []
    for (serviceref, servicename) in bouquetlist:

        if (eServiceReference(serviceref).flags
                & eServiceReference.isDirectory):
            # handle directory services
            log.debug("SPC: found directory %s" % (serviceref))
            chlist.extend(getServicesOfBouquet(serviceref))

        elif (eServiceReference(serviceref).flags & eServiceReference.isGroup):
            # handle group services
            log.debug("SPC: found group %s" % (serviceref))
            chlist.extend(getServicesOfBouquet(serviceref))

        elif not (eServiceReference(serviceref).flags
                  & eServiceReference.isMarker):
            # playable
            log.debug("SPC: found playable service %s" % (serviceref))
            chlist.append(
                (servicename, re.sub('::.*', ':',
                                     serviceref), unifyChannel(servicename)))

    return chlist