Skip to content

Rework all info-like functions to use get_info() #7

Open

Description

@maphew

With 32fbd7b we have a working info command, and a get_info() function which builds a dictionary of useful attributes. Now we have the necessary plumbing to rework all the functions which go out one by one to fetch and build the attributes one at a time into simple lookups from the dict.

So instead of calling on 3 chained functions

def ball(packages):
    '''Print full local path name of package archive '''
    print "\n%s = %s" % (p, get_ball(p))

def get_ball (packagename):
    url, md5 = get_url (packagename)
    return '%s/%s' % (downloads, url)

def get_url (packagename):
    if not dists[distname].has_key (packagename) \
   ...~20 lines snipped...
    return filename, md5

we can just do

pkg_info = get_info(pkg)
print pkg_info['ball']

A delightful collapse in complexity which should make understanding and working on this program a whole lot easier and more enjoyable!

Before going to deep into touching all the info-like functions we should spend some time thinking about building a nested list/dictionary one level higher. Get_info() gives us a dict for each package, one at a time. Should we also build a list-of-pkg-dicts for everything all in one go?

Activity

  1. maphew commented on Jan 10, 2015

    @maphew
    OwnerAuthor

    when converting apt url to get_info() this morning I realized most of the lightweight info functions could be generalized into a single function along the lines of:

    def info(subcommand, packages):
        if not packages:
            help(//subcommand//)
            sys.stderr.write('No package specified. Try running "apt list"')
                return
    
        for p in packages:
            print '%-20s%-12s' % (p, get_info(p)[//subcommand//])
    

    Really the only thing that changes from function to function (for many) is the docstring and how the information is reported to the user. In the end though, it may this last item that dictates keeping the separate functions.

    Something to think about anyway.

  2. maphew commented on Apr 4, 2015

    @maphew
    OwnerAuthor

    this is postponed until after #35, clarifying the internal data model, because get_info right now doesn't properly distinguish between installed info and setup.ini info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions