コード例 #1
0
ファイル: fg.py プロジェクト: kzwkt/dff
class FG(Script):
  def __init__(self):
    Script.__init__(self, "fg")
    self.processusManager = ProcessusManager()
    self.vtreeprinter = VariantTreePrinter()
	
  def start(self, args):
    jobs = args["pid"].value()
    for proc in self.processusManager:
      if jobs == proc.pid:
        print "Displaying processus: " + str(proc.pid) + " name: " + str(proc.name) + " state: " + str(proc.state) + "\n"
        try :
	  text = self.processusManager[jobs].stream.get(0)
	  while text:
	    print text
	    text = self.processusManager[jobs].stream.get(0)
        except Empty:
          pass
        print self.vtreeprinter.fillMap(0, proc.res)
コード例 #2
0
ファイル: processus.py プロジェクト: kzwkt/dff
class Processus(Script):
    def __init__(self, mod, pid, args, exec_flags):
        #ProcessusManager().add(self) done elswere
        self.vfs = vfs.vfs()
        self.mod = mod
        self.inst = mod.create()
        self.exec_flags = exec_flags
        self.state = "wait"
        self.pid = pid
        self.args = args
        self.stream = Queue()
        self.event = threading.Event()
        self.vtreeprinter = VariantTreePrinter()
        self.timestart = 0
        self.timeend = 0
        self.streamOut = None
        #XXX test for singleton module that could be launch multiple time foder locker/
        self.error_result = ''
        self.lock = threading.Lock()
        self.lock.acquire()
        self.launchCount = 0
        self.lock.release()

    def launch(self, args):
        self.state = "Running"
        self.lock.acquire()
        self.launchCount += 1
        self.timestart = time.time()
        self.timeend = 0
        self.lock.release()
        try:
            self.args = args
            self.start(args)
            ModuleProcessusManager().update(self)
            try:
                if "gui" in self.exec_flags:
                    if "gui" in self.mod.flags:
                        for func in sched.event_func["add_qwidget"]:
                            func(self)
                if "console" in self.exec_flags:
                    if "console" in self.mod.flags:
                        self.c_display()
            except AttributeError:
                pass
        except:
            error = sys.exc_info()
            self.error(error)
        self.setState()
        self.event.set()
        if not "thread" in self.exec_flags:
            self.result()

    def result(self):
        if self.res and len(self.res):
            self.lock.acquire()  #singleton module can modify results
            buff = self.vtreeprinter.fillMap(0, self.res)
            self.lock.release()
            print buff

    def error(self, trace=None):
        if trace:
            err_type, err_value, err_traceback = trace
            res = "\n\nWhat:\n"
            res += "----------\n"
            err_typeval = traceback.format_exception_only(err_type, err_value)
            for err in err_typeval:
                res += err
            res += "\nWhere:\n"
            res += "-----------\n"
            err_trace = traceback.format_tb(err_traceback)
            for err in err_trace:
                res += err
            self.lock.acquire()
            #res = Variant(res)
            self.error_result += res
            self.state = "Fail"
            self.lock.release()

    def setState(self):
        #if trace == None and"gui" in self.exec_flags and "gui" in self.mod.flags:
        #self.state = "wait"
        self.lock.acquire()
        self.launchCount -= 1
        if self.launchCount <= 0:
            self.timeend = time.time()
            if self.state != "Fail":
                self.state = "Finish"
        self.lock.release()

    def __getattr__(self, attr):
        return getattr(self.inst, attr)
