Esempio n. 1
0
    def invoke(self):

        # invocation-count
        self.runCount += 1

        try:

            # get Fluxcli instance
            fluxcli = Activator().getInstance('Fluxcli')
            
            # process jobs
            jobCopy = self.jobs[:]
            for job in jobCopy:
            
                # build arg-array
                args = []
                args.append('rss')
                args.append(job['savedir'])
                args.append('%s%s.dat' % (self.dataDir, job['filtername']))
                args.append('%s%s.hist' % (self.dataDir, job['filtername']))
                args.append(job['url'])
                
                # execute job
                try:
                    # log run
                    self.logger.debug('running rssad-job: %s' % job.__str__())
                    # invoke fluxcli
                    result = fluxcli.invoke(args, True).strip()
                    # log result
                    self.logger.debug('rssad-run-result:\n%s' % result)
                except Exception, e:
                    self.logger.error("Error when calling rssad (%s)" % (e))

            # return
            return True
Esempio n. 2
0
def transferStart(name):

    # imports
    from fluxd.activator.Activator import Activator

    # get Fluxcli-instance
    fluxcli = Activator().getInstance('Fluxcli')

    # invoke fluxcli
    try:
        # invoke and return
        return fluxcli.invoke(['start', name], True).strip()
    except Exception, e:
        raise Exception, "Exception when invoking fluxcli to start transfer %s (%s)" % (name, e)
Esempio n. 3
0
    def invoke(self):

        # invocation-count
        self.runCount += 1

        try:

            # get Fluxcli instance
            fluxcli = Activator().getInstance("Fluxcli")

            # process jobs
            jobCopy = self.jobs[:]
            for job in jobCopy:

                # build arg-array
                args = []
                args.append("watch")
                args.append(job["D"])  # watchdir
                args.append(job["U"])  # user
                if job.has_key("A"):  # action
                    action = job["A"]
                else:
                    action = "ds"
                extraargs = []
                if job.has_key("P"):  # profile
                    action += "p"
                    extraargs.append(job["P"])
                args.append(action)
                args += extraargs

                # execute job
                try:
                    # log run
                    self.logger.debug("running watch-job: %s" % job.__str__())
                    # invoke fluxcli
                    result = fluxcli.invoke(args, True).strip()
                    # log result
                    self.logger.debug("watch-run-result:\n%s" % result)
                except Exception, e:
                    self.logger.error("Error when calling watch (%s)" % (e))

            # return
            return True
    def invoke(self):

        # invocation-count
        self.runCount += 1

        try:
            
            # get Fluxcli instance
            fluxcli = Activator().getInstance('Fluxcli')
            
            # invoke
            result = fluxcli.invoke(['maintenance', self.restart], True).strip()
            
            # log
            self.logger.debug('maintenance-run-result:\n%s' % result)
            
            # return
            return True
        
        except Exception, e:
            self.logger.error("Error when calling maintenance (%s)" % (e))
Esempio n. 5
0
    def _fireEventCore(self, event, name, action, new):
        """actually call the event."""

        if action.startswith('execute'):
            script = action.split(Trigger.CmdDelim)[1]

            # pass stuff to the environment
            params = {}
            params[Trigger.Param_CURDATE]  = time.strftime(Config().get('logging', 'Dateformat'))
            params[Trigger.Param_DOCROOT]  = Config().get('dir', 'docroot').strip()
            params[Trigger.Param_EVENT]    = event
            params[Trigger.Param_FLUXCLI]  = Activator().getInstance('Fluxcli').getPath()
            params[Trigger.Param_FLUXD]    = Config().get('dir', 'pathFluxd').strip()
            params[Trigger.Param_OWNER]    = new.transferowner.strip()
            params[Trigger.Param_PATH]     = Config().get('dir', 'pathTf').strip()
            params[Trigger.Param_PHP]      = Config().get('file', 'php').strip()
            params[Trigger.Param_TRANSFER] = name 
            #params[Trigger.Param_TYPE]    = type
            params[Trigger.Param_RUNNING]  = new.running
            params[Trigger.Param_PERCENT]  = new.percent_done
            params[Trigger.Param_TIME]     = new.time_left
            params[Trigger.Param_DOWN]     = new.down_speed
            params[Trigger.Param_UP]       = new.up_speed
            params[Trigger.Param_SEEDS]    = new.seeds
            params[Trigger.Param_PEERS]    = new.peers
            params[Trigger.Param_SHARING]  = new.sharing
            params[Trigger.Param_SEEDLIM]  = new.seedlimit
            params[Trigger.Param_UPTOTAL]  = new.uptotal
            params[Trigger.Param_DOWNTOTAL]= new.downtotal
            params[Trigger.Param_SIZE]     = new.size

            # Prepare environment (clean up and add params).
            env = dict([(k, v) for k, v in os.environ.iteritems() if not k.startswith(Trigger.ParamPrefix)])
            env.update(params)

            bgShellCmd(self.logger, self.name + ':' + event, script, Config().get('dir', 'pathTf').strip(), env)
            return self.removeJob(name, event, action)

        elif action.startswith('email'):
            """ Attempt to email the user, and fall back to PM if necessary."""
            try:
                # Can't get the email out of the DB at this time
                # it must be inserted into the job initially.
                
                recipient = action.split(Trigger.CmdDelim)[1]
                sender = '*****@*****.**'
                msg = MIMEText('%s has met criteria: %s' % (name, event))
                msg['Subject'] = 'Update from Torrentflux-B4rt'
                msg['From'] = sender
                msg['To'] = recipient
                
                # actually send the message. could require setting the host
                # and port on some systems.
                s = smtplib.SMTP()
                s.connect()
                s.sendmail(sender, [recipient], msg.as_string())
                s.close()
            except Exception, e:
                """ email failed, fallback to PM"""

                # log
                self.logger.error('cannot email, falling back to PM: %s' % e)

                # get fluxcli instance
                fluxcli = Activator().getInstance('Fluxcli');

                # invoke fluxcli
                try:
                    # invoke
                    fluxcli.invoke(['pm', 'Trigger', new.transferowner.strip(), name + ' has met criteria: ' + event], False)
                except Exception, e:
                    raise Exception, 'Exception when attempting to pm the user: %s' % e
Esempio n. 6
0
                except Exception, e:
                    raise Exception, 'Exception when attempting to pm the user: %s' % e

            return self.removeJob(name, event, action)

        elif action.startswith('tset'):
            """ adjust transfer settings."""
            # check the parameters
            (setting, value) = action.split(Trigger.CmdDelim)[1:]

            # get fluxcli instance
            fluxcli = Activator().getInstance('Fluxcli');

            # invoke fluxcli
            try:
                fluxcli.invoke(['tset', name, setting, value], True).strip()
            except Exception, e:
                raise Exception, "Exception when attempting to adjust torrent settings"

            return self.removeJob(name, event, action)

        elif action.startswith('unzip'):
            # don't find the files, get them directly from the user!
            files = action.split(Trigger.CmdDelim)[1:]
            for file in files:
                try:
                    # Get the file's extension
                    extension = os.path.splitext(file)[1]
                    
                    # seperate gzip'd files from tar'd and gzip'd files
                    if file.endswith('.tar.gz'):