Пример #1
0
def _main(cmd):
    if cmd.encoding:
        encoding = cmd.encoding
    else:
        encoding = "iso8859-1" if cmd.Print else "utf-8"
    PMA.default_encoding = encoding
    for msg in messages_from_args(cmd.argv, cmd.msg_base_dirs):
        txt = formatted(msg, encoding=encoding)
        if cmd.Print:
            from plumbum import local as pbl
            from _TFL.FCM import open_tempfile
            subject = msg.scope.subject
            pbl.env["LC_ALL"] = "en_US.%s" % encoding.replace("-", "")
            with open_tempfile() as (file, temp_name):
                file.write(txt)
                file.close()
                a2ps = pbl ["a2ps"] \
                    [ "-s", "-8", "-nL", "-nu", "-nS"
                    , pyk.encoded ("-H%s" % (subject, ), encoding)
                    , "-P%s" % (cmd.printer_name, )
                    , temp_name
                    ]
                if cmd.verbose:
                    print(a2ps)
                a2ps()
        else:
            print(txt)
Пример #2
0
def _main (cmd) :
    if cmd.encoding :
        encoding = cmd.encoding
    else :
        encoding = "iso8859-1" if cmd.Print else "utf-8"
    PMA.default_encoding = encoding
    for msg in messages_from_args (cmd.argv, cmd.msg_base_dirs) :
        txt = formatted (msg, encoding = encoding)
        if cmd.Print :
            from plumbum  import local as pbl
            from _TFL.FCM import open_tempfile
            subject = msg.scope.subject
            pbl.env ["LC_ALL"] = "en_US.%s" % encoding.replace ("-", "")
            with open_tempfile () as (file, temp_name) :
                file.write (txt)
                file.close ()
                a2ps = pbl ["a2ps"] \
                    [ "-s", "-8", "-nL", "-nu", "-nS"
                    , pyk.encoded ("-H%s" % (subject, ), encoding)
                    , "-P%s" % (cmd.printer_name, )
                    , temp_name
                    ]
                if cmd.verbose :
                    print (a2ps)
                a2ps ()
        else :
            print (txt)
Пример #3
0
 def _handler (self, sub, cmd) :
     time_format        = _Sub_Command_.time_fmt = cmd.time_format
     i_enc              = cmd.input_encoding
     o_enc              = cmd.output_encoding
     pbl.env ["LC_ALL"] = "en_US.%s" % o_enc.replace ("-", "")
     for arg in cmd.argv :
         if arg in ("-", "STDIN") :
             file_time = time.localtime ()
             fn        = "STDIN"
             txt_in    = sys.stdin.read ()
         else :
             file_time = time.localtime (sos.path.getmtime (arg))
             fn        = Filename (arg).relative_to ("~/")
             with open (arg, "rb") as fi :
                 txt_in = fi.read ()
         txt     = txt_in.decode       (i_enc).lstrip ("\n").rstrip ()
         ft      = time.strftime       (time_format, file_time)
         txt_out = self._encoded       (txt, o_enc)
         out_opt = self._output_option (cmd)
         options = self._pbl_options   (* sub.options (cmd, fn, ft, out_opt))
         pbl_cmd = sub.pbl_cmd.__getitem__ (options)
         with open_tempfile ("wb") as (fo, no) :
             fo.write (txt_out)
             fo.close ()
             cx  = pbl_cmd [no]
             if cmd.verbose or cmd.dry_run :
                 print (pbl_cmd, arg, "[%s]" % no)
             if not cmd.dry_run :
                 if cmd.Display :
                     self._check_print (cmd, "Display")
                     with open_tempfile () as (fd, nd) :
                         fd.write (cx ())
                         fd.close ()
                         pbl [cmd.display_program] [nd] ()
                 elif cmd.PDF :
                     self._check_print (cmd, "PDF")
                     if fn == "-" :
                         target = "-"
                     else :
                         target = cmd.Output or \
                             (arg.replace (".", "__") + ".pdf")
                     pdf_opts   = self._pbl_options ("-", target)
                     px  = cx \
                         | (pbl [cmd.pdf_program].__getitem__ (pdf_opts))
                     px ()
                 else :
                     cx ()
