예제 #1
0
    def _stream_formatter(self, record):
        """The formatter for standard output."""
        if record.levelno < logging.DEBUG:
            print(record.levelname, end='')
        elif(record.levelno < logging.INFO):
            colourPrint(record.levelname, 'green', end='')
        elif(record.levelno < IMPORTANT):
            colourPrint(record.levelname, 'magenta', end='')
        elif(record.levelno < logging.WARNING):
            colourPrint(record.levelname, 'lightblue', end='')
        elif(record.levelno < logging.ERROR):
            colourPrint(record.levelname, 'brown', end='')
        else:
            colourPrint(record.levelname, 'red', end='')

        if record.levelno == logging.WARN:
            message = '{0}'.format(record.msg[record.msg.find(':') + 2:])
        else:
            message = '{0}'.format(record.msg)

        if len(message) > self.wrapperLength:
            tw = TextWrapper()
            tw.width = self.wrapperLength
            tw.subsequent_indent = ' ' * (len(record.levelname) + 2)
            tw.break_on_hyphens = False
            message = '\n'.join(tw.wrap(message))

        print(': ' + message)
예제 #2
0
def renameConfigFile(config, filename, newNames, dryRun=False, print=print):
    wrapper = TextWrapper()
    wrapper.width = 80
    wrapper.break_long_words = False
    wrapper.break_on_hyphens = False

    wrap = lambda names: '\n'.join(wrapper.wrap(' '.join(names)))

    didRename = False
    for propertyName, values in config.items('glyphs'):
        glyphNames = values.split()
        # print(propertyName, glyphNames)
        propChanged = False
        for name in glyphNames:
            if name in newNames:
                sectionChanged = True
        if sectionChanged:
            config.set('glyphs', propertyName, wrap(glyphNames) + '\n')
            didRename = True

        # config.set(section, option, value)
    if didRename:
        s = StringIO()
        config.write(s)
        s = s.getvalue()
        s = re.sub(r'\n(\w+)\s+=\s*', '\n\\1: ', s, flags=re.M)
        s = re.sub(r'((?:^|\n)\[[^\]]*\])', '\\1\n', s, flags=re.M)
        s = re.sub(r'\n\t\n', '\n\n', s, flags=re.M)
        s = s.strip() + '\n'
        print('Writing', filename)
        if not dryRun:
            with open(filename, 'w') as f:
                f.write(s)
예제 #3
0
    def _stream_formatter(self, record):
        """The formatter for standard output."""
        if record.levelno < logging.DEBUG:
            print(record.levelname, end='')
        elif(record.levelno < logging.INFO):
            colourPrint(record.levelname, 'green', end='')
        elif(record.levelno < IMPORTANT):
            colourPrint(record.levelname, 'magenta', end='')
        elif(record.levelno < logging.WARNING):
            colourPrint(record.levelname, 'lightblue', end='')
        elif(record.levelno < logging.ERROR):
            colourPrint(record.levelname, 'brown', end='')
        else:
            colourPrint(record.levelname, 'red', end='')

        if record.levelno == logging.WARN:
            message = '{0}'.format(record.msg[record.msg.find(':')+2:])
        else:
            message = '{0}'.format(record.msg)

        if len(message) > self.wrapperLength:
            tw = TextWrapper()
            tw.width = self.wrapperLength
            tw.subsequent_indent = ' ' * (len(record.levelname)+2)
            tw.break_on_hyphens = False
            message = '\n'.join(tw.wrap(message))

        print(': ' + message)
예제 #4
0
def updateConfigFile(config, filename, rmnames):
  wrapper = TextWrapper()
  wrapper.width = 80
  wrapper.break_long_words = False
  wrapper.break_on_hyphens = False
  wrap = lambda names: '\n'.join(wrapper.wrap(' '.join(names)))

  didChange = False

  for propertyName, values in config.items('glyphs'):
    glyphNames = values.split()
    propChanged = False
    glyphNames2 = [name for name in glyphNames if name not in rmnames]
    if len(glyphNames2) < len(glyphNames):
      print('[fontbuild.cfg] updating glyphs property', propertyName)
      config.set('glyphs', propertyName, wrap(glyphNames2)+'\n')
      didChange = True

  if didChange:
    s = StringIO()
    config.write(s)
    s = s.getvalue()
    s = re.sub(r'\n(\w+)\s+=\s*', '\n\\1: ', s, flags=re.M)
    s = re.sub(r'((?:^|\n)\[[^\]]*\])', '\\1\n', s, flags=re.M)
    s = re.sub(r'\n\t\n', '\n\n', s, flags=re.M)
    s = s.strip() + '\n'
    print('Writing', filename)
    if not dryRun:
      with open(filename, 'w') as f:
        f.write(s)
