def getUpdateInfosCB(self, callback, errback, retval = None):
		if retval is not None:
			if retval is True:
				if iSoftwareTools.available_updates is not 0:
					# _("There are at least ") + str(iSoftwareTools.available_updates) + _(" updates available.")
					log.debug( "Updates available." )
					return self.buildList(callback, errback)
				else:
					# _("There are no updates available.")
					log.debug( "There are no updates available." )
					return callback()
			elif retval is False:
				if iSoftwareTools.lastDownloadDate is None:
					if iSoftwareTools.NetworkConnectionAvailable:
						# _("Updatefeed not available.")
						log.debug( "Updatefeed not available." )
						return errback(_("Updatefeed not available."))
					else:
						# _("No network connection available.")
						log.debug( "No network connection available." )
						return errback(_("No network connection available."))
				else:
					log.debug( "IPKGUpdateNotification getUpdates" )
					# Call update
					iSoftwareTools.lastDownloadDate = time()
					iSoftwareTools.list_updating = True
					iSoftwareTools.getUpdates( boundFunction(self.getUpdateInfosCB, callback, errback) )
					return
		callback()
 def getUpdateInfosCB(self, callback, errback, retval=None):
     if retval is not None:
         if retval is True:
             if iSoftwareTools.available_updates is not 0:
                 # _("There are at least ") + str(iSoftwareTools.available_updates) + _(" updates available.")
                 log.debug("Updates available.")
                 return self.buildList(callback, errback)
             else:
                 # _("There are no updates available.")
                 log.debug("There are no updates available.")
                 return callback()
         elif retval is False:
             if iSoftwareTools.lastDownloadDate is None:
                 if iSoftwareTools.NetworkConnectionAvailable:
                     # _("Updatefeed not available.")
                     log.debug("Updatefeed not available.")
                     return errback(_("Updatefeed not available."))
                 else:
                     # _("No network connection available.")
                     log.debug("No network connection available.")
                     return errback(_("No network connection available."))
             else:
                 log.debug("IPKGUpdateNotification getUpdates")
                 # Call update
                 iSoftwareTools.lastDownloadDate = time()
                 iSoftwareTools.list_updating = True
                 iSoftwareTools.getUpdates(
                     boundFunction(self.getUpdateInfosCB, callback,
                                   errback))
                 return
     callback()
Exemplo n.º 3
0
	def push(self, callback, errback, pluginname, subject, body="", attachments=[]):
		from Plugins.Extensions.PushService.plugin import NAME, VERSION, SUPPORT, DONATE
		
		# Set SMTP parameters
		mailconf = {}
		mailconf["host"]     = self.getValue('smtpserver')
		mailconf["port"]     = self.getValue('smtpport')
		mailconf["username"] = self.getValue('username')
		mailconf["password"] = self.getValue('password')
		mailconf["ssl"]      = self.getValue('smtpssl')
		mailconf["tls"]      = self.getValue('smtptls')
		mailconf["timeout"]  = self.getValue('timeout')
		
		# Create message object
		from_addr = self.getValue('mailfrom')
		to_addrs = [self.getValue('mailto') or from_addr]
		
		# Prepare message
		if body == "": body = subject
		subject = MAIL_HEADER_TEMPLATE.format( **{'box': config.pushservice.boxname.value, 'name': NAME, 'plugin': pluginname, 'subject': subject} )
		body    = MAIL_BODY_TEMPLATE.format( **{'body': str(body), 'name': NAME, 'version': VERSION, 'plugin': pluginname, 'support': SUPPORT, 'donate': DONATE} )
		message = Message(from_addr, to_addrs, subject, body) #TODO change mime="text/plain", charset="utf-8")
		if attachments:
			for attachment in attachments:
				message.attach(attachment) #TODO change mime=None, charset=None, content=None):
		
		# Send message
		log.debug( ("PushService PushMail: Sending message: %s") % subject )
		deferred, connector = sendmail(mailconf, message)
		
		# Add callbacks
		deferred.addCallback(callback)
		deferred.addErrback(errback)
		
		self.connectors.append(connector)
