Ejemplo n.º 1
0
    def execute(self, skipOnSuccess=False):

        #print self.__str__()

        #Do a dictionary replacement.
        #Replace replacement strings
        global replacementDic

        #for each key replace all instances of the key in the command string
        for key, value in replacementDic.iteritems():
            key = toStrFromUnicode(key)
            replacementDic[key] = toStrFromUnicode(value)
            #self.outputLocation = toStrFromUnicode(self.outputLocation)
            #self.command = self.command.replace ( key, quote(replacementDic[key]) )
            self.command = self.command.replace(
                key, escapeForCommand(replacementDic[key]))
            if self.outputLocation:
                self.outputLocation = self.outputLocation.replace(
                    key, replacementDic[key])
        print "Running: "
        print self.__str__()

        self.exitCode, self.stdOut, self.stdError = executeOrRun(
            self.type, self.command)

        if (not self.exitCode) and self.verificationCommand:
            print
            self.exitCode = self.verificationCommand.execute(
                skipOnSuccess=True)

        if (not self.exitCode) and self.eventDetailCommand:
            self.eventDetailCommand.execute(skipOnSuccess=True)

        #If unsuccesful
        if self.exitCode:
            print >> sys.stderr, "Failed:"
            #print >>sys.stderr, self.__str__()
            print self.stdOut
            print >> sys.stderr, self.stdError
            if False and self.failedCount < 1:  #retry count
                self.failedCount = self.failedCount + 1
                time.sleep(2)
                print >> sys.stderr, "retrying, ", self.failedCount
                return self.execute(skipOnSuccess)
        else:
            global onSuccess
            #uncommenting these floods the buffers with ffmpeg
            #print self.stdOut
            #print self.stdError
            if (not skipOnSuccess) and onSuccess:
                onSuccess(self)
        return self.exitCode
    def __init__(self, jobChainLink, pk, unit):
        super(linkTaskManagerDirectories,
              self).__init__(jobChainLink, pk, unit)
        self.tasks = []
        stc = StandardTaskConfig.objects.get(id=str(pk))
        filterFileEnd = stc.filter_file_end
        filterFileStart = stc.filter_file_start
        filterSubDir = stc.filter_subdir
        self.requiresOutputLock = stc.requires_output_lock
        standardOutputFile = stc.stdout_file
        standardErrorFile = stc.stderr_file
        execute = stc.execute
        self.execute = execute
        arguments = stc.arguments

        if filterSubDir:
            directory = os.path.join(unit.currentPath, filterSubDir)
        else:
            directory = unit.currentPath

        # Apply passvar replacement values
        if self.jobChainLink.passVar != None:
            if isinstance(self.jobChainLink.passVar, list):
                for passVar in self.jobChainLink.passVar:
                    if isinstance(passVar, ReplacementDict):
                        arguments, standardOutputFile, standardErrorFile = passVar.replace(
                            arguments, standardOutputFile, standardErrorFile)
            elif isinstance(self.jobChainLink.passVar, ReplacementDict):
                arguments, standardOutputFile, standardErrorFile = self.jobChainLink.passVar.replace(
                    arguments, standardOutputFile, standardErrorFile)

        # Apply unit (SIP/Transfer) replacement values
        commandReplacementDic = unit.getReplacementDic(directory)
        # Escape all values for shell
        for key, value in commandReplacementDic.items():
            commandReplacementDic[
                key] = archivematicaFunctions.escapeForCommand(value)
        arguments, standardOutputFile, standardErrorFile = commandReplacementDic.replace(
            arguments, standardOutputFile, standardErrorFile)

        self.task = taskStandard(self,
                                 execute,
                                 arguments,
                                 standardOutputFile,
                                 standardErrorFile,
                                 UUID=self.UUID)
        databaseFunctions.logTaskCreatedSQL(self, commandReplacementDic,
                                            self.UUID, arguments)
        t = threading.Thread(target=self.task.performTask)
        t.daemon = True
        t.start()
    def execute(self, skipOnSuccess=False):

        #print self.__str__()

        #Do a dictionary replacement.
        #Replace replacement strings
        global replacementDic

        #for each key replace all instances of the key in the command string
        for key, value in replacementDic.iteritems():
            key = toStrFromUnicode(key)
            replacementDic[key] = toStrFromUnicode(value)
            #self.outputLocation = toStrFromUnicode(self.outputLocation)
            #self.command = self.command.replace ( key, quote(replacementDic[key]) )
            self.command = self.command.replace( key, escapeForCommand(replacementDic[key]) )
            if self.outputLocation:
                self.outputLocation = self.outputLocation.replace( key, replacementDic[key] )
        print "Running: "
        print self.__str__()

        self.exitCode, self.stdOut, self.stdError = executeOrRun(self.type, self.command)


        if (not self.exitCode) and self.verificationCommand:
            print
            self.exitCode = self.verificationCommand.execute(skipOnSuccess=True)

        if (not self.exitCode) and self.eventDetailCommand:
            self.eventDetailCommand.execute(skipOnSuccess=True)

        #If unsuccesful
        if self.exitCode:
            print >>sys.stderr, "Failed:"
            #print >>sys.stderr, self.__str__()
            print self.stdOut
            print >>sys.stderr, self.stdError
            if False and self.failedCount < 1: #retry count
                self.failedCount= self.failedCount + 1
                time.sleep(2)
                print >>sys.stderr, "retrying, ", self.failedCount
                return self.execute(skipOnSuccess)
        else:
            global onSuccess
            #uncommenting these floods the buffers with ffmpeg
            #print self.stdOut
            #print self.stdError
            if (not skipOnSuccess) and onSuccess:
                onSuccess(self)
        return self.exitCode
Ejemplo n.º 4
0
    def __init__(self, jobChainLink, unit):
        super(linkTaskManagerGetMicroserviceGeneratedListInStdOut,
              self).__init__(jobChainLink, unit)
        config = self.jobChainLink.link.config
        filterSubDir = config["filter_subdir"]
        standardOutputFile = config["stdout_file"]
        standardErrorFile = config["stderr_file"]
        execute = config["execute"]
        arguments = config["arguments"]

        # Used by ``TaskGroup._log_task``.
        self.execute = config["execute"]

        if filterSubDir:
            directory = os.path.join(unit.currentPath, filterSubDir)
        else:
            directory = unit.currentPath

        # Apply passvar replacement values
        if self.jobChainLink.passVar is not None:
            if isinstance(self.jobChainLink.passVar, list):
                for passVar in self.jobChainLink.passVar:
                    if isinstance(passVar, ReplacementDict):
                        arguments, standardOutputFile, standardErrorFile = passVar.replace(
                            arguments, standardOutputFile, standardErrorFile)
            elif isinstance(self.jobChainLink.passVar, ReplacementDict):
                arguments, standardOutputFile, standardErrorFile = self.jobChainLink.passVar.replace(
                    arguments, standardOutputFile, standardErrorFile)

        # Apply unit (SIP/Transfer) replacement values
        commandReplacementDic = unit.getReplacementDic(directory)
        # Escape all values for shell
        for key, value in commandReplacementDic.items():
            commandReplacementDic[
                key] = archivematicaFunctions.escapeForCommand(value)
        arguments, standardOutputFile, standardErrorFile = commandReplacementDic.replace(
            arguments, standardOutputFile, standardErrorFile)

        group = TaskGroup(self, execute)
        group.addTask(
            arguments,
            standardOutputFile,
            standardErrorFile,
            commandReplacementDic=commandReplacementDic,
            wants_output=True,
        )
        group.logTaskCreatedSQL()
        TaskGroupRunner.runTaskGroup(group, self.taskGroupFinished)
