예제 #1
0
파일: serialize.py 프로젝트: tv42/bugit
def serialize(
    snapshot,
    ticket,
    fp,
    ):
    print >>fp, 'ticket %s' % ticket
    number = snapshot.get(os.path.join(ticket, 'number'))
    if number is not None:
        number = number.rstrip()
        print >>fp, 'number #%s' % number
    names = sorted(snapshot.ls(os.path.join(ticket, 'name')))
    if names:
        print >>fp, textwrap.fill(
            ' '.join(names),
            initial_indent='name ',
            subsequent_indent='     ',
            break_long_words=False,
            )
    tags = set(snapshot.ls(os.path.join(ticket, 'tags')))
    if tags:
        tags = tagsort.human_friendly_tagsort(tags)
        print >>fp, textwrap.fill(
            ' '.join(tags),
            initial_indent='tags ',
            subsequent_indent='     ',
            break_long_words=False,
            )
    seen = set(snapshot.ls(os.path.join(ticket, 'seen')))
    if seen:
        # TODO map to tags
        seen = sorted(seen)
        print >>fp, textwrap.fill(
            ' '.join(seen),
            initial_indent='seen ',
            subsequent_indent='     ',
            break_long_words=False,
            )
    not_seen = set(snapshot.ls(os.path.join(ticket, 'not-seen')))
    if not_seen:
        # TODO map to tags
        not_seen = sorted(not_seen)
        print >>fp, textwrap.fill(
            ' '.join(not_seen),
            initial_indent='not-seen ',
            subsequent_indent='         ',
            break_long_words=False,
            )
    print >>fp
    description = snapshot.get(os.path.join(ticket, 'description'))
    if description is not None:
        description = description.rstrip()
        if description:
            print >>fp, description
            print >>fp
    print >>fp, '--'
    def get_the_rest():
        for name in snapshot.ls(ticket):
            if name in [
                'number',
                'description',
                ]:
                continue
            leading = name.split(os.sep, 1)[0]
            if leading in [
                'tags',
                'name',
                'seen',
                'not-seen',
                ]:
                continue
            yield name
    the_rest = sorted(get_the_rest())
    if the_rest:
        for name in the_rest:
            content = snapshot.get(os.path.join(ticket, name)).rstrip()
            if not content:
                print >>fp, name
            elif '\n' not in content:
                # one line with optional newline; distinguishable from
                # multiple lines by value starting on the same line,
                # even if it is wordwrapped for display

                # presence of final newline is not encoded in any way,
                # on purpose.
                print >>fp, '\n'.join(textwrap.wrap(
                        content,
                        initial_indent='%s=' % name,
                        subsequent_indent='\t',
                        break_long_words=False,
                        ))
            else:
                print >>fp, '%s=' % name
                print >>fp, '\n'.join([
                        '\t%s' % line
                        for line in content.split('\n')
                        ])
예제 #2
0
파일: test_tagsort.py 프로젝트: tv42/bugit
def test_priority_first():
    got = tagsort.human_friendly_tagsort(
        ['quux', 'priority:foo', 'bar', 'foo'])
    eq(got, ['priority:foo', 'bar', 'foo', 'quux'])
예제 #3
0
파일: test_tagsort.py 프로젝트: tv42/bugit
def test_unknown_semicolons_last():
    got = tagsort.human_friendly_tagsort(
        ['quux', 'froop:foo', 'bar', 'foo'])
    eq(got, ['bar', 'foo', 'quux', 'froop:foo'])
예제 #4
0
파일: test_tagsort.py 프로젝트: tv42/bugit
def test_alphabetical():
    got = tagsort.human_friendly_tagsort(
        ['quux', 'xyzzy', 'bar', 'foo'])
    eq(got, ['bar', 'foo', 'quux', 'xyzzy'])
예제 #5
0
파일: cmd_list.py 프로젝트: tv42/bugit
def main(appinfo, args):
    """List tickets matching given criteria"""
    parser = optparse.OptionParser(
        usage='%prog list [OPTS] [--] [SEARCH..]',
        )
    parser.add_option(
        '-v', '--verbose',
        help='show more information',
        action='count',
        )
    parser.add_option(
        '--tag',
        help='only list tickets having this tag',
        action='append',
        )
    parser.add_option(
        '--order',
        help='sort listing according to criteria',
        )
    parser.add_option(
        '--hide',
        metavar='FIELD',
        help='hide field from listing',
        )
    parser.add_option(
        '--show',
        metavar='FIELD',
        help='show field in listing',
        )
    (options, args) = parser.parse_args(args)

    if args:
        raise NotImplementedError(
            'TODO Full text search not supported yet.')

    def list_tickets():
        for (mode, type_, object, basename) in storage.git_ls_tree(
            path='',
            children=True,
            ):
            yield basename

    for ticket in list_tickets():
        number = storage.get(os.path.join(ticket, 'number'))
        if number is not None:
            number = number.rstrip()
            ident = '#%s' % number
        else:
            ident = ticket[:7]
        description = storage.get(os.path.join(ticket, 'description')).rstrip()
        tags = set(storage.ls(os.path.join(ticket, 'tags')))
        if options.tag:
            must = frozenset(options.tag)
            if not tags & must:
                continue
        tags = tagsort.human_friendly_tagsort(tags)
        if options.verbose:
            raise NotImplementedError
        if options.order:
            raise NotImplementedError
        if options.show:
            raise NotImplementedError
        if options.hide:
            raise NotImplementedError
        (title, description) = util.extract_title(description)
        print '%(ident)s\t%(title)s' % dict(
            ident=ident,
            title=title,
            )
        if tags:
            print textwrap.fill(
                ' '.join(tags),
                initial_indent='  ',
                subsequent_indent='  ',
                break_long_words=False,
                )