Example #1
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
Example #2
0
            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'):
                        # Tar'd and Gzip'd file, switch extension
                        # so we use the right command to extract it
                        extension = '.tgz'
                    
                    # Get path to the unzip binary
                    path_unzip = Trigger.archivers[extension]
                    
                    bgShellCmd(self.logger,  self.name + ':' + event,  path_unzip + file,  Config().get('dir', 'pathTf').strip() + new.transferowner.strip())
                except:
                    self.logger.error('Exception while unziping %s' % e)
                    return False
                    
            return self.removeJob(name,  event,  action)

        elif action.startswith('move'):
            file, destination = action.split(Trigger.CmdDelim)[1:3]
            
            bgShellCmd(self.logger,  self.name + ':' + event,  Trigger.bin_mv + ' ' + file + ' ' + destination,  Config().get('dir', 'pathTf').strip())
            
            return self.removeJob(name,  event,  action)
            
            
        else: