Example #1
0
 def __init__(self, command, file_name, context, delete=False, max_time=60):
     if not (command or file_name):
         raise ValueError('File or command must be specified')
     file_name, command = decode(file_name), decode(command)
     self._file=None
     self._command=None
     v={v: (escape_path(x) if isinstance(x, six.text_type) else str(x)) for v,x in six.iteritems(context) }
     dirname=None
     f=AdvancedFormatter()
     if file_name:
         fname=f.format(file_name,**v)
         if not fname:
             raise ValueError('No filename available after vars expansion')
         dirname=os.path.dirname(fname)
         if dirname and not os.path.exists(dirname):
             os.makedirs(dirname)
         if os.path.isdir(fname):
             raise ValueError('Filename %s is directory', 
                       fname)
         self._file=fname
     v['file_name'] = self._file or ''
     v['file_base_name'] = os.path.splitext(os.path.basename(self._file))[0] if self._file else ''
     v['file_dir'] = dirname or ''
     if command:
         cmd = f.format(command,**v)
         if not cmd:
             raise ValueError('No command available after vars expansion')
         self._command = cmd
         
     self._process=None
     self._stdout=''
     self._stderr=''
     self._killed=False
     self._timer=Timer(max_time, self.terminate)
     self._delete=delete
Example #2
0
 def conv_dict(d):
     if not d:
         return {}
     if not isinstance(d, tuple):
         raise ValueError('Expected tuple as value')
     res={}
     for i in range(0,len(d)-1, 2):
         res[lower_safe(d[i])]=decode(d[i+1])
     return res
Example #3
0
 def conv_dict(d):
     if not d:
         return {}
     if not isinstance(d, tuple):
         raise ValueError('Expected tuple as value')
     res = {}
     for i in range(0, len(d) - 1, 2):
         res[lower_safe(d[i])] = decode(d[i + 1])
     return res
Example #4
0
 def faddr(a):
     if not a.mailbox:
         return ''
     if not a.host:
         return decode(a.mailbox)
     return decode(a.mailbox + b'@' + a.host)