Exemplo n.º 4
0
    def push(self,
             callback,
             errback,
             pluginname,
             subject,
             body="",
             attachments=[]):
        from Plugins.Extensions.PushService.plugin import NAME, VERSION, SUPPORT, DONATE

        # Set SMTP parameters
        mailconf = {}
        mailconf["host"] = self.getValue('smtpserver')
        mailconf["port"] = self.getValue('smtpport')
        mailconf["username"] = self.getValue('username')
        mailconf["password"] = self.getValue('password')
        mailconf["ssl"] = self.getValue('smtpssl')
        mailconf["tls"] = self.getValue('smtptls')
        mailconf["timeout"] = self.getValue('timeout')

        # Create message object
        from_addr = self.getValue('mailfrom')
        to_addrs = [self.getValue('mailto') or from_addr]

        # Prepare message
        if body == "": body = subject
        subject = MAIL_HEADER_TEMPLATE.format(
            **{
                'box': config.pushservice.boxname.value,
                'name': NAME,
                'plugin': pluginname,
                'subject': subject
            })
        body = MAIL_BODY_TEMPLATE.format(
            **{
                'body': str(body),
                'name': NAME,
                'version': VERSION,
                'plugin': pluginname,
                'support': SUPPORT,
                'donate': DONATE
            })
        message = Message(
            from_addr, to_addrs, subject,
            body)  #TODO change mime="text/plain", charset="utf-8")
        if attachments:
            for attachment in attachments:
                message.attach(
                    attachment
                )  #TODO change mime=None, charset=None, content=None):

        # Send message
        log.debug(("PushService PushMail: Sending message: %s") % subject)
        deferred, connector = sendmail(mailconf, message)

        # Add callbacks
        deferred.addCallback(callback)
        deferred.addErrback(errback)

        self.connectors.append(connector)
	def run(self, callback, errback):
		# At the end a plugin has to call one of the functions: callback or errback
		# Callback should return with at least one of the parameter: Header, Body, Attachment
		# If empty or none is returned, nothing will be sent
		if iSoftwareTools.lastDownloadDate is not None and iSoftwareTools.lastDownloadDate > ( time() - (24*60*60) ):
			# Last refresh was within one day
			return self.buildList(callback, errback)
		else:
			log.debug( "IPKGUpdateNotification run else" )
			if self.getValue('selfcheck'):
				# Refresh package list
				iSoftwareTools.startSoftwareTools( boundFunction(self.getUpdateInfosCB, callback, errback) )
				return
		callback()
	def begin(self):
		# Is called after starting PushService
		
		if self.getValue('send_on_start') or self.getValue('send_on_end'):
			if NavigationInstance.instance:
				if self.onRecordEvent not in NavigationInstance.instance.RecordTimer.on_state_change:
					log.debug( "append" )
					# Append callback function
					NavigationInstance.instance.RecordTimer.on_state_change.append(self.onRecordEvent)
			else:
				# Try again later
				self.forceBindRecordTimer.startLongTimer(1)
		else:
			# Remove callback function
			self.end()
 def run(self, callback, errback):
     # At the end a plugin has to call one of the functions: callback or errback
     # Callback should return with at least one of the parameter: Header, Body, Attachment
     # If empty or none is returned, nothing will be sent
     if iSoftwareTools.lastDownloadDate is not None and iSoftwareTools.lastDownloadDate > (
             time() - (24 * 60 * 60)):
         # Last refresh was within one day
         return self.buildList(callback, errback)
     else:
         log.debug("IPKGUpdateNotification run else")
         if self.getValue('selfcheck'):
             # Refresh package list
             iSoftwareTools.startSoftwareTools(
                 boundFunction(self.getUpdateInfosCB, callback, errback))
             return
     callback()
Exemplo n.º 8
0
    def begin(self):
        # Is called after starting PushService

        if self.getValue('send_on_start') or self.getValue('send_on_end'):
            if NavigationInstance.instance:
                if self.onRecordEvent not in NavigationInstance.instance.RecordTimer.on_state_change:
                    log.debug("append")
                    # Append callback function
                    NavigationInstance.instance.RecordTimer.on_state_change.append(
                        self.onRecordEvent)
            else:
                # Try again later
                self.forceBindRecordTimer.startLongTimer(1)
        else:
            # Remove callback function
            self.end()