예제 #5
0
def wrap_for_make(items):
    line = join(sorted(items))
    wrapper = TextWrapper()
    wrapper.width = 60
    wrapper.break_on_hyphens = False
    wrapper.subsequent_indent = '\t' * 2
    return ' \\\n'.join(wrapper.wrap(line))
예제 #6
0
def print_terminal_help_topic(topic):
    helpmodule = importlib.import_module('cqlhelp.cql%s' % "".join(w.capitalize() for w in topic.split("_")))

    lines = helpmodule.__doc__.split('\n')

    try:
        rows, columns = subprocess.check_output(['stty', 'size']).split()
    except:
        rows = 25
        columns = 80

    wrapper = TextWrapper()
    wrapper.break_on_hyphens = False
    try:
        wrapper.width = int(columns)
    except ValueError:
        wrapper.width = 80

    for line in lines:
        if re.match(r'\s', line):
            line = line.strip()
            wrapper.initial_indent = '    '
            if line.startswith('-'):
                wrapper.subsequent_indent = '        '
            else:
                wrapper.subsequent_indent = '    '
        else:
            wrapper.initial_indent = ''
            wrapper.subsequent_indent = ''

        print(wrapper.fill(line))
예제 #7
0
 def product_attribute_formatter(self, key, value):
   # Products can include very long enzyme names which we don't want to break
   wrapper = TextWrapper()
   wrapper.initial_indent='FT                   '
   wrapper.subsequent_indent='FT                   '
   wrapper.width=79
   wrapper.break_on_hyphens=True
   attribute_text_template='/{attribute_key}="{attribute_value}"'
   attribute_text=attribute_text_template.format(attribute_key=key, attribute_value=value)
   return wrapper.fill(attribute_text)
예제 #8
0
 def product_attribute_formatter(self, key, value):
     # Products can include very long enzyme names which we don't want to break
     wrapper = TextWrapper()
     wrapper.initial_indent = 'FT                   '
     wrapper.subsequent_indent = 'FT                   '
     wrapper.width = 80  # can use 80 characters plus the new line
     wrapper.break_on_hyphens = True
     attribute_text_template = '/{attribute_key}="{attribute_value}"'
     attribute_text = attribute_text_template.format(attribute_key=key,
                                                     attribute_value=value)
     return wrapper.fill(attribute_text)
def linewrap(width = None):
    """Returns a function that wraps long lines to a max of 251 characters.
	Note that this function returns a list of lines, which is suitable as the
	argument for the spss.Submit function.
    """
    wrapper = TextWrapper()
    wrapper.width = width or 251
    wrapper.replace_whitespace = True
    wrapper.break_long_words = False
    wrapper.break_on_hyphens = False
    return wrapper.wrap
예제 #10
0
    def dry_run(self):
        from textwrap import TextWrapper
        wrapper = TextWrapper()
        wrapper.subsequent_indent = '  '
        wrapper.break_long_words = False
        wrapper.break_on_hyphens = False
        wrapper.width = 78

        commands = [
            '# Create %s' % self._object.full_name(),
            self.create_cmd(),
            self._hook.__str__(self._object)
        ]
        for command in commands:
            command.strip()
            if len(command) > 0:
                print ' \\\n'.join(wrapper.wrap(command))
        print ''
예제 #11
0
파일: var.py 프로젝트: neishm/pygeode
  def __str__ (self):
  # {{{
    from textwrap import TextWrapper
#    axes_list = '(' + ', '.join(a.name if a.name != '' else repr(a) for a in self.axes) + ')'
#    axes_details = ''.join(['  '+str(a) for a in self.axes])
#    s = repr(self) + ':\n\n  axes: ' + axes_list + '\n  shape: ' + str(self.shape) + '\n\n' + axes_details
    s = repr(self) + ':\n'
    if self.units != '':
      s += '  Units: ' + self.units
    s += '  Shape:'
    s += '  (' + ','.join(a.name for a in self.axes) + ')'
    s += '  (' + ','.join(str(len(a)) for a in self.axes) + ')\n'
    s += '  Axes:\n'
    for a in self.axes:
      s += '    '+str(a) + '\n'
    
    w = TextWrapper(width=80)
    w.initial_indent = w.subsequent_indent = '    '
    w.break_on_hyphens = False
    s += '  Attributes:\n' + w.fill(str(self.atts)) + '\n'
    s += '  Type:  %s (dtype="%s")' % (self.__class__.__name__, self.dtype.name)
    return s
