コード例 #1
0
ファイル: formatter.py プロジェクト: 4teamwork/ftw.upgrade
    def _split_lines(self, text, width):
        lines = list()
        main_indent = TERMINAL.length(re.match(r'( *)', text).group(1))
        # Wrap each line individually to allow for partial formatting
        for line in text.splitlines():

            # Get this line's indent and figure out what indent to use
            # if the line wraps. Account for lists of small variety.
            indent = TERMINAL.length(re.match(r'( *)', line).group(1))
            list_match = re.match(r'( *)(([*-+>]+|\w+\)|\w+\.) +)', line)
            if(list_match):
                sub_indent = indent + TERMINAL.length(list_match.group(2))
            else:
                sub_indent = indent

            # Textwrap will do all the hard work for us
            line = self._whitespace_matcher.sub(' ', line).strip()
            new_lines = textwrap.wrap(
                text=line,
                width=width,
                initial_indent=' ' * (indent - main_indent),
                subsequent_indent=' ' * (sub_indent - main_indent),
            )

            # Blank lines get eaten by textwrap, put it back with [' ']
            lines.extend(new_lines or [' '])

        return lines
コード例 #2
0
    def _split_lines(self, text, width):
        lines = list()
        main_indent = TERMINAL.length(re.match(r'( *)', text).group(1))
        # Wrap each line individually to allow for partial formatting
        for line in text.splitlines():

            # Get this line's indent and figure out what indent to use
            # if the line wraps. Account for lists of small variety.
            indent = TERMINAL.length(re.match(r'( *)', line).group(1))
            list_match = re.match(r'( *)(([*-+>]+|\w+\)|\w+\.) +)', line)
            if (list_match):
                sub_indent = indent + TERMINAL.length(list_match.group(2))
            else:
                sub_indent = indent

            # Textwrap will do all the hard work for us
            line = self._whitespace_matcher.sub(' ', line).strip()
            new_lines = textwrap.wrap(
                text=line,
                width=width,
                initial_indent=' ' * (indent - main_indent),
                subsequent_indent=' ' * (sub_indent - main_indent),
            )

            # Blank lines get eaten by textwrap, put it back with [' ']
            lines.extend(new_lines or [' '])

        return lines
コード例 #3
0
def format_proposed_upgrades(response):
    tabledata = []
    for upgrade in response.json():
        tabledata.append([
            upgrade_id_with_flags(upgrade, omit_flags=('proposed', )),
            TERMINAL.bold(upgrade.get('title')),
        ])
    print TERMINAL.bold('Proposed upgrades:')
    print_table(tabledata, ['ID:', 'Title:'])
コード例 #4
0
ファイル: list_cmd.py プロジェクト: Vinsurya/Plone
def format_proposed_upgrades(response):
    tabledata = []
    for upgrade in response.json():
        tabledata.append(
            [upgrade_id_with_flags(upgrade, omit_flags=('proposed',)),
             TERMINAL.bold(upgrade.get('title')),
             ])
    print TERMINAL.bold('Proposed upgrades:')
    print_table(tabledata, ['ID:', 'Title:'])
コード例 #5
0
ファイル: list_cmd.py プロジェクト: 4teamwork/ftw.upgrade
def format_profiles(response):
    tabledata = []
    for profile in response.json():
        tabledata.append(
            [colorize_profile_id(profile['id']),
             colorized_profile_flags(profile),
             TERMINAL.bold(profile['title']),
             colorized_profile_versions(profile)])

    print TERMINAL.bold('Installed profiles:')
    print_table(tabledata, ['ID:', '', 'Title:', 'Versions (DB/FS):'])
コード例 #6
0
ファイル: list_cmd.py プロジェクト: erral/ftw.upgrade
def format_profiles(response):
    tabledata = []
    for profile in response.json():
        tabledata.append([
            colorize_profile_id(profile['id']),
            colorized_profile_flags(profile),
            TERMINAL.bold(profile['title']),
            colorized_profile_versions(profile)
        ])

    print(TERMINAL.bold('Installed profiles:'))
    print_table(tabledata, ['ID:', '', 'Title:', 'Versions (DB/FS):'])
コード例 #7
0
ファイル: list_cmd.py プロジェクト: 4teamwork/ftw.upgrade
def format_proposed_upgrades(response):
    proposed = []
    for upgrade in response.json():
        is_deferrable = upgrade.get('deferrable', False)

        omit_flags = ('proposed', 'orphan') if is_deferrable else ('proposed',)

        table_row = [upgrade_id_with_flags(upgrade, omit_flags=omit_flags),
                     TERMINAL.bold(upgrade.get('title')),
                     ]
        proposed.append(table_row)

    print TERMINAL.bold('Proposed upgrades:')
    print_table(proposed, ['ID:', 'Title:'])
