Exemplo n.º 1
0
def test():
    pytils.log.props.debug = 1
    log.addWriter(LogColor())
    log.addWriter(LogColorDetail())
    log.info("this is info message", 1, log)
    log.debug("this is debug message", 1.2345)
    log.error("this is error message", 0x80)
    log.system("this is system message", sys)
Exemplo n.º 2
0
def test():
  pytils.log.props.debug = 1
  log.addWriter(LogColor())
  log.addWriter(LogColorDetail())
  log.info("this is info message",1,log)
  log.debug("this is debug message",1.2345)
  log.error("this is error message",0x80)
  log.system("this is system message",sys)
Exemplo n.º 3
0
 def depends_fromfile(self):
   """ Find module dependencies from the file.
   """
   log.debug(self.name(),"finding dependencies from source",self.source())
   modules = list()
   file = self.source()
   if file == None:
     modules
   source = open(file).read()
   try:
     ast = parser.suite(source)
   except parser.ParserError,msg:
     raise SyntaxError(file + ":" + str(msg))
Exemplo n.º 4
0
 def depends_fromfile(self):
     """ Find module dependencies from the file.
 """
     log.debug(self.name(), "finding dependencies from source",
               self.source())
     modules = list()
     file = self.source()
     if file == None:
         modules
     source = open(file).read()
     try:
         ast = parser.suite(source)
     except parser.ParserError, msg:
         raise SyntaxError(file + ":" + str(msg))
Exemplo n.º 5
0
def which(cmd):
  """
  """
  file = None
  if os.path.exists(cmd):
    file = cmd
  else:
    for dir in os.environ.get("PATH").split(":"):
      file = dir + "/" + cmd
      if os.path.exists(file):
        break
      file = None
  if file == None:
    log.debug(cmd,"not found")
    return None
  if not os.path.isfile(file):
    log.error(file,"is not file")
    return None
  if not os.access(file,os.X_OK):
    log.error(file,"exits but does not has execute access")
    return None
  return file
Exemplo n.º 6
0
 def run(self, args):
     """ run(args@seq) @void, raises Unknown, syncs single, mutates:
 """
     for arg in args:
         log.debug(arg)
Exemplo n.º 7
0
 def __call__(self, *args, **kwds):
     if self.absprog == None:
         raise RuntimeError("program " + self.prog + " not found")
     stdin = 0
     stdout = 0
     stderr = 0
     execute = 0
     wait = 0
     nolog = 0
     # process args
     args2 = []  # running args
     args2.append(self.absprog)
     args3 = []  # tags into default args too
     args3.extend(self.args)  # default args
     args3.extend(args)  # per process args
     for arg in args3:
         if arg == program.stdin:
             stdin = 1
             continue
         if arg == program.stdout:
             stdout = 1
             continue
         if arg == program.stderr:
             stderr = 1
             continue
         if arg == program.execute:
             execute = 1
             continue
         if arg == program.wait:
             wait = 1
             continue
         if arg == program.nolog:
             nolog = 1
             continue
         args2.append(str(arg))
     # check dryrun
     if props.dryrun:
         if not nolog:
             log.info("would run:", " ".join(args2))
         return Null
     # make environment
     env = {}
     env.update(os.environ)
     env.update(kwds)
     # switch text if execute
     if execute:
         if not nolog:
             log.system("EXEC", " ".join(args2))
         os.execve(self.absprog, args2, env)  # pass exceptions
     # fork
     if stdin:
         in_read, in_write = os.pipe()
     if stdout:
         out_read, out_write = os.pipe()
     if stderr:
         err_read, err_write = os.pipe()
     if not nolog:
         log.system("'" + "' '".join(args2) + "'")
     pid = os.fork()  ### 8<
     if pid == 0:  ### child
         # direct fds
         if stdin:
             os.dup2(in_read, 0)
         if stdout:
             os.dup2(out_write, 1)
         if stderr:
             os.dup2(err_write, 2)
         for fd in range(3, MAXFD):  # close other than std fds
             try:
                 os.close(fd)
             except:
                 pass
         os.execve(self.absprog, args2, env)
     ### parent
     if stdin:
         stdin = os.fdopen(in_write, "w")
         os.close(in_read)
     else:
         stdin = None
     if stdout:
         stdout = os.fdopen(out_read, "r")
         os.close(out_write)
     else:
         stdout = None
     if stderr:
         stderr = os.fdopen(err_read, "r")
         os.close(err_write)
     else:
         stderr = None
     ps = process(pid, stdin, stdout, stderr)
     if wait:  # for convience
         if not nolog:
             log.debug("waiting for process", ps.pid)
         ps.wait()
     return ps