Ejemplo n.º 5
0
    def execute(self, skipOnSuccess=False):
        #for each key replace all instances of the key in the command string
        for key, value in self.replacementDic.iteritems():
            key = toStrFromUnicode(key)
            self.replacementDic[key] = toStrFromUnicode(value)
            #self.outputLocation = toStrFromUnicode(self.outputLocation)
            #self.command = self.command.replace ( key, quote(replacementDic[key]) )
            self.command = self.command.replace(
                key, escapeForCommand(self.replacementDic[key]))
            if self.outputLocation:
                self.outputLocation = self.outputLocation.replace(
                    key, self.replacementDic[key])
        print "Running: "
        selfstr = self.__str__()
        print selfstr
        if self.opts:
            self.opts["prependStdOut"] += "\r\nRunning: \r\n%s" % (selfstr)

        self.exitCode, self.stdOut, self.stdError = executeOrRun(
            self.type, self.command)

        if (not self.exitCode) and self.verificationCommand:
            print
            if self.opts:
                self.opts["prependStdOut"] += "\r\n"
            self.exitCode = self.verificationCommand.execute(
                skipOnSuccess=True)

        if (not self.exitCode) and self.eventDetailCommand:
            self.eventDetailCommand.execute(skipOnSuccess=True)

        #If unsuccesful
        if self.exitCode:
            print >> sys.stderr, "Failed:"
            #print >>sys.stderr, self.__str__()
            print self.stdOut
            print >> sys.stderr, self.stdError
            if False and self.failedCount < 1:  #retry count
                self.failedCount = self.failedCount + 1
                time.sleep(2)
                print >> sys.stderr, "retrying, ", self.failedCount
                return self.execute(skipOnSuccess)
        else:
            if (not skipOnSuccess) and self.onSuccess:
                self.onSuccess(self, self.opts, self.replacementDic)
        return self.exitCode
    def execute(self, skipOnSuccess=False):
        #for each key replace all instances of the key in the command string
        for key, value in self.replacementDic.iteritems():
            key = toStrFromUnicode(key)
            self.replacementDic[key] = toStrFromUnicode(value)
            #self.outputLocation = toStrFromUnicode(self.outputLocation)
            #self.command = self.command.replace ( key, quote(replacementDic[key]) )
            self.command = self.command.replace( key, escapeForCommand(self.replacementDic[key]) )
            if self.outputLocation:
                self.outputLocation = self.outputLocation.replace( key, self.replacementDic[key] )
        print "Running: "
        selfstr = self.__str__()
        print selfstr
        if self.opts:
            self.opts["prependStdOut"] += "\r\nRunning: \r\n%s" % (selfstr)

        self.exitCode, self.stdOut, self.stdError = executeOrRun(self.type, self.command)


        if (not self.exitCode) and self.verificationCommand:
            print
            if self.opts:
                self.opts["prependStdOut"] += "\r\n"
            self.exitCode = self.verificationCommand.execute(skipOnSuccess=True)

        if (not self.exitCode) and self.eventDetailCommand:
            self.eventDetailCommand.execute(skipOnSuccess=True)

        #If unsuccesful
        if self.exitCode:
            print >>sys.stderr, "Failed:"
            #print >>sys.stderr, self.__str__()
            print self.stdOut
            print >>sys.stderr, self.stdError
            if False and self.failedCount < 1: #retry count
                self.failedCount= self.failedCount + 1
                time.sleep(2)
                print >>sys.stderr, "retrying, ", self.failedCount
                return self.execute(skipOnSuccess)
        else:
            if (not skipOnSuccess) and self.onSuccess:
                self.onSuccess(self, self.opts, self.replacementDic)
        return self.exitCode