Пример #4
0
 def _handler (self, sub, cmd) :
     time_format        = _Sub_Command_.time_fmt = cmd.time_format
     i_enc              = cmd.input_encoding
     o_enc              = cmd.output_encoding
     pbl.env ["LC_ALL"] = "en_US.%s" % o_enc.replace ("-", "")
     for arg in cmd.argv :
         if arg in ("-", "STDIN") :
             file_time = time.localtime ()
             fn        = "STDIN"
             txt_in    = sys.stdin.read ()
         else :
             file_time = time.localtime (sos.path.getmtime (arg))
             fn        = Filename (arg).relative_to ("~/")
             with open (arg, "rb") as fi :
                 txt_in = fi.read ()
         txt     = txt_in.decode  (i_enc)
         ft      = time.strftime  (time_format, file_time)
         txt_out = txt.encode     (o_enc, "replace")
         options = tuple \
             (pyk.encoded (o) for o in sub.options (cmd, fn, ft))
         pbl_cmd = sub.pbl_cmd.__getitem__ (options)
         with open_tempfile () as (fo, no) :
             fo.write (txt_out)
             fo.close ()
             cx  = pbl_cmd [no]
             if cmd.verbose or cmd.dry_run :
                 print (pbl_cmd, arg, "[%s]" % no)
             if not cmd.dry_run :
                 if cmd.Display :
                     if cmd.Print :
                         print \
                             ( "Specify either -Display or -Print, "
                               "but not both"
                             )
                         raise SystemExit (10)
                     with open_tempfile () as (fd, nd) :
                         fd.write (cx ())
                         fd.close ()
                         pbl [cmd.display_program] [nd] ()
                 else :
                     cx ()
Пример #5
0
 def _handler(self, sub, cmd):
     time_format = _Sub_Command_.time_fmt = cmd.time_format
     i_enc = cmd.input_encoding
     o_enc = cmd.output_encoding
     pbl.env["LC_ALL"] = "en_US.%s" % o_enc.replace("-", "")
     for arg in cmd.argv:
         if arg in ("-", "STDIN"):
             file_time = time.localtime()
             fn = "STDIN"
             txt_in = sys.stdin.read()
         else:
             file_time = time.localtime(sos.path.getmtime(arg))
             fn = Filename(arg).relative_to("~/")
             with open(arg, "rb") as fi:
                 txt_in = fi.read()
         txt = txt_in.decode(i_enc).lstrip("\n").rstrip()
         ft = time.strftime(time_format, file_time)
         txt_out = self._encoded(txt, o_enc)
         options = tuple \
             (pyk.encoded (o) for o in sub.options (cmd, fn, ft))
         pbl_cmd = sub.pbl_cmd.__getitem__(options)
         with open_tempfile() as (fo, no):
             fo.write(txt_out)
             fo.close()
             cx = pbl_cmd[no]
             if cmd.verbose or cmd.dry_run:
                 print(pbl_cmd, arg, "[%s]" % no)
             if not cmd.dry_run:
                 if cmd.Display:
                     if cmd.Print:
                         print \
                             ( "Specify either -Display or -Print, "
                               "but not both"
                             )
                         raise SystemExit(10)
                     with open_tempfile() as (fd, nd):
                         fd.write(cx())
                         fd.close()
                         pbl[cmd.display_program][nd]()
                 else:
                     cx()
Пример #6
0
 def _std_err_out (self) :
     with open_tempfile (mode = "r+b") as (stdout, out_name) :
         with open_tempfile (mode = "r+b") as (stderr, err_name) :
             yield stderr, stdout
             self.resulting_error  = self._read_result (stderr, err_name)
             self.resulting_output = self._read_result (stdout, out_name)
Пример #7
0
 def _std_err_out(self):
     with open_tempfile(mode="r+b") as (stdout, out_name):
         with open_tempfile(mode="r+b") as (stderr, err_name):
             yield stderr, stdout
             self.resulting_error = self._read_result(stderr, err_name)
             self.resulting_output = self._read_result(stdout, out_name)