示例#1
0
 def mkfifo(self, file, mode=0666):
     if os.path.exists(file) and stat.S_ISFIFO(os.stat(file).st_mode):
         return file
     self.mkdir(os.path.dirname(file))
     log.system("fifo", file, str(oct(mode)), "create")
     os.mkfifo(file, mode)
     return file
示例#2
0
 def mkfifo(self,file,mode = 0666):
   if os.path.exists(file) and stat.S_ISFIFO(os.stat(file).st_mode):
     return file
   self.mkdir(os.path.dirname(file))
   log.system("fifo",file,str(oct(mode)),"create")
   os.mkfifo(file,mode)
   return file
示例#3
0
 def mksymlink(self, file, target):
     if (os.path.islink(file) and os.readlink(file) == target):
         return file
     self.mkdir(os.path.dirname(file))
     log.system("symlink", file, "->", target)
     os.symlink(target, file)
     return file
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)
示例#5
0
 def mksymlink(self,file,target):
   if (os.path.islink(file) and
       os.readlink(file) == target):
     return file
   self.mkdir(os.path.dirname(file))
   log.system("symlink",file,"->",target)
   os.symlink(target,file)
   return file
示例#6
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)
示例#7
0
 def mklink(self, file, target):
     """
 - cannot link to directory
 """
     if (os.path.exists(file) and os.path.exists(target)
             and os.stat(file).st_ino == os.stat(target).st_ino):
         return file
     self.mkdir(os.path.dirname(file))
     log.system("link", file, "->", target)
     os.link(target, file)
     return file
示例#8
0
 def mklink(self,file,target):
   """
   - cannot link to directory
   """
   if (os.path.exists(file) and
       os.path.exists(target) and
       os.stat(file).st_ino == os.stat(target).st_ino):
     return file
   self.mkdir(os.path.dirname(file))
   log.system("link",file,"->",target)
   os.link(target,file)
   return file
示例#9
0
 def mkdir(self,file,mode=0777):
   if file == "":
     return file
   if os.path.isdir(file):
     if not os.access(file,os.X_OK):
       raise IOError,file + " user has no executece access"
     return file
   if os.path.exists(file):
     raise IOError,file + " exists and is not a directory"
   self.mkdir(os.path.split(file)[0],mode)
   log.system("directory",file,str(oct(mode)),"create")
   os.mkdir(file,mode)
   return file    
示例#10
0
 def mkdir(self, file, mode=0777):
     if file == "":
         return file
     if os.path.isdir(file):
         if not os.access(file, os.X_OK):
             raise IOError, file + " user has no executece access"
         return file
     if os.path.exists(file):
         raise IOError, file + " exists and is not a directory"
     self.mkdir(os.path.split(file)[0], mode)
     log.system("directory", file, str(oct(mode)), "create")
     os.mkdir(file, mode)
     return file
示例#11
0
 def printer_plain_1_33_x2p(self, file):
     cmd = " ".join(
         [
             str(a2ps),
             "--portrait",
             "--columns=1",
             "--no-header",
             "--font-size=14",
             "--borders=no",
             file,
             "|",
             str(lpr),
         ]
     )
     log.system(cmd)
     os.system(cmd)
示例#12
0
 def mkdir(cls,apath,mode=0777):
   """ file.mkdir(apath@path, mode@int = 0777) @ file, raise IOError:
   """
   if type(apath) == str:
     apath = path(apath)
   if type(apath) != path:
     raise TypeError,"apath is not type path"
   #print apath,len(apath)
   for i in range(1,len(apath)+1):
     p = file(apath[:i])
     #print p
     if p.isdir():
       if not os.access(p,os.X_OK):
         raise IOError,p + " user has no executece access"
       continue
     if p.exists():
       raise IOError,p + " exists and is not a directory"
     log.system(p,"directory create")
     os.mkdir(p,mode)
   return file(apath)
示例#13
0
 def mkdir(cls, apath, mode=0777):
     """ file.mkdir(apath@path, mode@int = 0777) @ file, raise IOError:
 """
     if type(apath) == str:
         apath = path(apath)
     if type(apath) != path:
         raise TypeError, "apath is not type path"
     #print apath,len(apath)
     for i in range(1, len(apath) + 1):
         p = file(apath[:i])
         #print p
         if p.isdir():
             if not os.access(p, os.X_OK):
                 raise IOError, p + " user has no executece access"
             continue
         if p.exists():
             raise IOError, p + " exists and is not a directory"
         log.system(p, "directory create")
         os.mkdir(p, mode)
     return file(apath)
示例#14
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
示例#15
0
 def unlink(self,file):
   if not os.path.exits(file):
     return file
   log.system("unlink",file)
   os.unlink(file)
示例#16
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
示例#17
0
    mkdir = classmethod(mkdir)

    def mksymlink(cls, apath, target):
        """ file.symlink(linkfile@str,target@str) @str,raises IOError:
    """
        try:
            os.symlink(target, apath)
        except OSError, (errnro, errstr):
            if errnro == errno.EEXIST:
                if os.path.islink(apath) and os.readlink(apath) != target:
                    raise ExistsError
            else:
                raise OSError(errnro, errstr)
        else:
            log.system("symlinking:", apath, target)

    mksymlink = classmethod(mksymlink)


######################################################################
##


class FsFixed(FS, FsProps):
    """
  """
    def __init__(self, path):
        """
    ? ValueError path is not absolute
    """
示例#18
0
    return file(apath)
  mkdir = classmethod(mkdir)

  def mksymlink(cls,apath,target):
    """ file.symlink(linkfile@str,target@str) @str,raises IOError:
    """
    try:
      os.symlink(target,apath)
    except OSError,(errnro,errstr):
      if errnro == errno.EEXIST:
        if os.path.islink(apath) and os.readlink(apath) != target:
          raise ExistsError
      else:
        raise OSError(errnro,errstr)
    else:
      log.system("symlinking:",apath,target)
  mksymlink = classmethod(mksymlink)

######################################################################
##


class FsFixed(FS,FsProps):
  """
  """

  def __init__(self,path):
    """
    ? ValueError path is not absolute
    """
    if not os.path.isabs(path):
示例#19
0
 def unlink(self, file):
     if not os.path.exits(file):
         return file
     log.system("unlink", file)
     os.unlink(file)
示例#20
0
 def printer_postscript(self, file):
     cmd = " ".join([str(lpr), file])
     log.system(cmd)
     os.system(cmd)