Ejemplo n.º 7
0
    def __init__(self, jobChainLink, pk, unit):
        super(linkTaskManagerDirectories, self).__init__(jobChainLink, pk, unit)
        stc = StandardTaskConfig.objects.get(id=str(pk))
        filterSubDir = stc.filter_subdir
        standardOutputFile = stc.stdout_file
        standardErrorFile = stc.stderr_file
        execute = stc.execute
        self.execute = execute
        arguments = stc.arguments

        if filterSubDir:
            directory = os.path.join(unit.currentPath, filterSubDir)
        else:
            directory = unit.currentPath

        # Apply passvar replacement values
        if self.jobChainLink.passVar is not None:
            if isinstance(self.jobChainLink.passVar, list):
                for passVar in self.jobChainLink.passVar:
                    if isinstance(passVar, ReplacementDict):
                        arguments, standardOutputFile, standardErrorFile = passVar.replace(arguments, standardOutputFile, standardErrorFile)
            elif isinstance(self.jobChainLink.passVar, ReplacementDict):
                arguments, standardOutputFile, standardErrorFile = self.jobChainLink.passVar.replace(arguments, standardOutputFile, standardErrorFile)

        # Apply unit (SIP/Transfer) replacement values
        commandReplacementDic = unit.getReplacementDic(directory)
        # Escape all values for shell
        for key, value in commandReplacementDic.items():
            commandReplacementDic[key] = archivematicaFunctions.escapeForCommand(value)
        arguments, standardOutputFile, standardErrorFile = commandReplacementDic.replace(arguments, standardOutputFile, standardErrorFile)

        group = TaskGroup(self, execute)
        group.addTask(arguments, standardOutputFile, standardErrorFile,
                      commandReplacementDic=commandReplacementDic)
        group.logTaskCreatedSQL()
        TaskGroupRunner.runTaskGroup(group, self.taskGroupFinished)
    def __init__(self, jobChainLink, pk, unit):
        super(linkTaskManagerFiles, self).__init__(jobChainLink, pk, unit)
        self.tasks = {}
        self.tasksLock = threading.Lock()
        self.exitCode = 0
        self.clearToNextLink = False

        stc = StandardTaskConfig.objects.get(id=str(pk))
        # These three may be concatenated/compared with other strings,
        # so they need to be bytestrings here
        filterFileEnd = str(stc.filter_file_end) if stc.filter_file_end else ''
        filterFileStart = str(
            stc.filter_file_start) if stc.filter_file_start else ''
        filterSubDir = str(stc.filter_subdir) if stc.filter_subdir else ''
        self.standardOutputFile = stc.stdout_file
        self.standardErrorFile = stc.stderr_file
        self.execute = stc.execute
        self.arguments = stc.arguments

        if stc.requires_output_lock:
            outputLock = threading.Lock()
        else:
            outputLock = None

        # Check if filterSubDir has been overridden for this Transfer/SIP
        try:
            var = UnitVariable.objects.get(unittype=self.unit.unitType,
                                           unituuid=self.unit.UUID,
                                           variable=self.execute)
        except (UnitVariable.DoesNotExist,
                UnitVariable.MultipleObjectsReturned):
            var = None

        if var:
            try:
                variableValue = ast.literal_eval(var.variablevalue)
            except SyntaxError:
                # SyntaxError = contents of variableValue weren't the expected dict
                pass
            else:
                filterSubDir = variableValue['filterSubDir']

        SIPReplacementDic = unit.getReplacementDic(unit.currentPath)
        # Escape all values for shell
        for key, value in SIPReplacementDic.items():
            SIPReplacementDic[key] = archivematicaFunctions.escapeForCommand(
                value)
        self.tasksLock.acquire()
        for file, fileUnit in unit.fileList.items():
            if filterFileEnd:
                if not file.endswith(filterFileEnd):
                    continue
            if filterFileStart:
                if not os.path.basename(file).startswith(filterFileStart):
                    continue
            if filterSubDir:
                if not file.startswith(unit.pathString + filterSubDir):
                    continue

            standardOutputFile = self.standardOutputFile
            standardErrorFile = self.standardErrorFile
            execute = self.execute
            arguments = self.arguments

            # Apply passvar replacement values
            if self.jobChainLink.passVar is not None:
                if isinstance(self.jobChainLink.passVar, list):
                    for passVar in self.jobChainLink.passVar:
                        if isinstance(passVar, ReplacementDict):
                            arguments, standardOutputFile, standardErrorFile = passVar.replace(
                                arguments, standardOutputFile,
                                standardErrorFile)
                elif isinstance(self.jobChainLink.passVar, ReplacementDict):
                    arguments, standardOutputFile, standardErrorFile = self.jobChainLink.passVar.replace(
                        arguments, standardOutputFile, standardErrorFile)

            # Apply file replacement values
            commandReplacementDic = fileUnit.getReplacementDic()
            for key, value in commandReplacementDic.items():
                # Escape values for shell
                commandReplacementDic[
                    key] = archivematicaFunctions.escapeForCommand(value)
            arguments, standardOutputFile, standardErrorFile = commandReplacementDic.replace(
                arguments, standardOutputFile, standardErrorFile)

            # Apply unit (SIP/Transfer) replacement values
            arguments, standardOutputFile, standardErrorFile = SIPReplacementDic.replace(
                arguments, standardOutputFile, standardErrorFile)

            UUID = str(uuid.uuid4())
            task = taskStandard(self,
                                execute,
                                arguments,
                                standardOutputFile,
                                standardErrorFile,
                                outputLock=outputLock,
                                UUID=UUID)
            self.tasks[UUID] = task
            databaseFunctions.logTaskCreatedSQL(self, commandReplacementDic,
                                                UUID, arguments)
            t = threading.Thread(target=task.performTask)
            t.daemon = True
            while (archivematicaMCP.limitTaskThreads <=
                   threading.activeCount()):
                self.tasksLock.release()
                time.sleep(archivematicaMCP.limitTaskThreadsSleep)
                self.tasksLock.acquire()
            t.start()

        self.clearToNextLink = True
        self.tasksLock.release()
        if self.tasks == {}:
            self.jobChainLink.linkProcessingComplete(self.exitCode)
