openpyxl-redmine admin

Note

Below etest-admin is used in the examples. To perform real work replace etest by the acronym of the Redmine project procedure to be worked with (e.g. pmo, erd, crd…).

Warning

Good practice is to start each session with your working Redmine project by using the workflow_in_redmine command to certify that it’s the right Redmine project.

Overview

The admin module provides additional Redmine management features including creating and maintaining Redmine username-id and project_id identification files required by other modules in the package.

Authorization and execution is identical to that described in the workflow chapter and not repeated here.

Admin commands

Use the -h request to view module help text. Currently it shows:

$ ptc-admin -h
usage: ptc-admin [-h] [--username USERNAME]
                 password {create_userid_file,update_userid_file,
                 which_user,get_redmine_project_containers,
                 create_redmine_project_container,move_issue_to_container}

positional arguments:
  password              if --username then password, else user's API key
  {create_userid_file,update_userid_file,which_user,
  get_redmine_project_containers,create_redmine_project_container,
  move_issue_to_container}
    create_userid_file  creates a username:id file
    update_userid_file  updates a username:id file
    which_user          prints fuzzy matches to username
    get_redmine_project_containers
                        get redmine project container names and ids
    create_redmine_project_container
                        get usernames in id range, slow 1-by-1 hence
                        printout
    move_issue_to_container
                        moves issue to project container

optional arguments:
  -h, --help            show this help message and exit
  --username USERNAME   account with access rights to EuXFEL Redmine

Admin command parameters

Use the sub-command -h to view sub-command help text, e.g.

$ ptc-admin $API_key create_userid_file -h
usage: ptc-admin password create_userid_file [-h] filename

positional arguments:
  filename    filename to store results, type <class 'str'>

optional arguments:
  -h, --help  show this help message and exit

A cut-and-paste from source code listing for all sub-commands shows:

sub_commands = {
    'create_userid_file': {
        'help': 'creates a username:id file',
        'params': [('filename', str, 'filename to store results')]},
    'update_userid_file': {
        'help': 'updates a username:id file',
        'params': [('filename', str, 'filename of results to extend')]},
    'which_user': {
        'help': 'prints fuzzy matches to username ',
        'params': [('filename', str, 'filename of Redmine users & ids'),
                   ('username', str, 'name to match')]},
    'get_redmine_project_containers': {
        'help': 'get redmine project container names and ids',
        'params': [('filename', str, 'filename to store results')]},
    'create_redmine_project_container': {
        'help': 'get usernames in id range, slow 1-by-1 hence printout',
        'params': [('parent_project_id', int, 'parent container id'),
                   ('target_project_name', str, 'container name')]},
    'move_issue_to_container': {
        'help': 'moves issue to project container',
        'params': [('issue id', int, 'issue_id'),
                   ('project id', int, 'project_id')]}
}

create_userid_file

Creates a userid json file containing a Redmine user name keyed dictionary of Redmine ids. The dictionary is used during task Assignee name validation and id allocation.

$ ptc-admin $API_key create_userid_file playground/tmp.json
keep 1 Bartosz Poljancewicz (redmine)
miss 2
...
keep 244 Djelloul Boukhelef
^C KeyboardInterrupt

$ cat playground/tmp.json
{
    "user_ids": {
        "Bartosz Poljancewicz (redmine)": 1,
        ...
        "Djelloul Boukhelef": 244
    }
}

update_userid_file

Updates the userid json file by scanning the next 100 ids following the last in the file dictionary.

$ ptc-admin $API_key update_userid_file playground/tmp.json
last user id stored was: 244
keep 244 Djelloul Boukhelef
keep 245 Janusz Szuba
...
keep 255 Mikhail Yakopov
^Cadding 11 user ids
(base) youngman@cypc2:~/ptc/openpyxl-redmine$ !cat
cat playground/tmp.json
{
    "user_ids": {
        "Bartosz Poljancewicz (redmine)": 1,
        ...
        "Mikhail Yakopov": 255
    }
}

which_user

Dumps the best 3 userid name matches (and probabilities) in the dict to the name specified followed by the candidate’s Redmine ids. There are ~2k users registered and inspite of the mistype the fuzzywuzzy package gets it right, but clearly there has to be a limit and specifying first and lastnames is recommended (there may be two Yungmans)

$ ptc-admin $API_key which_user src/config/everybodies_ids.json yungman
best 3 matches to: yungman were: [('Christopher Youngman', 77),
    ('Ulf Brueggmann', 64), ('Oleg Engelmann', 64)]
redmine user ids: [('Christopher Youngman', 241),
    ('Ulf Brueggmann', 604), ('Oleg Engelmann', 652)]

$ ptc-admin $API_key which_user src/config/everybodies_ids.json
    'christ yungman'
best 3 matches to: christ yungman were: [('Christopher Youngman', 82),
    ('Eike-Christian Martens', 58), ('Christian Holz', 57)]
redmine user ids: [('Christopher Youngman', 241),
    ('Eike-Christian Martens', 754), ('Christian Holz', 693)]

get_redmine_project_containers

Project container (aka folder) names are not unique, but the project_id is.

$ ptc-admin $API_key get_redmine_project_containers
    playground/tmp.json
this will take some time - wait!
could see 529 projects
{'name': 'XFEL', 'created_on': '2014-10-01T15:03:50',
    'updated_on': '2014-10-01T15:03:50'}
...
{'name': 'XO Ticket ', 'created_on': '2019-10-02T13:44:04',
    'updated_on': '2019-10-07T09:42:50'}

$ cat playground/tmp.json
{
    "containers": {
        "317": {
            "name": "XFEL",
            "created_on": "2014-10-01T15:03:50",
            "updated_on": "2014-10-01T15:03:50"
        },
        "1121": {
            "name": "XO Ticket ",
            "created_on": "2019-10-02T13:44:04",
            "updated_on": "2019-10-07T09:42:50"
        },
    }
}

create_redmine_project_container

Warning

Not recommended - use with care

move_issue_to_container

Warning

Not recommended - use with care