コード例 #3
0
class FILEINFO(Script): 
  def __init__(self):
      Script.__init__(self, "fileinfo")
      self.vtreeprinter = VariantTreePrinter()

      
  def start(self, args):
    buff = ""
    node = args["file"].value()
    if args.has_key("max-items"):
      self.vtreeprinter.setMaxItemListToExpand(args["max-items"].value())
    else:
      self.vtreeprinter.setMaxItemListToExpand(-1)
    if args.has_key("max-depth"):
      self.vtreeprinter.setMaxDepth(args["max-depth"].value())
    else:
      self.vtreeprinter.setMaxDepth(-1)
    buff += self.fillBase(node)
    buff += self.fillAttributes(node)
    self.res["result"] = Variant(buff)


  def fillBase(self, node):
    buff = ""
    fsobj = node.fsobj()
    fsobjname = ""
    if fsobj != None:
      fsobjname = fsobj.name
    buff += "name :\t\t" + str(node.name()) + "\n"
    buff += "node type :\t\t" 
    if node.isFile():
      buff += "file"
      if node.hasChildren():
        buff += " " + "with module(s) applied on it"
    if node.isDir():
      buff += "folder"
      if not node.hasChildren():
        buff += " " + "empty"
    if node.isDeleted():
      buff += " " + "deleted"
    buff += "\n"

    buff += self.fillCompatModule(node)
    if node.hasChildren():
      buff += self.fillChildren(node)

    buff += "generated by:\t\t"
    buff += fsobjname + "\n"
    
    buff += "size:\t\t\t"
    buff += str(node.size())
    buff += "\n"
    return buff


  def fillCompatModule(self, node):
    buff = ""
    l = node.compatibleModules()
    if len(l) > 0:
      buff += "relevant module(s) :\t"
      for i in l:
        buff += str(i) + " " 
    buff += "\n"
    return buff


  def fillChildren(self, node): 
    buff = "children\t\t"
    children = node.children()
    filessize = 0
    filecount = 0
    dircount = 0
    for child in children:
      if child.size():
        filessize += child.size()
        filecount += 1
      elif child.isDir() or child.hasChildren():
        dircount += 1
    if filecount > 0:
      buff += "file(s)"
      buff += str(filecount) + " totalizing " + str(filessize) + " bytes\n"
    if dircount > 0:
      buff += "folder(s) "
      buff += str(dircount) + "\n"
    return buff


  def fillAttributes(self, node):
    buff = ""
    vmap = node.attributes()
    if len(vmap) > 0:
      buff = self.vtreeprinter.fillMap(1, vmap, "attributes:\n")
    return buff
コード例 #4
0
ファイル: processus.py プロジェクト: arxsys/dff-api
class Processus(Script):
  def __init__(self, mod, pid, args, exec_flags):
    #ProcessusManager().add(self) done elswere
    self.vfs = vfs.vfs()
    self.mod = mod
    self.inst = mod.create()
    self.exec_flags = exec_flags
    self.state = "wait"
    self.pid =  pid 
    self.args = args
    self.stream = Queue()
    self.event = threading.Event()
    self.vtreeprinter = VariantTreePrinter()
    self.timestart = 0
    self.timeend = 0
    self.streamOut = None
    #XXX test for singleton module that could be launch multiple time foder locker/
    self.error_result = '' 
    self.lock = threading.Lock()
    self.lock.acquire()
    self.launchCount = 0  
    self.lock.release()

  def launch(self, args):
    self.state = "Running"
    self.lock.acquire()
    self.launchCount += 1
    self.timestart = time.time()
    self.timeend = 0
    self.lock.release()
    try :
      self.args = args 
      self.start(args)
      ModuleProcessusManager().update(self)
      try :
        if "gui" in self.exec_flags:
          if "gui" in self.mod.flags:
             for func in sched.event_func["add_qwidget"]:
	        func(self)
	if "console" in self.exec_flags:
	  if "console" in self.mod.flags:
		self.c_display()  
      except AttributeError:
	pass	
    except :
	 error = sys.exc_info()
         self.error(error)
    self.setState()
    self.event.set()
    if not "thread" in self.exec_flags:
	self.result()

  def result(self):
    if self.res and len(self.res):
      self.lock.acquire() #singleton module can modify results
      buff = self.vtreeprinter.fillMap(0, self.res)
      self.lock.release()
      print buff

  def error(self, trace = None):
     if trace:
	 err_type, err_value, err_traceback = trace
	 res = "\n\nWhat:\n"
         res +=  "----------\n"
         err_typeval = traceback.format_exception_only(err_type, err_value)
         for err in err_typeval:
           res += err
         res += "\nWhere:\n"
         res += "-----------\n"
	 err_trace =  traceback.format_tb(err_traceback)
         for err in err_trace:
           res += err
         self.lock.acquire()
 	 #res = Variant(res)
         self.error_result += res 
         self.state = "Fail"
	 self.lock.release()

  def setState(self):
    #if trace == None and"gui" in self.exec_flags and "gui" in self.mod.flags:
      #self.state = "wait"
    self.lock.acquire()
    self.launchCount -= 1
    if self.launchCount <= 0:
        self.timeend = time.time()
        if self.state != "Fail":
          self.state = "Finish"
    self.lock.release()

  def __getattr__(self, attr):
     return  getattr(self.inst, attr)