Exemplo n.º 8
0
 def run(self,args):
   """ run(args@seq) @void, raises Unknown, syncs single, mutates:
   """
   for arg in args:
     log.debug(arg)
Exemplo n.º 9
0
 def __call__(self,*args,**kwds):
   if self.absprog == None:
     raise RuntimeError("program " + self.prog + " not found")
   stdin = 0
   stdout = 0
   stderr = 0
   execute = 0
   wait = 0
   nolog = 0
   # process args
   args2 = [] # running args
   args2.append(self.absprog)
   args3 = [] # tags into default args too
   args3.extend(self.args) # default args
   args3.extend(args)      # per process args
   for arg in args3:
     if arg == program.stdin:
       stdin = 1
       continue
     if arg == program.stdout:
       stdout = 1
       continue
     if arg == program.stderr:
       stderr = 1
       continue
     if arg == program.execute:
       execute = 1
       continue
     if arg == program.wait:
       wait = 1
       continue
     if arg == program.nolog:
       nolog = 1
       continue
     args2.append(str(arg))
   # check dryrun
   if props.dryrun:
     if not nolog:
       log.info("would run:"," ".join(args2))
     return Null
   # make environment
   env = {}
   env.update(os.environ)
   env.update(kwds)
   # switch text if execute
   if execute:
     if not nolog:
       log.system("EXEC"," ".join(args2))
     os.execve(self.absprog,args2,env) # pass exceptions
   # fork
   if stdin:
     in_read,in_write = os.pipe()
   if stdout:
     out_read,out_write = os.pipe()
   if stderr:
     err_read,err_write = os.pipe()
   if not nolog:
     log.system("'" + "' '".join(args2) + "'")
   pid = os.fork() ### 8<
   if pid == 0: ### child
     # direct fds
     if stdin:
       os.dup2(in_read,0)
     if stdout:
       os.dup2(out_write,1)
     if stderr:
       os.dup2(err_write,2)
     for fd in range(3,MAXFD): # close other than std fds
       try:
         os.close(fd)
       except:
         pass
     os.execve(self.absprog,args2,env)
   ### parent
   if stdin:
     stdin = os.fdopen(in_write,"w")
     os.close(in_read)
   else:
     stdin = None
   if stdout:
     stdout = os.fdopen(out_read,"r")
     os.close(out_write)
   else:
     stdout = None
   if stderr:
     stderr = os.fdopen(err_read,"r")
     os.close(err_write)
   else:
     stderr = None
   ps = process(pid,stdin,stdout,stderr)
   if wait: # for convience
     if not nolog:
       log.debug("waiting for process",ps.pid)
     ps.wait()
   return ps
Exemplo n.º 10
0
 def update(self):
   if self._depends == None:
     log.debug("updating module dependencies",self.source())
     self._depends = pytils.rel.union(self.depends_runtime(),
                                     self.depends_fromfile())
   self._update_location()
Exemplo n.º 11
0
 def update(self):
     if self._depends == None:
         log.debug("updating module dependencies", self.source())
         self._depends = pytils.rel.union(self.depends_runtime(),
                                          self.depends_fromfile())
     self._update_location()