Exemplo n.º 9
0
	def run(self, callback, errback):
		# At the end a plugin has to call one of the functions: callback or errback
		# Callback should return with at least one of the parameter: Header, Body, Attachment
		# If empty or none is returned, nothing will be sent
		path = self.getValue('path')
		limit = self.getValue('limit')
		
		if not self.getValue('wakehdd'):

			# User specified to avoid HDD wakeup if it is sleeping
			from Components.Harddisk import harddiskmanager
			dev = getDevicebyMountpoint( harddiskmanager, mountpoint(path) )
			if dev is not None:
				hdd = getHDD( harddiskmanager, dev )
				if hdd is not None:
					if hdd.isSleeping():
						# Don't wake up HDD
						log.debug( _("[FreeSpace] HDD is idle: ") + str(path) )
						callback()
		
		# Check free space on path
		if os.path.exists( path ):
			stat = os.statvfs( path )
			free = ( stat.f_bavail if stat.f_bavail!=0 else stat.f_bfree ) * stat.f_bsize / 1024 / 1024 # MB
			if limit > (free/1024): #GB
				if free >= 10*1024:	#MB
					free = "%d GB" %(free/1024)
				else:
					free = "%d MB" %(free)
				# Not enough free space
				text = ""
				if self.getValue('listtimer'):
					text = "\r\n\r\n" 
					text += _("Next timer:") 
					text += "\r\n"
					import NavigationInstance
					now = time()
					next_day = now + 86400 # Add one day
					for t in NavigationInstance.instance.RecordTimer.timer_list + NavigationInstance.instance.RecordTimer.processed_timers:
						if not t.disabled and not t.justplay and now < t.begin and t.end < next_day:
							text += "\t" + timerToString(t)  + "\r\n"
					
				callback( SUBJECT, BODY % (path, limit, free) + text )
			else:
				# There is enough free space
				callback()
	def buildList(self, callback, errback):
		updates = ""
		for package in iSoftwareTools.available_updatelist:
			packagename = package[0]
			instversion = ""
			if packagename in iSoftwareTools.installed_packetlist:
				instversion = iSoftwareTools.installed_packetlist[packagename]
			updversion = ""
			for p, v, d in iSoftwareTools.available_packetlist:
				if p == packagename:
					updversion = v
					break
			log.debug( "PushService: " + packagename + " :\t" + instversion + " :\t" + updversion )
			if instversion != updversion:
				updates += packagename + " :\t" + instversion + " :\t" + updversion + "\n"
		if updates:
			callback( SUBJECT, BODY % (updates) )
		else:
			callback()
 def buildList(self, callback, errback):
     updates = ""
     for package in iSoftwareTools.available_updatelist:
         packagename = package[0]
         instversion = ""
         if packagename in iSoftwareTools.installed_packetlist:
             instversion = iSoftwareTools.installed_packetlist[packagename]
         updversion = ""
         for p, v, d in iSoftwareTools.available_packetlist:
             if p == packagename:
                 updversion = v
                 break
         log.debug("PushService: " + packagename + " :\t" + instversion +
                   " :\t" + updversion)
         if instversion != updversion:
             updates += packagename + " :\t" + instversion + " :\t" + updversion + "\n"
     if updates:
         callback(SUBJECT, BODY % (updates))
     else:
         callback()
Exemplo n.º 12
0
    def callback(self):
        import NavigationInstance
        # Called after all services succeded
        if self.getValue('remove_timer'):

            # Remove deactivated timers
            for timer in self.timers[:]:
                if timer in NavigationInstance.instance.RecordTimer.processed_timers:
                    NavigationInstance.instance.RecordTimer.processed_timers.remove(
                        timer)
                elif timer in NavigationInstance.instance.RecordTimer.timer_list:
                    NavigationInstance.instance.RecordTimer.timer_list.remove(
                        timer)
                self.timers.remove(timer)

        # Set tag to avoid resending it
        for timer in self.timers:
            if TAG not in timer.tags:
                log.debug("[PS] timer append tag")
                timer.tags.append(TAG)
        NavigationInstance.instance.RecordTimer.saveTimer()
        self.timers = []
