Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 612684 - new script to list / edit the resume list
Summary: new script to list / edit the resume list
Status: UNCONFIRMED
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Enhancement/Feature Requests (show other bugs)
Hardware: All Linux
: Normal enhancement with 1 vote (vote)
Assignee: Portage team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-03-15 08:55 UTC by Jocelyn Mayer
Modified: 2017-03-15 16:52 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jocelyn Mayer 2017-03-15 08:55:33 UTC
The attached script allows one to list and delete item(s) from the gentoo portage resume list.
It would be useful, imo, to have such a script in the app-portage/gentoolkit package.

Reproducible: Always

Steps to Reproduce:
As an example: list the current resume list:
# edit_resume_list.py -l
1: =cross-powerpc64-unknown-linux-gnu/binutils-2.25.1-r1
2: =cross-powerpc-unknown-linux-gnu/binutils-2.25.1-r1

Actual Results:  
This python script allows one to list and / or delete item(s) from the resume list


#!/bin/env python

import sys, portage

def item_dump(list, idx, dblen):
  if idx >= 0 and idx < dblen:
    print("%d: =%s" % (idx + 1, list[idx][2]))
  else:
    sys.exit('Error: invalid resume item index %d' % (idx + 1))

def item_del(list, idx, dblen):
  if idx >= 0 and idx < dblen:
    print("delete item %d: =%s" % (idx + 1, list[idx][2]))
    del list[idx]
  else:
    sys.exit('Error: invalid resume item index %d' % (idx + 1))

argv_len = len(sys.argv)
# If no arguments or '-l' argument, we want to dump
if argv_len == 1 or sys.argv[1] == '-l':
    #resume_list=portage.mtimedb["resume"]["mergelist"]
    resume_list=portage.mtimedb.get("resume", {}).get("mergelist")
    if resume_list == None:
        resume_len = 0
    else:
        resume_len=len(resume_list)
    # Exit directly if resume list is empty
    if resume_len == 0:
        sys.exit('Nothing in resume list')
    if argv_len == 3:
        i = int(sys.argv[2]) - 1
        item_dump(resume_list, i, resume_len)
    else:
        for i in range(resume_len):
            item_dump(resume_list, i, resume_len)
elif sys.argv[1] == '-d':
    #resume_list=portage.mtimedb["resume"]["mergelist"]
    resume_list=portage.mtimedb.get("resume", {}).get("mergelist")
    if resume_list == None:
        resume_len = 0
    else:
        resume_len=len(resume_list)
    # Exit directly if resume list is empty
    if resume_len == 0:
        sys.exit('Nothing in resume list')
    if argv_len == 3:
        if sys.argv[2] == 'all':
            # Delete all items from resume list
            for i in range(resume_len):
                item_del(resume_list, i, resume_len)
        else:
            # Delete one item from resume list
            i = int(sys.argv[2]) - 1
            item_del(resume_list, i, resume_len)
        # Commit changes in portage database
        portage.mtimedb.commit()
    else:
        sys.exit('Delete function must be given an argument')
    print("Usage: edit_resume_list.py [-h] [-l [<idx>] | -d [<idx>|all]]")
    print("\t-h: print this help")
    print("\t-l: list item(s) from the resume list")
    print("\t\tprint resume list entry <idx>")
    print("\t\tor all items if no index is given")
    print("\t-d: delete item(s) from the resume list")
    print("\t\tdelete resume list entry <idx>")
    print("\t\tor all items if \"all\" argument is specified")
    print("\tdefault action is to list all resume list items\n")
    sys.exit()
else:
    sys.exit('Unknown argument %s' % sys.argv[1])
Comment 1 Brian Dolbec (RETIRED) gentoo-dev 2017-03-15 09:51:22 UTC
Or make it into an emaint module
Comment 2 Paul Varner (RETIRED) gentoo-dev 2017-03-15 13:07:40 UTC
I'd prefer to see it as an emaint module, instead of being a standalone script in gentoolkit.
Comment 3 Brian Dolbec (RETIRED) gentoo-dev 2017-03-15 16:49:23 UTC
Emaint has been re-written as a plugin system.

There are 2 main files in the plugin module.

1) the modules directory __init__.py  It contains the info about the module, such as the options it takes, the file and class or classes it exports, etc.
You should be able to figure it out by looking at some existing modules.

2) the .py file which contains the class that will be run to perform the functions.  If possible try to use the generic check/fix options, but I don't think they will be much use for this.

There are several of the portage team members in IRC #gentoo-portage  that can help you with getting it ready for emaint as a plugin module.
Comment 4 Brian Dolbec (RETIRED) gentoo-dev 2017-03-15 16:52:39 UTC
I clicked save too soon :/

There is an existing resume emaint module, so it should be fairly easy to extend it's capabilities to add your new functionality and options.  It is already laid out, it just needs extending.