コード例 #5
0
ファイル: show_db.py プロジェクト: kzwkt/dff
class SHOW_DB(Script):
    def __init__(self):
        Script.__init__(self, "show_db")
        self.cm = ConfigManager.Get()
        self.processusManager = ProcessusManager()
        self.ti = typeId.Get()
        self.vtreeprinter = VariantTreePrinter()

    def processesByModuleName(self, modname):
        processes = []
        for proc in self.processusManager:
            if proc.name == modname:
                processes.append(proc)
        return processes

    def keyInConfigArguments(self, config, key):
        res = ""
        argument = config.argumentByName(key)
        if argument:
            if argument.type() == 0:
                res += "\n\targument switch"
            else:
                res += "\n\t\targument of type < " + self.ti.typeToName(
                    argument.type()) + " >"
            count = argument.parametersCount()
            if count:
                res += "\n\t\tpredefined parameters: "
                parameters = argument.parameters()
                for parameter in parameters:
                    if argument.type() == typeId.Node:
                        res += str(parameter.value().absolute())
                    else:
                        res += str(parameter.toString())
                count -= 1
                if count:
                    res += ", "
        return res

    def keyInConfigConstants(self, config, key):
        res = ""
        constant = config.constantByName(key)
        if constant:
            res += "\n\t\tconstant of type < " + self.ti.typeToName(
                constant.type()) + " >"
            items = constant.values()
            count = len(items)
            res += "\n\t\tdefined constants: "
            for item in items:
                if constant.type() == typeId.Node:
                    res += str(item.value().absolute())
                else:
                    res += str(item.toString())
                count -= 1
                if count:
                    res += ", "
        return res

    def keyInProcessArguments(self, processes, key):
        res = ""
        for proc in processes:
            if proc.args.has_key(key):
                res += "\n\t\tparameters provided to process id " + str(
                    proc.pid) + ":\n\t\t\t"
                arg = proc.args[key]
                if arg.type() == typeId.List:
                    vlist = arg.value()
                    lenvlist = len(vlist)
                    for item in vlist:
                        lenvlist -= 1
                        if item.type() == typeId.Node:
                            res += str(item.value().absolute())
                        else:
                            res += str(item.toString())
                        if lenvlist:
                            res += ", "
                elif arg.type() == typeId.Node:
                    res += str(arg.value().absolute())
                else:
                    res += str(arg.toString())
        return res

    def keyInVMap(self, vmap, key):
        res = ""
        for ikey in vmap.keys():
            vval = vmap[ikey]
            if vval.type() == typeId.Map:
                res += self.keyInVMap(vval.value(), key)
            elif vval.type() == typeId.List:
                res += self.keyInVList(vval.value(), key)
            elif ikey == key:
                if vval.type() == typeId.Node:
                    res += "\n\t\t\t" + str(vval.value().absolute())
                elif vval.type() == typeId.List:
                    res += self.vtreeprinter.fillList(3, vval.value())
                elif vval.type() == typeId.Map:
                    res += self.vtreeprinter.fillMap(3, vval.value())
                else:
                    res += "\n\t\t\t" + str(vval.toString())
                res += " (type < " + self.ti.typeToName(vval.type()) + " >)"
        return res

    def keyInVList(self, vlist, key):
        res = ""
        for item in vlist:
            if item.type() == typeId.Map:
                res += self.keyInVMap(item.value(), key)
            elif item.type() == typeId.List:
                res += self.keyInVList(item.value(), key)
        return res

    def keyInProcessResults(self, processes, key):
        res = ""
        for proc in processes:
            match = ""
            if len(proc.res):
                results = proc.res
                for ikey in results.keys():
                    item = results[ikey]
                    if ikey == key:
                        if item.type() == typeId.Node:
                            match += "\n\t\t\t" + str(item.value().absolute())
                        elif item.type() == typeId.List:
                            match += self.vtreeprinter.fillList(
                                3, item.value())
                        elif item.type() == typeId.Map:
                            match += self.vtreeprinter.fillMap(3, item.value())
                        else:
                            match += "\n\t\t\t" + str(item.toString())
                        match += " (type < " + self.ti.typeToName(
                            item.type()) + " >)"
                    elif item.type() == typeId.Map:
                        match += self.keyInVMap(item.value(), key)
                    elif item.type() == typeId.List:
                        match += self.keyInVList(item.value(), key)
            if match:
                res += "\n\t\tresults of process id " + str(proc.pid) + ":"
                res += match
        return res

    def get_dbinfo(self, key):
        res = ""
        configs = self.cm.configs()
        for config in configs:
            if config.origin() != "show_db":
                processes = self.processesByModuleName(config.origin())
                match = self.keyInConfigArguments(config, key)
                if match:
                    res += "\n\tmodule: " + config.origin()
                    res += match
                    res += self.keyInProcessArguments(processes, key)
                match = self.keyInConfigConstants(config, key)
                if match:
                    res += "\n\tmodule: " + config.origin()
                    res += match
                match = self.keyInProcessResults(processes, key)
                if match:
                    res += "\n\tmodule: " + config.origin()
                    res += match
        return res

    def fillProcessArgumentsKeys(self, keymap):
        for proc in self.processusManager:
            args = proc.args
            if args and proc.name != "show_db":
                for key in args.keys():
                    if not keymap.has_key(key):
                        keymap[key] = []
                    arg = args[key]
                    if arg.type() == 0:
                        res = "\n\tswitch argument"
                    else:
                        res = "\n\targument of type " + self.ti.typeToName(
                            arg.type())
                    res += " from " + proc.mod.conf.origin(
                    ) + " in processus " + str(proc.pid)
                    if arg.type() == typeId.List:
                        res += "\n\t\t"
                        vlist = arg.value()
                        lenvlist = len(vlist)
                        for item in vlist:
                            lenvlist -= 1
                            if item.type() == typeId.Node:
                                res += str(item.value().absolute())
                            else:
                                res += str(item.toString())
                            if lenvlist:
                                res += ", "
                    elif arg.type() == typeId.Node:
                        res += "\n\t\t"
                        res += str(arg.value().absolute())
                    elif arg.type() != 0:
                        res += "\n\t\t"
                        res += str(arg.toString())
                keymap[key].append(res)
        return keymap

    def fillKeyInList(self, vlist, keymap, cname, pid):
        for item in vlist:
            if item.type() == typeId.Map:
                keymap = self.fillKeyInMap(item.value(), keymap, cname, pid)
        return keymap

    def fillKeyInMap(self, vmap, keymap, cname, pid):
        for key in vmap.keys():
            if not keymap.has_key(key):
                keymap[key] = []
            val = vmap[key]
            if val.type() == typeId.List:
                res = "\n\tresult of type " + self.ti.typeToName(val.type())
                res += " from " + cname + " in processus " + str(pid)
                keymap[key].append(res)
                keymap = self.fillKeyInList(val.value(), keymap, cname, pid)
            elif val.type() == typeId.Map:
                res = "\n\tresult of type " + self.ti.typeToName(val.type())
                res += " from " + cname + " in processus " + str(pid)
                keymap[key].append(res)
                keymap = self.fillKeyInMap(val.value(), keymap, cname, pid)
            else:
                res = "\n\tresult of type " + self.ti.typeToName(val.type())
                res += " from " + cname + " in processus " + str(pid)
                if val.type() == typeId.Node:
                    res += "\n\t\t" + str(val.value().absolute())
                else:
                    res += "\n\t\t" + val.toString()
                keymap[key].append(res)
        return keymap

    def fillProcessResultsKeys(self, keymap):
        for proc in self.processusManager:
            results = proc.res
            if results and proc.name != "show_db":
                for key in results.keys():
                    if not keymap.has_key(key):
                        keymap[key] = []
                    item = results[key]
                    res = "\n\tresult of type " + self.ti.typeToName(
                        item.type())
                    res += " from " + proc.mod.conf.origin(
                    ) + " in processus " + str(proc.pid)
                    if item.type() == typeId.Node:
                        res += "\n\t\t" + str(item.value().absolute())
                        keymap[key].append(res)
                    elif item.type() == typeId.List:
                        keymap[key].append(res)
                        keymap = self.fillKeyInList(item.value(), keymap,
                                                    proc.mod.conf.origin(),
                                                    proc.pid)
                    elif item.type() == typeId.Map:
                        keymap[key].append(res)
                        keymap = self.fillKeyInMap(item.value(), keymap,
                                                   proc.mod.conf.origin(),
                                                   proc.pid)
                    else:
                        res += "\n\t\t" + str(item.value())
                        keymap[key].append(res)
        return keymap

    def fillAllArgumentsKey(self, keymap):
        configs = self.cm.configs()
        for config in configs:
            if config.origin() != "show_db":
                arguments = config.arguments()
                for argument in arguments:
                    argname = argument.name()
                    if not keymap.has_key(argname):
                        keymap[argname] = []
                    if argument.type() == 0:
                        stres = "\n\tswitch argument"
                    else:
                        stres = "\n\targument of type " + self.ti.typeToName(
                            argument.type())
                    stres += " from " + config.origin()
                    pcount = argument.parametersCount()
                    if pcount != 0:
                        parameters = argument.parameters()
                        stres += "\n\t\t"
                        for parameter in parameters:
                            if argument.type() == typeId.Node:
                                stres += str(parameter.value().absolute())
                            else:
                                stres += parameter.toString()
                            pcount -= 1
                            if pcount != 0:
                                stres += ", "
                    keymap[argname].append(stres)
        return keymap

    def fillAllConstantsKey(self, keymap):
        configs = self.cm.configs()
        for config in configs:
            if config.origin() != "show_db":
                constants = config.constants()
                for constant in constants:
                    cname = constant.name()
                    if not keymap.has_key(cname):
                        keymap[cname] = []
                    stres = "\n\tconstant of type " + self.ti.typeToName(
                        constant.type()) + " from " + config.origin()
                    items = constant.values()
                    pcount = len(items)
                    stres += "\n\t\t"
                    for item in items:
                        if item.type() == typeId.Node:
                            stres += str(item.value().absolute())
                        else:
                            stres += item.toString()
                        pcount -= 1
                        if pcount != 0:
                            stres += ", "
                    keymap[cname].append(stres)
        return keymap

    def get_alldbinfo(self):
        keymap = {}
        keymap = self.fillAllArgumentsKey(keymap)
        keymap = self.fillAllConstantsKey(keymap)
        keymap = self.fillProcessArgumentsKeys(keymap)
        keymap = self.fillProcessResultsKeys(keymap)
        res = ""
        for key in keymap.keys():
            res += "\n\n" + key
            for item in keymap[key]:
                res += item
        return res

    def start(self, args):
        res = "Variable DB\n"
        if args.has_key("key"):
            key = args['key'].value()
            res += "key <" + key + ">"
            match = self.get_dbinfo(key)
            if match:
                res += match
            else:
                res += " not found in db"
        else:
            res += self.get_alldbinfo()
        print res