Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
maphew opened this issue Nov 1, 2014 · 2 comments
Open

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

maphew opened this issue Nov 1, 2014 · 2 comments

Comments

@maphew
Copy link
Owner

maphew commented Nov 1, 2014

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?

maphew added a commit that referenced this issue Nov 2, 2014
Follow up on #7, transforming all of setup.ini into a single python data
object
@maphew
Copy link
Owner Author

maphew commented Jan 10, 2015

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.

@maphew
Copy link
Owner Author

maphew commented Apr 4, 2015

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
Projects
None yet
Development

No branches or pull requests

1 participant