Ejemplo n.º 9
0
import os
import sys
sys.path.append("/usr/lib/archivematica/archivematicaCommon")
from executeOrRunSubProcess import executeOrRun
from databaseFunctions import insertIntoEvents
from archivematicaFunctions import escapeForCommand

clamscanResultShouldBe="Infected files: 0"

if __name__ == '__main__':
    fileUUID = sys.argv[1]
    target =  sys.argv[2]
    date = sys.argv[3]
    taskUUID = sys.argv[4]

    command = 'clamdscan  - <"' + escapeForCommand(target) + '"'
    print >>sys.stderr, command
    commandVersion = "clamdscan -V"
    eventOutcome = "Pass"

    clamscanOutput = executeOrRun("bashScript", command, printing=False)
    clamscanVersionOutput = executeOrRun("command", commandVersion, printing=False)

    if clamscanOutput[0] or clamscanVersionOutput[0]:
        if clamscanVersionOutput[0]:
            print >>sys.stderr, clamscanVersionOutput
            exit(2)
        else:
            eventOutcome = "Fail"

    if eventOutcome == "Fail" or clamscanOutput[1].find(clamscanResultShouldBe) == -1:
Ejemplo n.º 10
0
    def __init__(self, jobChainLink, pk, unit):
        super(linkTaskManagerFiles, self).__init__(jobChainLink, pk, unit)

        if jobChainLink.reloadFileList:
            unit.reloadFileList()

        # The list of task groups we'll be executing for this batch of files
        self.taskGroupsLock = threading.Lock()
        self.taskGroups = {}

        # Zero if every taskGroup executed so far has succeeded.  Otherwise,
        # something greater than zero.
        self.exitCode = 0

        self.clearToNextLink = False

        stc = StandardTaskConfig.objects.get(id=str(pk))
        # These three may be concatenated/compared with other strings,
        # so they need to be bytestrings here
        filterFileEnd = str(stc.filter_file_end) if stc.filter_file_end else ''
        filterFileStart = str(stc.filter_file_start) if stc.filter_file_start else ''
        filterSubDir = str(stc.filter_subdir) if stc.filter_subdir else ''
        self.standardOutputFile = stc.stdout_file
        self.standardErrorFile = stc.stderr_file
        self.execute = stc.execute
        self.arguments = stc.arguments

        outputLock = threading.Lock()

        # Check if filterSubDir has been overridden for this Transfer/SIP
        try:
            var = UnitVariable.objects.get(unittype=self.unit.unitType,
                                           unituuid=self.unit.UUID,
                                           variable=self.execute)
        except (UnitVariable.DoesNotExist, UnitVariable.MultipleObjectsReturned):
            var = None

        if var:
            try:
                variableValue = ast.literal_eval(var.variablevalue)
            except SyntaxError:
                # SyntaxError = contents of variableValue weren't the expected dict
                pass
            else:
                filterSubDir = variableValue['filterSubDir']

        SIPReplacementDic = unit.getReplacementDic(unit.currentPath)
        # Escape all values for shell
        for key, value in SIPReplacementDic.items():
            SIPReplacementDic[key] = archivematicaFunctions.escapeForCommand(value)
        self.taskGroupsLock.acquire()

        currentTaskGroup = None

        for file, fileUnit in unit.fileList.items():
            if filterFileEnd:
                if not file.endswith(filterFileEnd):
                    continue
            if filterFileStart:
                if not os.path.basename(file).startswith(filterFileStart):
                    continue
            if filterSubDir:
                if not file.startswith(unit.pathString + filterSubDir):
                    continue

            standardOutputFile = self.standardOutputFile
            standardErrorFile = self.standardErrorFile
            arguments = self.arguments

            # Apply passvar replacement values
            if self.jobChainLink.passVar is not None:
                if isinstance(self.jobChainLink.passVar, list):
                    for passVar in self.jobChainLink.passVar:
                        if isinstance(passVar, ReplacementDict):
                            arguments, standardOutputFile, standardErrorFile = passVar.replace(arguments, standardOutputFile, standardErrorFile)
                elif isinstance(self.jobChainLink.passVar, ReplacementDict):
                    arguments, standardOutputFile, standardErrorFile = self.jobChainLink.passVar.replace(arguments, standardOutputFile, standardErrorFile)

            # Apply file replacement values
            commandReplacementDic = fileUnit.getReplacementDic()
            for key, value in commandReplacementDic.items():
                # Escape values for shell
                commandReplacementDic[key] = archivematicaFunctions.escapeForCommand(value)
            arguments, standardOutputFile, standardErrorFile = commandReplacementDic.replace(arguments, standardOutputFile, standardErrorFile)

            # Apply unit (SIP/Transfer) replacement values
            arguments, standardOutputFile, standardErrorFile = SIPReplacementDic.replace(arguments, standardOutputFile, standardErrorFile)

            if currentTaskGroup is None or currentTaskGroup.count() > BATCH_SIZE:
                currentTaskGroup = TaskGroup(self, self.execute)
                self.taskGroups[currentTaskGroup.UUID] = currentTaskGroup

            currentTaskGroup.addTask(
                arguments, standardOutputFile, standardErrorFile,
                outputLock, commandReplacementDic)

        for taskGroup in self.taskGroups.values():
            taskGroup.logTaskCreatedSQL()
            TaskGroupRunner.runTaskGroup(taskGroup, self.taskGroupFinished)

        self.clearToNextLink = True
        self.taskGroupsLock.release()

        # If the batch of files was empty, we can immediately proceed to the
        # next job in the chain.  Assume a successful status code.
        if self.taskGroups == {}:
            self.jobChainLink.linkProcessingComplete(0)
