Roundup Tracker - Issues

Message6912

Author tekberg
Recipients rouilj, tekberg
Date 2020-05-14.18:35:15
Message-id <1589481316.18.0.953671432578.issue2551084@roundup.psfhosted.org>
In-reply-to
This is the class I created to return the ids, instead of writing them to stdout. (There is more text after the class.)

from roundup.admin import AdminTool

class Admin(AdminTool):
    """
    Class to allow one to run roundup-admin using its API.
    Roundup writes results to (IDs on creates) to stdout.
    This version returns ints.
    Currently only create has been implemented. The other roundup-admin
    commands should work but haven't been tested.
    """
    def __init__(self, args):
        super().__init__()
        self.args = args

        # These are set in the AdminTool.main method. Since that isn't called we set them here.
        self.tracker_home = self.args.tracker_home
        self.separator = None
        self.print_designator = 0
        self.verbose = 1 if self.args.debug else 0

        # Override the create command with our version.
        self.commands['create'] = self.do_create
        if self.args.debug:
            print('Exit Admin.__init__')


    def do_create(self, args):
        """
        Same as AdminTool.do_create except this returns the result as an int,
        instead of writing to stdout.
        """
        try:
            # Capture output.
            old_stdout = sys.stdout
            sys.stdout = io.StringIO()
            super().do_create(args)
            sys.stdout.seek(0)
            return int(sys.stdout.readline())
        finally:
            sys.stdout = old_stdout
        return -1

This class gets instantiated the normal way

    tool = Admin(args)

and gets called with

    id = tool.run_command(command)
    ids[command[1]] = id

With the id being stored in a dict. A command is a list of roundup-admin arguments:

 ['create', 'msg', ...
 ['create', 'file', ...
 ['create', 'issue', 'files=%s' % ids['file'], 'messages=%s' % ids['message'], ...

Hopefully that make sense. Now on to your comment. This is purely a performance issue. The file data I'm creating is a PDF file, which may contain the '=' character. I'm still debugging the code. On my last test the acrobat reader didn't like the PDF file format. I'll need to compare what is in the tracker file system with the original PDF file.

To get to this point, especially the create issue command, I realized that the roundup-admin documentation could be beefed up a bit. I eventually determined that 'roundup-admin -i dir specification issue' helped with the files and messages properties of the create issue command.
History
Date User Action Args
2020-05-14 18:35:16tekbergsetmessageid: <1589481316.18.0.953671432578.issue2551084@roundup.psfhosted.org>
2020-05-14 18:35:16tekbergsetrecipients: + tekberg, rouilj
2020-05-14 18:35:16tekberglinkissue2551084 messages
2020-05-14 18:35:15tekbergcreate