예제 #12
0
    def __init__(self, message, *args):

        tw = TextWrapper()
        tw.width = 79
        tw.subsequent_indent = ''
        tw.break_on_hyphens = False

        # Adds custom error
        message += '\n\n'
        message += '*' * 79 + '\n'

        addenda = ('If you are not sure of how to solve this problem '
                   'please copy this error message and email to Jose '
                   'Sanchez-Gallego <*****@*****.**> and Drew '
                   'Chojnowski <*****@*****.**> and CC Demitri Muna '
                   '<*****@*****.**> and John Parejko '
                   '<*****@*****.**>.\n')
        addenda = '\n'.join(tw.wrap(addenda))
        message += addenda + '\n'

        message += '*' * 79 + '\n'

        super(PluggingException, self).__init__(message)
예제 #13
0
파일: var.py 프로젝트: weilin2018/pygeode
    def __str__(self):
        # {{{
        from textwrap import TextWrapper
        #    axes_list = '(' + ', '.join(a.name if a.name != '' else repr(a) for a in self.axes) + ')'
        #    axes_details = ''.join(['  '+str(a) for a in self.axes])
        #    s = repr(self) + ':\n\n  axes: ' + axes_list + '\n  shape: ' + str(self.shape) + '\n\n' + axes_details
        s = repr(self) + ':\n'
        if self.units != '':
            s += '  Units: ' + self.units
        s += '  Shape:'
        s += '  (' + ','.join(a.name for a in self.axes) + ')'
        s += '  (' + ','.join(str(len(a)) for a in self.axes) + ')\n'
        s += '  Axes:\n'
        for a in self.axes:
            s += '    ' + str(a) + '\n'

        w = TextWrapper(width=80)
        w.initial_indent = w.subsequent_indent = '    '
        w.break_on_hyphens = False
        s += '  Attributes:\n' + w.fill(str(self.atts)) + '\n'
        s += '  Type:  %s (dtype="%s")' % (self.__class__.__name__,
                                           self.dtype.name)
        return s
예제 #14
0
파일: dataset.py 프로젝트: aerler/pygeode
  def __str__ (self):
    from textwrap import TextWrapper
    # Degenerate case - no variables??
    if len(self.vars) == 0:
      return '<empty Dataset>'
    lines = list(self.__str_vararr__())
    pad1 = max(len(a[0]) for a in lines) + 1
    pad2 = max(len(a[1]) for a in lines) + 1

    s = '<' + self.__class__.__name__ + '>:\n'

    s = s + 'Vars:\n'
    for name,dims,shape in lines:
     s = s + '  ' + name.ljust(pad1) + dims.ljust(pad2) + shape + '\n'

    s = s + 'Axes:\n  ' + '  '.join([str(a)+'\n' for a in self.axes])

    w = TextWrapper(width=80)
    w.initial_indent = w.subsequent_indent = '  '
    w.break_on_hyphens = False
    s = s + 'Global Attributes:\n' + w.fill(str(self.atts))

    return s
예제 #15
0
파일: dataset.py 프로젝트: wdjlover/pygeode
    def __str__(self):
        # {{{
        from textwrap import TextWrapper
        # Degenerate case - no variables??
        if len(self.vars) == 0:
            return '<empty Dataset>'
        lines = list(self.__str_vararr__())
        pad1 = max(len(a[0]) for a in lines) + 1
        pad2 = max(len(a[1]) for a in lines) + 1

        s = '<' + self.__class__.__name__ + '>:\n'

        s = s + 'Vars:\n'
        for name, dims, shape in lines:
            s = s + '  ' + name.ljust(pad1) + dims.ljust(pad2) + shape + '\n'

        s = s + 'Axes:\n  ' + '  '.join([str(a) + '\n' for a in self.axes])

        w = TextWrapper(width=80)
        w.initial_indent = w.subsequent_indent = '  '
        w.break_on_hyphens = False
        s = s + 'Global Attributes:\n' + w.fill(str(self.atts))

        return s
예제 #16
0
def wrap_for_usage(prefix, items):
    line = prefix + join(sorted(items))
    wrapper = TextWrapper()
    wrapper.break_on_hyphens = False
    wrapper.subsequent_indent = ' ' * len(prefix)
    return wrapper.fill(line)