Exemplo n.º 1
0
class ZipFile(Module):
    name = "Output to Zip"
    description = "Outputs files to a zip file"
    input = "files"
    root = False
    settings = {
        "Output File": Setting("file", ScriptUtils.getHomePath() + os.sep + "tbscriptoutput.zip", "Zip file to put contents into. *Overwrites if exists", ["*.zip"])
    }
    
    def run(self, input):
        print "Outputting", len(input), "items"
        output = zipfile.ZipFile (self.settings["Output File"].value, "w")
        for file in input: # assume input is set of something...
            print file.filename
            output.writestr(file.filename, file.data)
        output.close()
            
        
Exemplo n.º 2
0
class Log(Module):
    name = "Log"
    description = "Logs a string representation of the given input to a file"
    input = "any"
    root = False
    settings = {
        "Log Directory":
        Setting("directory", ScriptUtils.getHomePath(),
                "Directory to output log file(s) to")
    }

    def run(self, input):
        print "logging", len(input), "items"
        logfile = open(
            self.settings["Log Directory"].value + os.sep + "tbscript-" +
            str(datetime.now()) + ".log", "w")
        for item in input:  # assume input is set of something...
            logfile.write(str(item))
        logfile.close()