Example #1
0
 def onecmd(self, line):
     """`line` may be a `str` or an `unicode` object"""
     try:
         if isinstance(line, str):
             if self.interactive:
                 encoding = sys.stdin.encoding
             else:
                 encoding = getpreferredencoding() # sys.argv
             line = to_unicode(line, encoding)
         if self.interactive:
             line = line.replace('\\', '\\\\')
         rv = cmd.Cmd.onecmd(self, line) or 0
     except SystemExit:
         raise
     except AdminCommandError as e:
         printerr(_("Error: %(msg)s", msg=to_unicode(e)))
         if e.show_usage:
             print()
             self.do_help(e.cmd or self.arg_tokenize(line)[0])
         rv = 2
     except TracError as e:
         printerr(exception_to_unicode(e))
         rv = 2
     except Exception as e:
         printerr(exception_to_unicode(e))
         rv = 2
         if self.env_check():
             self.env.log.error("Exception in trac-admin command: %s",
                                exception_to_unicode(e, traceback=True))
     if not self.interactive:
         return rv
Example #2
0
 def onecmd(self, line):
     """`line` may be a `str` or an `unicode` object"""
     try:
         if isinstance(line, str):
             if self.interactive:
                 encoding = sys.stdin.encoding
             else:
                 encoding = getpreferredencoding() # sys.argv
             line = to_unicode(line, encoding)
         if self.interactive:
             line = line.replace('\\', '\\\\')
         rv = cmd.Cmd.onecmd(self, line) or 0
     except SystemExit:
         raise
     except AdminCommandError as e:
         printerr(_("Error: %(msg)s", msg=to_unicode(e)))
         if e.show_usage:
             print()
             self.do_help(e.cmd or self.arg_tokenize(line)[0])
         rv = 2
     except TracError as e:
         printerr(exception_to_unicode(e))
         rv = 2
     except Exception as e:
         printerr(exception_to_unicode(e))
         rv = 2
         if self.env_check():
             self.env.log.error("Exception in trac-admin command: %s",
                                exception_to_unicode(e, traceback=True))
     if not self.interactive:
         return rv
Example #3
0
def _format_datetime_without_babel(t, format):
    normalize_Z = False
    if format.lower().startswith('iso8601'):
        if 'date' in format:
            format = '%Y-%m-%d'
        elif 'time' in format:
            format = '%H:%M:%S%z'
            normalize_Z = True
        else:
            format = '%Y-%m-%dT%H:%M:%S%z'
            normalize_Z = True
    text = t.strftime(str(format))
    if normalize_Z:
        text = text.replace('+0000', 'Z')
        if not text.endswith('Z'):
            text = text[:-2] + ":" + text[-2:]
    encoding = getlocale(LC_TIME)[1] or getpreferredencoding() \
               or sys.getdefaultencoding()
    return unicode(text, encoding, 'replace')
Example #4
0
def _format_datetime_without_babel(t, format):
    normalize_Z = False
    if format.lower().startswith('iso8601'):
        if 'date' in format:
            format = '%Y-%m-%d'
        elif 'time' in format:
            format = '%H:%M:%S%z'
            normalize_Z = True
        else:
            format = '%Y-%m-%dT%H:%M:%S%z'
            normalize_Z = True
    text = t.strftime(str(format))
    if normalize_Z:
        text = text.replace('+0000', 'Z')
        if not text.endswith('Z'):
            text = text[:-2] + ":" + text[-2:]
    encoding = getlocale(LC_TIME)[1] or getpreferredencoding() \
               or sys.getdefaultencoding()
    return unicode(text, encoding, 'replace')
Example #5
0
def _format_datetime_without_babel(t, format):
    text = t.strftime(str(format))
    encoding = getlocale(LC_TIME)[1] or getpreferredencoding() \
               or sys.getdefaultencoding()
    return unicode(text, encoding, 'replace')
Example #6
0
 def str_path(path):
     if isinstance(path, unicode):
         path = path.encode(sys.getfilesystemencoding()
                            or getpreferredencoding())
     return path
Example #7
0
 def str_path(path):
     if isinstance(path, unicode):
         path = path.encode(sys.getfilesystemencoding() or
                            getpreferredencoding())
     return path
Example #8
0
def _format_datetime_without_babel(t, format):
    text = t.strftime(str(format))
    encoding = getlocale(LC_TIME)[1] or getpreferredencoding() \
               or sys.getdefaultencoding()
    return unicode(text, encoding, 'replace')