コード例 #8
0
ファイル: list_cmd.py プロジェクト: erral/ftw.upgrade
def format_proposed_upgrades(response):
    proposed = []
    for upgrade in response.json():
        is_deferrable = upgrade.get('deferrable', False)

        omit_flags = ('proposed',
                      'orphan') if is_deferrable else ('proposed', )

        table_row = [
            upgrade_id_with_flags(upgrade, omit_flags=omit_flags),
            TERMINAL.bold(upgrade.get('title')),
        ]
        proposed.append(table_row)

    print(TERMINAL.bold('Proposed upgrades:'))
    print_table(proposed, ['ID:', 'Title:'])
コード例 #9
0
    def _fill_text(self, text, width, indent):
        text = (re.compile('\[quote\].*?\[\/quote\]', re.DOTALL).sub(
            lambda match: (match.group(0).replace('\n', '[QUOTE:NEWLINE]')),
            text))

        text = '\n'.join(
            [indent + line for line in self._split_lines(text, width)])

        text = (re.compile('\[quote\](.*?)\[\/quote\]', re.DOTALL).sub(
            lambda match: TERMINAL.green(
                match.group(1).replace('\n', ' ').replace(
                    '[QUOTE:NEWLINE]', TERMINAL.normal + '\n    ' + TERMINAL.
                    green).rstrip(' ').strip('\n')), text))
        return text
コード例 #10
0
ファイル: formatter.py プロジェクト: 4teamwork/ftw.upgrade
    def _fill_text(self, text, width, indent):
        text = (re.compile('\[quote\].*?\[\/quote\]', re.DOTALL)
                .sub(lambda match: (
                    match.group(0)
                    .replace('\n', '[QUOTE:NEWLINE]')),
                     text))

        text = '\n'.join([indent + line for line
                          in self._split_lines(text, width)])

        text = (re.compile('\[quote\](.*?)\[\/quote\]', re.DOTALL)
                .sub(lambda match: TERMINAL.green(
                    match.group(1)
                    .replace('\n', ' ')
                    .replace('[QUOTE:NEWLINE]',
                             TERMINAL.normal + '\n    ' + TERMINAL.green)
                    .rstrip(' ').strip('\n')),
                     text))
        return text
コード例 #11
0
 def test_lstrip(self):
     self.assertEquals(TERMINAL.lstrip('  foo  '),
                       FakeTerminal().lstrip('  foo  '))
コード例 #12
0
 def test_center(self):
     self.assertEquals(TERMINAL.center('foo', 10),
                       FakeTerminal().center('foo', 10))
コード例 #13
0
 def test_rjust(self):
     self.assertEquals(TERMINAL.rjust('foo', 10),
                       FakeTerminal().rjust('foo', 10))
コード例 #14
0
 def test_ljust(self):
     self.assertEquals(TERMINAL.ljust('foo', 10),
                       FakeTerminal().ljust('foo', 10))
     self.assertEquals(TERMINAL.ljust(u'foo', 10),
                       FakeTerminal().ljust(u'foo', 10))
コード例 #15
0
 def test_lstrip(self):
     self.assertEquals(TERMINAL.lstrip('  foo  '),
                       FakeTerminal().lstrip('  foo  '))
コード例 #16
0
 def test_center(self):
     self.assertEquals(TERMINAL.center('foo', 10),
                       FakeTerminal().center('foo', 10))
コード例 #17
0
 def test_rjust(self):
     self.assertEquals(TERMINAL.rjust('foo', 10),
                       FakeTerminal().rjust('foo', 10))
コード例 #18
0
 def test_ljust(self):
     self.assertEquals(TERMINAL.ljust('foo', 10),
                       FakeTerminal().ljust('foo', 10))
     self.assertEquals(TERMINAL.ljust(u'foo', 10),
                       FakeTerminal().ljust(u'foo', 10))
コード例 #19
0
def translate(text):
    if text in ('positional arguments', 'optional arguments'):
        return TERMINAL.bold(_(text).upper())
    else:
        return _(text)
コード例 #20
0
ファイル: formatter.py プロジェクト: 4teamwork/ftw.upgrade
def translate(text):
    if text in ('positional arguments',
                'optional arguments'):
        return TERMINAL.bold(_(text).upper())
    else:
        return _(text)
コード例 #21
0
 def test_rstrip(self):
     self.assertEqual(TERMINAL.rstrip('  foo  '),
                      FakeTerminal().rstrip('  foo  '))