Ejemplo 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)
Ejemplo 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)
Ejemplo n.º 3
0
 def import_path(self,path):
   """ Import module by given file path.
   This is not yet fully correct, this imports module as qname
   after all, not as a direct file.
   - path@str Path to file, can be relative or absolute.
   + module@Module Imported module.
   ? unknown
   = unsafe
   """
   qname = self.path2qname(path)
   log.info("importing path",path,"as",qname)
   return self.import_qname(qname)
Ejemplo n.º 4
0
 def import_path(self, path):
     """ Import module by given file path.
 This is not yet fully correct, this imports module as qname
 after all, not as a direct file.
 - path@str Path to file, can be relative or absolute.
 + module@Module Imported module.
 ? unknown
 = unsafe
 """
     qname = self.path2qname(path)
     log.info("importing path", path, "as", qname)
     return self.import_qname(qname)
Ejemplo n.º 5
0
 def chmod(self,file,mode):
   st = os.stat(file)
   if stat.S_IMODE(st.st_mode) != mode:
     log.info("mode",file,oct(mode))
     os.chmod(file,mode)
Ejemplo n.º 6
0
 def create_file_notify(self,file):
   if not os.path.exists(file):
     self.mkdir(os.path.dirname(file))
     log.info("create file",file)
Ejemplo n.º 7
0
 def chmod(self, file, mode):
     st = os.stat(file)
     if stat.S_IMODE(st.st_mode) != mode:
         log.info("mode", file, oct(mode))
         os.chmod(file, mode)
Ejemplo n.º 8
0
 def create_file_notify(self, file):
     if not os.path.exists(file):
         self.mkdir(os.path.dirname(file))
         log.info("create file", file)
Ejemplo 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
Ejemplo n.º 10
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