Exemplo n.º 13
0
	def run(self, callback, errback):
		# At the end a plugin has to call one of the functions: callback or errback
		# Callback should return with at least one of the parameter: Header, Body, Attachment
		# If empty or none is returned, nothing will be sent
		self.timers = []
		text = ""
		now = time()
		for timer in NavigationInstance.instance.RecordTimer.timer_list + NavigationInstance.instance.RecordTimer.processed_timers:
			if timer.justplay:
				log.debug( _("ActiveTimers: Skip justplay") + str(timer.name) )
				pass
			
			elif str(timer.service_ref)[0]=="-":
				log.debug( _("ActiveTimers: Skip serviceref") + str(timer.name) )
				pass
			
			elif self.getValue('add_tag') and TAG in timer.tags:
				log.debug( _("ActiveTimers: Skip tag") + str(timer.name) )
				pass
			
			elif timer.disabled:
				log.debug( _("ActiveTimers: Skip disabled") + str(timer.name) )
				pass
			
			elif timer.begin < now:
				log.debug( _("ActiveTimers: Skip begin < now") + str(timer.name) )
				pass
			
			else:
				text += str(timer.name) + "    " \
							+ strftime(_("%Y.%m.%d %H:%M"), localtime(timer.begin)) + " - " \
							+ strftime(_("%H:%M"), localtime(timer.end)) + "    " \
							+ str(timer.service_ref and timer.service_ref.getServiceName() or "") \
							+ "\n"
				self.timers.append( timer )
		if self.timers and text:
			callback( SUBJECT, BODY % text )
		else:
			callback()
Exemplo n.º 14
0
	def parse_args(self, args=None, values=None):
		values, args = OptionParser.parse_args(self, args, values)

		if values.message is None:
			log.debug( 'Enter a message followed by Ctrl-D' )
			try:
				message = sys.stdin.read()
			except KeyboardInterrupt:
				exit()
		else:
			message = values.message

		if values.title is None:
			values.title = ' '.join(args)

		# If we still have an empty title, use the
		# first bit of the message as the title
		if values.title == '':
			values.title = message[:20]

		values.verbose = logging.WARNING - values.verbose * 10

		return values, message
Exemplo n.º 15
0
    def parse_args(self, args=None, values=None):
        values, args = OptionParser.parse_args(self, args, values)

        if values.message is None:
            log.debug('Enter a message followed by Ctrl-D')
            try:
                message = sys.stdin.read()
            except KeyboardInterrupt:
                exit()
        else:
            message = values.message

        if values.title is None:
            values.title = ' '.join(args)

        # If we still have an empty title, use the
        # first bit of the message as the title
        if values.title == '':
            values.title = message[:20]

        values.verbose = logging.WARNING - values.verbose * 10

        return values, message
	def opkgupgradableFinished(self, retval=None):
		
		try:
			log.debug( "PushService retval: ",str(retval) )
		except:
			pass
		try:
			log.debug( "PushService self.data: ",str(self.data) )
		except:
			pass
		
		updates = ""
		excepts = ""
		
		if self.data:
			try:
				for line in self.data.split("\n"):
					log.debug( "PushService opkg upgradable data: ",line )
					if line.startswith("Inflating"):
						continue
					if line.startswith("Updated"):
						continue
					if line.startswith("Downloading"):
						continue
					if line.startswith("Ign "):
						continue
					if line.startswith("Get:"):
						continue
					if line.startswith("Hit "):
						continue
					if line.startswith("Fetched "):
						continue
					if line.startswith("Reading "):
						continue
					if line.startswith("Err "):
						continue
					if line.find('404 ') != -1:
						continue
					if line.find('Failed ') != -1:
						continue
					if line.find('failed ') != -1:
						continue
					if line == '':
						continue
					updates += line + "\r\n"
			except Exception, e:
				excepts += "\r\n\r\nException:\r\n" + str(e)
Exemplo n.º 17
0
	def aptupgradableFinished(self, retval=None):
		
		try:
			log.debug( "PushService retval: ",str(retval) )
		except:
			pass
		try:
			log.debug( "PushService self.data: ",str(self.data) )
		except:
			pass
		
		updates = ""
		excepts = ""
		
		if self.data:
			try:
				for line in self.data.split("\n"):
					log.debug( "PushService opkg upgradable data: ",line )
					if line.startswith("Inst"):
						updates += line[5:] + "\r\n"
						continue
			except Exception, e:
				excepts += "\r\n\r\nException:\r\n" + str(e)