Ejemplo n.º 11
0
    exitCode = 0
    target = sys.argv[1]
    XMLfile = sys.argv[2]
    date = sys.argv[3]
    eventUUID = sys.argv[4]
    fileUUID  = sys.argv[5]
    fileGrpUse = sys.argv[6]

    if fileGrpUse in ["DSPACEMETS"]:
        print "file's fileGrpUse in exclusion list, skipping"
        exit(0)


    tempFile="/tmp/" + uuid.uuid4().__str__()

    command = "fits.sh -i \"" + escapeForCommand(target) + "\" -o \"" + tempFile + "\""
    #print >>sys.stderr, command
    #print >>sys.stderr,  shlex.split(command)
    try:
        p = subprocess.Popen(shlex.split(command), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

        #p.wait()
        output = p.communicate()
        retcode = p.returncode

        if output[0] != "":
            print output[0]
        if output[1] != "":
            print >>sys.stderr, output[1]

        #it executes check for errors
Ejemplo n.º 12
0
    fileUUID = sys.argv[5]
    fileGrpUse = sys.argv[6]

    if fileGrpUse in ["DSPACEMETS", "maildirFile"]:
        print "file's fileGrpUse in exclusion list, skipping"
        exit(0)

    sql = """SELECT fileUUID FROM FilesFits WHERE fileUUID = '%s';""" % (
        fileUUID)
    if len(databaseInterface.queryAllSQL(sql)):
        print >> sys.stderr, "Warning: Fits has already run on this file. Not running again."
        exit(0)

    tempFile = "/tmp/" + uuid.uuid4().__str__()

    command = "openfits -i \"" + escapeForCommand(
        target) + "\" -o \"" + tempFile + "\""
    #print >>sys.stderr, command
    #print >>sys.stderr,  shlex.split(command)
    try:
        p = subprocess.Popen(shlex.split(command),
                             stdin=subprocess.PIPE,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)

        #p.wait()
        output = p.communicate()
        retcode = p.returncode

        if output[0] != "":
            print output[0]
        if output[1] != "":
Ejemplo n.º 13
0
    eventUUID = sys.argv[4]
    fileUUID  = sys.argv[5]
    fileGrpUse = sys.argv[6]

    if fileGrpUse in ["DSPACEMETS", "maildirFile"]:
        print "file's fileGrpUse in exclusion list, skipping"
        exit(0)

    sql = """SELECT fileUUID FROM FilesFits WHERE fileUUID = '%s';""" % (fileUUID)
    if len(databaseInterface.queryAllSQL(sql)):
        print >>sys.stderr, "Warning: Fits has already run on this file. Not running again."
        exit(0)

    tempFile="/tmp/" + uuid.uuid4().__str__()

    command = "openfits -i \"" + escapeForCommand(target) + "\" -o \"" + tempFile + "\""
    try:
        p = subprocess.Popen(shlex.split(command), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

        output = p.communicate()
        retcode = p.returncode

        if output[0] != "":
            print output[0]
        if output[1] != "":
            print >>sys.stderr, output[1]

        #it executes check for errors
        if retcode != 0:
            print >>sys.stderr, "error code:" + retcode.__str__()
            print output[1]# sError
Ejemplo n.º 14
0
    date = sys.argv[3]
    eventUUID = sys.argv[4]
    fileUUID = sys.argv[5]
    fileGrpUse = sys.argv[6]

    if fileGrpUse in ["DSPACEMETS", "maildirFile"]:
        print "file's fileGrpUse in exclusion list, skipping"
        exit(0)

    if not FPCommandOutput.objects.filter(file=fileUUID).exists():
        print >> sys.stderr, "Warning: Fits has already run on this file. Not running again."
        exit(0)

    tempFile = "/tmp/" + uuid.uuid4().__str__()

    command = "fits.sh -i \"" + escapeForCommand(
        target) + "\" -o \"" + tempFile + "\""
    try:
        p = subprocess.Popen(shlex.split(command),
                             stdin=subprocess.PIPE,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)

        output = p.communicate()
        retcode = p.returncode

        if output[0] != "":
            print output[0]
        if output[1] != "":
            print >> sys.stderr, output[1]

        #it executes check for errors
Ejemplo n.º 15
0
import os
import sys
sys.path.append("/usr/lib/archivematica/archivematicaCommon")
from executeOrRunSubProcess import executeOrRun
from databaseFunctions import insertIntoEvents
from archivematicaFunctions import escapeForCommand

clamscanResultShouldBe="Infected files: 0"

if __name__ == '__main__':
    fileUUID = sys.argv[1]
    target =  sys.argv[2]
    date = sys.argv[3]
    taskUUID = sys.argv[4]

    command = 'clamdscan  - <"' + escapeForCommand(target).replace("$", "\\$") + '"'
    print >>sys.stderr, command
    commandVersion = "clamdscan -V"
    eventOutcome = "Pass"

    clamscanOutput = executeOrRun("bashScript", command, printing=False)
    clamscanVersionOutput = executeOrRun("command", commandVersion, printing=False)

    if clamscanOutput[0] or clamscanVersionOutput[0]:
        if clamscanVersionOutput[0]:
            print >>sys.stderr, clamscanVersionOutput
            exit(2)
        else:
            eventOutcome = "Fail"

    if eventOutcome == "Fail" or clamscanOutput[1].find(clamscanResultShouldBe) == -1:
Ejemplo n.º 16
0
import os
import sys
sys.path.append("/usr/lib/archivematica/archivematicaCommon")
from executeOrRunSubProcess import executeOrRun
from databaseFunctions import insertIntoEvents
from archivematicaFunctions import escapeForCommand

clamscanResultShouldBe = "Infected files: 0"

if __name__ == '__main__':
    fileUUID = sys.argv[1]
    target = sys.argv[2]
    date = sys.argv[3]
    taskUUID = sys.argv[4]

    command = 'clamdscan  - <"' + escapeForCommand(target).replace("$",
                                                                   "\\$") + '"'
    print >> sys.stderr, command
    commandVersion = "clamdscan -V"
    eventOutcome = "Pass"

    clamscanOutput = executeOrRun("bashScript", command, printing=False)
    clamscanVersionOutput = executeOrRun("command",
                                         commandVersion,
                                         printing=False)

    if clamscanOutput[0] or clamscanVersionOutput[0]:
        if clamscanVersionOutput[0]:
            print >> sys.stderr, clamscanVersionOutput
            exit(2)
        else:
            eventOutcome = "Fail"