Tuesday, August 19, 2014

GSoC 2014, Week #13: All good things must come to an end

Hello everyone,

    As you might already know, this is the last post for my Google Summer of Code endeavour for this year. That said, that doesn't mean that this last week was spent doing nothing.

1.) Pull Requests, merged:

    All my previous pull requests for features that I wanted to add to layman have been merged with master. This includes the overlay-maker utility, squashfs-support, the portage sync plug-in, the ability to disable and enable a repository, modular overlay types, and more!

2.) Goodbye G-Common:

    G-common was an overlay type that was supported by Gentoo. It was decided that g-common was no longer going to be supported because no one (that we can tell) uses it. Typically you wouldn't see this type of thing happening, but g-common was replaced by g-sorcery. Which is the latest variant of that tool.

    I personally have no experience with either VCS, but I have spoken to the maintainer of g-sorcery.

3.) Modular Configuration types:

    Remember the RepoConfManager class? The class that handles all the repo configuration configuring has now been modified to support config type modules. So what does that mean? It means if a user has a configuration method that they want to support for layman they only need to add the module to layman's codebase and add the option to their layman.cfg.

    The same can be said for layman overlay types. If a user would like layman to support an overlay type that's not currently supported then all they need to do is add the module. If it works well, you could then submit a bug report and submit a patch with the new module and it might be added to layman on the next release.

4.) Documentation changes:

    With new features comes new documentation. This should always be the case, always. So users can be aware of the latest and greatest things that have been done to their newest release. In preparation for a new release, the man pages have been modified, the layman,cfg has been modified, and the version has been bumped to 2.2.0!

5.) Code refining:

    As I had said previously, you will never stop refining your code. I will bug squash till the day I die and I'll love every second of it too. After the documentation changes were made, the live ebuild (9999) for layman was updated as well. So users could now install (and test) the latest codebase for layman and return feedback to me to allow me to improve upon my code, or fix mistakes previously missed. A few bugs here and there have been found and squashed throughout the span of this week.

Goals for next week:
  • Go to School, get my education on.
  • Enjoy this last week of Summer.
    I would like to say thank you to everyone who assisted me throughout the span of this program and I thoroughly enjoyed myself working on layman, in an effort to contribute to the Gentoo community. As I said above, the layman-9999 ebuild is available for people to test, and I welcome all feedback!

With regards,
    Devan Franchini (twitch153)

Sunday, August 10, 2014

GSoC 2014, Week #12: Starting to wrap everything

Hello faithful readers!

    As the title says, things are beginning to get wrapped up nicely with a little bow and everything.

    A lot of time this week was spent on trying to get all my pull requests pushed to layman's master branch. Two notable ones (in my opinion) that got merged into the master branch were the overlay-maker tool and the portage sync plug-in. However, a few things needed to be changed to get these features up to snuff, particularly the overlay-maker.

1.) Overlay maker auto-completion improvements:

    Recall previously that I discussed that the overlay-maker has auto-completion for source URLs? Well the code for that was admittedly very horrid to go through. Not very clean, not very easily maintained.

    In order to improve upon that, I took the original concept and changed the implementation almost completely.

    Originally, if you were to give the overlay-maker the source URL of "git://git.overlays.gentoo.org/proj/layman.git" a series of string modifications were made to turn that source into two other source URLs along with the homepage and two separate feeds.

    To do this, there was a function called _set_gentoo_info() or something very similar to that. Sounds a little complex, but not really. Right? Right. I would agree with you. But imagine if you wanted to add support for another source URL for auto-completion of information? And then another? If we go under the assumption that the _set_gentoo_info() function was roughly 45-50 lines of code and we wanted to add two more source URLs for support then that's an additional 45-50 lines of code per source mirror!

    That's what we call "spaghettified code" and it's not pretty, and not always necessary.

    So for the sake of space, maintainability, and pride in your ability to code you want to take something like that down from 135-150 lines to 60 lines of code. Maintain the idea of modifying the URLs and feeds, and the homepage based on a specific URL mirror such as github, gentoo, or bitbucket. Then realize what differs from one github URL to another github URL. Those are your variables.

    After that it's as simple as creating a template constant that includes the auto-completion information for you. Once that's implemented then it's as simple as breaking up the URL into the variables you need and then perform interpolation on the template to get the correct overlay information.

   To anyone interested in seeing that concept in action then you should take a peak at: https://github.com/twitch153/layman/commit/7537f0b6216c2cbb13e2059edd9be0ed8e19a097

2.) Overlay-maker CLI interface:

    Up until now whenever a user wanted to tell the overlay-maker that they wanted to have auto-completion support for their overlay then they had to specify on every overlay creation. That can get tedious and sometimes annoying if you're working on adding a large amount of overlays to an xml. In favor of ease of use and not wanting users to curse my name at the end of their keyboard I gave users the ability to simply specify this via command line arguments.

    You can now do the following:
  • List all mirrors supported for auto-completion.
  • Tell the overlay-maker you only want the bare basics for the overlay(s) you are creating.
  • Select a mirror for auto-completion when creating your overlay.
  • Override certain checks when creating an overlay such as only saving the overlay.xml in your "overlay_defs"  location and giving an overlay a name of an overlay that already exists.
After both these changes were made to the overlay-maker then it was time that the pull-request was merged into master. It's only a matter of time before a new release is available to users (wink, wink).

3.) Merged test-suite and updated-updater:

    Both of these branches were merged to master along with the other two.

    The changes made to the test-suite were simple things like modifying what gets checked to assure that the test is working out exactly as it should.

     The changes made to updated-updater were also minimal. Now updater.py will check to see which conf_types are enabled and will then create the proper configuration files based on that.

    This brought the pull-request count down from 7 to 3! Which just shows how much closer we are to completion.

4.) Added layman-mounter tool:

    Recall in the past (we seem to do that a lot recently) that I added squashfs overlay support to layman. Well, it turns out that the method I used to add the support by unpacking the archive wasn't what my mentor had in mind (whoops!). After a little bit of discussion we came to the agreement that we wanted to add squashfs support to layman so that it would mount it read-only.

    The benefit of this is that you save space on your system. The drawback is that once you reboot your computer the overlay is no longer mounted.

   To address that drawback a utility script was created called "layman-mounter". This sounds a little...odd for a tool. What will this do? Well, it's not that odd. Really. I swear. And it does the following:
  1. lists all mountable overlays.
  2. lists the status of all mountable overlays (mounted/unmounted).
  3. Can mount overlay(s).
  4. Can unmount overlay(s).
    The beauty of that is that a user can then have layman-mounter invoked on every reboot to mount all your overlays. Or only select ones. The squashfs overlay code was also changed to reflect the behavior of being mounted instead of extracted. So look for this handy tool on the next release.

    Be aware that this method of squashfs overlay support does require you to have CONFIG_SQUASHFS enabled in your kernel though.

Goals for next week:
  •  Work on getting the last three pull-requests merged with layman's master branch.
  • Add modular configuration plug-ins.
  • Refine any code necessary in order to get a new release out before the end of the program.
As always, to anyone interested the source code and my commits can be found on git.overlays.gentoo.org/gitweb/[1] or on github.com[2] on layman's gsoc2014 branch.

  [1]http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=shortlog;h=refs/heads/gsoc2014
  [2]https://github.com/twitch153/layman/tree/gsoc2014

With regards,
    Devan Franchini (twitch153)

Friday, August 1, 2014

GSoC 2014, Week #11: Code Refinement at its finest

Hello again everyone,

This week was a fairly busy week due to my birthday and all the celebration that revolved around that.

Don't worry though! I didn't completely slack off. Work was accomplished.

1.) Modular overlay type plug-ins:

    If you can recall from my previous posts, I explained a little about the SquashFS overlay type as well as making the code for both Tar and SquashFS overlay types common in one class called ArchiveOverlay. If any of that doesn't sound familiar, no worries. I'll explain as we go along. But knowing of that will help you understand a bit better of what I'm about to discuss.

    This week I implemented a system in layman that will interact with modules. This commit: https://github.com/twitch153/layman/commit/0d4523513464c9bce836308d085995cb8a24644b is the module plug-in system and essentially what it does is look in a specified directory and find all available plug-ins. From there it will become a container of sorts that will obtain the class of any module, by name.

    This logic was then implemented into layman's overlay types. Recall wanting to install the overlay "twitch153". You would invoke layman as so: layman -a twitch153 and it would install (as long as you have git installed on your system). So you need to have git on your system and layman just magically takes care of it! Vioala!

    Well, in reality, you need git on your system because layman is informed that the type of the overlay is "git". The Overlay class will then find the proper class associated with "git", which in turn would be "GitOverlay". From there it would go to that class' add() function to see what steps would be necessary to add the overlay.

    As always, we strive to know more about why things happen. So why oh why am I explaining this to you and wasting the precious time you could be spending looking at lolcats and looking at other people's pictures of their food on their Facebook? Simple. Now that the module plug-in system has been implemented the Overlay class no longer needs to keep track of the available overlay type classes. This makes the main code much more maintainable, as well as making the addition of a new overlay type (such as squashfs) as simple as adding it to the correct directory and configuring it correctly.

    This also has another benefit to it. If this gets implemented into the main version of layman (which I would hope it does), it would make it possible to split out the modules into their own separate packages. This follows the Gentoo mentality of having choice. In previous versions of layman (even the current 2.1.0), you have specific USE flags that determine which VCSs you would add support for in layman. So if you were to install layman with USE='-darcs' you would not emerge the darcs version control system as a dependency. You would, however still have the code in layman that handles darcs overlays.

    This goes against the mentality of choice and forces users to have something on their system that they might never use. This is why the nature of modular overlay-type plug-ins is a great thing.

That's all that was accomplished this week. I do hope to work a little more next week to try to pick up some of the slack I left behind because of my birthday. But hey, if you can't celebrate your own birthday then I feel bad for you.

Goals for next week:
  •  Work on anything I need to in order to get the overlay-maker and the sync-plugin into the master branch of layman.
  • Discuss splitting the layman overlay-type plug-ins.
  • Refine layman's codebase.
As always, to anyone interested the source code and my commits can be found on git.overlays.gentoo.org/gitweb/[1] or on github.com[2] on layman's gsoc2014 branch.

  [1]http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=shortlog;h=refs/heads/gsoc2014
  [2]https://github.com/twitch153/layman/tree/gsoc2014

With regards,
    Devan Franchini (twitch153)

Friday, July 25, 2014

GSoC 2014, Week #10: Testing, Testing, 4, 5, 6...

Welcome back to all my long term readers, and to anyone new...welcome! Hope you enjoy this blog as much as I enjoy writing for it.

Unbeknown to me previously, my mentor had surgery while he was in the hospital. I was actually quite shocked to hear that, considering his condition previously. I just wanted to take the time here to say that I hope he has a good, and painless recovery. In the very least, I hope he is able to fully recover.

This week, the following has been accomplished:

1.) More docstring migrations to test suite:

   If you've been keeping up with my posts you'll know that this week is the second week that I've been working on migrating from docstring tests in layman's code, to a full test suite.

   Good news is, this is my second week and I should be wrapping it up at a good number of 13 tests.

   Although this means little to your average user, the tests are a necessary part of assuring that the code works precisely as it says it does.

   The keyword of the day is quality assurance, or simply put: QA. QA is HUGE in the Gentoo Developer community. It's like the law of the land, metaphorically speaking. As I am part of the amazing Gentoo developer community I too firmly believe in QA and its necessity in our code. That doesn't mean I don't believe people make mistakes though. That's why these tests exist, to confirm that everything is working as it should.

2.) New layman release:

   To those of you who have been waiting for an official version of layman to be released that includes all the amazing work that has been done up until...roughly my fifth week or so working on it, well wait no more! layman is now officially at version 2.1.0 (OoooOOoooh AaaAaaAAaah).

   A handful of things had to be done previously to allow this release to be done, including uploading the source to sourceforge.com, as well as updating the CHANGES file to allow users to see what has been changed since the last release. Nothing spectacular or amazing, but still a very necessary part of the development cycle.

   It's almost neglectful to just push out a new version of something without telling people what's new about it. Although, this is just my own opinion on that.

   So fire up your CPU and get to installing layman-2.1.0, and be sure to give me some proper feedback on things I've done to make your life easier/harder. Especially if I made it harder due to some unforeseen bug in my code.

   I apologize about the short post, fingers crossed that next week I can give the post just a little bit more substance.

Goals for next week:
  • Begin making layman VCS types modular.
  • Polish any code already in layman's codebase.
As always, to anyone interested the source code and my commits can be found on git.overlays.gentoo.org/gitweb/[1] or on github.com[2] on layman's gsoc2014 branch.

  [1]http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=shortlog;h=refs/heads/gsoc2014
  [2]https://github.com/twitch153/layman/tree/gsoc2014

With regards,
    Devan Franchini (twitch153)

Saturday, July 19, 2014

GSoC 2014, Week #9: Testing, testing, 1, 2, 3...

Hello everyone!

Good news! My mentor, Brian Dolbec (aka, dol-sen) has returned from the hospital! He has to take things slow but at least we know he made it out alive. Best wishes for him and I hope everything goes well for him.

In an attempt to make things as short as possible here is what has been accomplished this week:

1.) Improvements to overlay-maker class:

  1. Support for bitbucket.org mirror auto-fill info has been added. When a user now gives the overlay-maker class a bitbucket.org source URL it will now try to determine which VCS type it is, as well as the possible feed and homepage URLs.
  2. In addition to adding the support for bitbucket.org auto-fill info, the function necessary to auto-fill the info for source URLs has been cleaned up for improved maintainability.
  3. The get_input() and get_ans() functions were improved upon, to allow for a colorful interface with users, similar to the output messages of layman. This was done for overlay uniformity and to just be...pretty.
  4. Message output for the overlay-maker class has been migrated from your run-of-the-mill print() functions to the output suite that layman has readily available. Again, this brings a uniform look to the interactive sessions.
  5. The get_ans() and get_input() functions were moved to utils.py. This allows them to be where they should belong, as well as making them readily available to other classes that can make use of them (ex: db.py).

2.) Added disable and enable functionality to repos.conf files:

    Do you all remember in my last post where I mentioned the ability to disable and enable a repository in the make.conf files? Well, I discussed it over with dol-sen and we figured the best way to "disable" a repo for repos.conf files is to simply comment it out.

    Because that is the case, adding support was easy and is now readily available to be merged onto the master git branch,

3.) Began migration from doctests to test suite:

    Essentially a doctest is an in ".py" file test that was run via the python command line. It it a test that can be run to ensure that the function that is being tested, actually works. The drawback of doctests (in my humble opinion) is that they should belong in a separate place aside from the actual ".py" file that is being tested.

    If we're moving the tests to a separate place, why not just move them from doctests to the actual implementation of the test?

    That's what I aim to accomplish in this upcoming week (and what I've been working on this week).

    To see a full list of tests added to the test suite, look at the test-suite branch on my layman github repo.

 Goals for next week:

  •  Continue working on migrating docstring tests to a full test suite.
As always, to anyone interested the source code and my commits can be found on git.overlays.gentoo.org/gitweb/[1] or on github.com[2] on layman's gsoc2014 branch.

  [1]http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=shortlog;h=refs/heads/gsoc2014
  [2]https://github.com/twitch153/layman/tree/gsoc2014

With regards,
    Devan Franchini (twitch153)

Friday, July 11, 2014

GSoC 2014, Week #8: Squashing some bugs

Hello everyone!

This week has been good in making leeway with open bugs for layman!

To all of you who are unaware of what bugs are (no, not the squirmy wormy ones), a bug is essentially a report regarding a certain program or package or pretty much whatever. It can cover a vast amount of things.

If you are curious to see the open bug for layman, follow this link here:
https://bugs.gentoo.org/buglist.cgi?quicksearch=layman&list_id=2406998

But I'm getting ahead of myself, I'm going to begin by discussing what has been accomplished this week for layman.

1.) Centralize archive overlay type code:

    Last week I added support for squashfs overlay types for layman and it struck me: "Hrm, the code for both tar overlays and squashfs overlays are super similar. So similar, in fact that the differences are less than the similarities. I bet I could make a class that all archive types get their main functions from". So that's exactly what I did!

    I created the ArchiveOverlay class which took all the similar code from both archive overlay types and brought it together for any archive overlay type to grab from. It's like a goody bag of archive functions.

   So now any archive overlay type will now subclass from the ArchiveOverlay instead of the SourceOverlay class, which the ArchiveOverlay class subclasses from. It's a large hierarchy that is as follows:

                             <archive overlay type being installed>
                                                           |
                                                     Overlay
                                                           |
                                          <archive overlay type>
                                                           |
                                                ArchiveOverlay
                                                           |
                                                 SourceOverlay
                                                           |
                                              Overlay installed
                                                           |
                                                         ???
                                                           |
                                                       Profit!

    When you go to install a tar overlay layman will know it is a tar overlay type. The Overlay class will then call the class associated with that type, being tar. The class associate with tar is...TarOverlay! So the TarOverlay class is called, and it wants to call the add() function. However, if you looked at the source code you'd see that the TarOverlay class doesn't have an add() function. So where does it get it from? The ArchiveOverlay class that it subclasses.

   The ArchiveOverlay class requires you to extract the archive, that the TarOverlay class has in its own class, that's what makes this class different from say...the SquashfsOverlay class. The way you extract the archive is different.

   So the TarOverlay class will call the ArchiveOverlay class' add() function which in turn will make use of the TarOverlay class' extract() function. The ArchiveOverlay class' add() function isn't complete though, it will make use of the add() function in the SourceOverlay class, to do anything else that the ArchiveOverlay class' function didn't cover. After this is complete you can enjoy your newly installed archive overlay and feel happy that you didn't have to do anything more than: layman -a <overlay>

2.) Adding multiple description field support:

    If you look at this bug report here: https://bugs.gentoo.org/show_bug.cgi?id=465730 you will see that layman currently did not handle multiple description fields when there was the possibility to do so (mostly due to it being translated into different languages and whatnot). This week I added that support to the Overlay class.

    I personally believe it needs to be fine-tuned in a few ways. I think I will wait until dol-sen's recovery to fully tackle this bug though. In all honesty it would work fine now as it is, but would not take into account that lang attribute of the description xml tag.

    In accordance with the changes being made to the Overlay class to support multiple description fields, the layman sync plugin and the overlay-maker class both also have been modified to reflect the newly added support. The overlay-maker class does not currently add more than one description to the overlay being created though. A function has been added to grab the description though and can be used to prompt the user for multiple description fields if we decide that would best.

3.) Slight additions to overlay-maker class:

    A few changes have been made to the overlay-maker class.
  1. github,com and git.overlays.gentoo.org https:// URLs are now supported (why they weren't before, I have no idea...I blame the media).
  2. On a successful write, the user is now notified of where the xml file is being written to.
    Nothing massively crazy or huge, but helpful nonetheless.  I have hopes that the layman sync plugin module and the overlay-maker class will both be merged to layman's master branch soon. But no promises.

4.) Adds interactive session for unofficial overlay installs:

     https://bugs.gentoo.org/show_bug.cgi?id=315359 hoped to add more of a warning to users that are not installing official overlays. I added that feature which I also made configurable. So now a user will be prompted when installing unofficial layman overlays. They will be asked if they would like to continue even though the overlay is unofficial and if they respond with "yes" then they will continue on with the installation.

    This feature, as I said previously, will be configurable and will be able to be turned on or off with the "check_official" configuration option. The config option name might be changed in the near future and if it does you guys will be the first to know. Well, unless someone checks the source code and it's on there before I report it to you.

5.) CLI improvements:

    CLI or (command-line interface) is the method of calling a command through the command-line and give it certain command line arguments. You've seen this in layman -a <overlay> the command line arguments here are the -a flag and the <overlay> name.

    Keeping that in mind, know that if you previously wanted to install multiple layman overlays, you'd have to do it as so: layman -a <overlay 1> -a <overlay 2>. But to be honest that's not really a natural way of doing so. Over this week I changed the way layman handled certain actions such as --add or --delete. So now instead of having to call the flag multiple times you can simply append multiple overlay names to the actions, as so: layman -a <overlay 1> <overlay 2>.

    This was done by removing the action parameter of the argparser add_argument function, and replacing it with nargs = '+'. Doing this changes the behaviour of how the flag gathers its information and will allow users to perform layman actions in a more natural manner.

    Another minimal change has been made to the command line arguments as well. I have taken the liberty of renaming the --setup_help flag to --setup-help as it should have been originally. Whether I made this mistake or not, I'm not aware. But it's fixed now, which is good.

6.) Ability to enable or disable overlays:

    Imagine you're spending the night in a hotel that just so happens to have really crappy internet (it's not like they don't have multiple people using the internet all the time, all day long or anything...) and you want to prevent portage from accessing the ebuilds that a certain overlay has installed.

    So how would you tackle this problem? You could go ahead and delete the overlay. That would work, sure. Unfortunately, you'd have to download the overlay again after that's done. Which, given your current situation, would suck. Or you could just have portage "forget" the overlay exists.

    How? With layman's new ability to disable and then enable the overlay. Preface: this currently only works if you use the make.conf repo configuration method.

    If you were to look in your make.conf (located by default) in /var/lib/layman, you would see the following:

                                          PORTDIR_OVERLAY="
                                          <overlay locations>
                                          $PORTDIR_OVERLAY
                                          "

    With the ability to enable or disable an overlay, this had to be changed. It's a rather simple and elegant solution:

                                          ENABLED="
                                          <overlay 1 location>
                                          <overlay 2 location>
                                          "
                                          DISABLED="
                                          "
                                          PORTDIR_OVERLAY="
                                          $ENABLED
                                          $PORTDIR_OVERLAY
                                          "
    So now, portage will only acknowledge the overlays listed in the ENABLED var and ignore the overlays in the DISABLED var. When calling layman -D <overlay 1> the overlay location of <overlay 1> will then be moved to the DISABLED var in the make.conf. Which you can re-enabled by invoking the layman -E <overlay 1> command. I hope to incorporate this into the repos.conf repo configuration method as well but how layman should go about doing so needs to be discussed.

7.) Small fixes made to codebase:

    Two small fixes were made to layman's codebase.
  1. Improvements of the way layman handled the success or failure of a write to a repo config method has been fixed. layman will now take into account the fact that a user can be invoking more than one repo config method and one may fail while the other succeeds. Previously this would lead to a false positive. That behaviour has been fixed.
  2. layman previously falsely informed a user that an overlay was not supported if they ran layman -v -i <overlay> and the overlay was actually supported. This was because layman was unpacking the values from the Info() function and unpacked the boolean for "supported" in the position of the boolean for "official".
 Goals for next week:
  •  Begin working on migrating docstring tests to a full test suite.
    • This goal has been allotted to take 2 weeks so don't expect a massively fulfilling report next week. 
As always, to anyone interested the source code and my commits can be found on git.overlays.gentoo.org/gitweb/[1] or on github.com[2] on layman's gsoc2014 branch.

  [1]http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=shortlog;h=refs/heads/gsoc2014
  [2]https://github.com/twitch153/layman/tree/gsoc2014

With regards,
    Devan Franchini (twitch153)

Saturday, July 5, 2014

GSoC 2014, Week #7: Going at a fine pace

Hello everyone!

This week has gone pretty well. I took yesterday off to spend the 4th of July with my family and I had some good times, but now is the time that I inform all you lovely readers what was accomplished throughout this week regarding layman.

A word beforehand, my mentor Brian Dolbec (dol-sen) is currently in the hospital and will be there at least until July 13th. I just wanted him to know that my best wishes go out to him and I hope the best for him.

While dol-sen is in the hospital recovering I will be bugging my other mentor (quantumsummers) a lot more than I bet he would hope for because I need the green light on my pull requests I have for certain features that I'll be elaborating more on in this post.

1.) Portage sync module plugin:

    The portage sync module plugin for layman should be ready to be merged with the master git branch. I required more seasoned eyes to skim through it and let me know that it is before merging it. The only change made to it throughout this week was that I added fetching of the remote list to layman by default when running any of the actions in the sync module.

2.) Overlay-maker class:

    This week has included a two changes for the overlay-maker class, one of which was made that directly affect the user.

    1.) The old method of branch tags has been removed:
            I previously added branch support for multiple overlay types.
    In order to declare an overlay had a branch you would simply add the
    <branch></branch> tags to indicate that the overlay uses this "branch".
    This has been changed. When you are creating an overlay.xml file now you
    can specify the branch for multiple source tags. ex.) You have an overlay
    located at http://github.com/twitch153/ebuilds.git and it uses the branch
    experimental, but you have another source of the same repo at
    git://foobar.com/twitch153/repo.git and it uses the branch unofficial. With
    the previous nature of the <branch></branch> xml tag you couldn't
    specify both tags for both sources and you'd be left sad and full of hate
    and anger toward the dev that made the decision to make it such a static
    thing. With the new nature of the branch info though you could do this:

        <source type="git" branch="experimental">http://github.com/twitch153/ebuilds.git</source>
        <source type="git" branch="unofficial">git://foobar.com/twitch153/repo.git</source>

     and that would work perfectly well! Of course, with this new change comes the need to modify the .dtd file again, so I'll have to create a patch and run that by the maintainers of the .dtd file once again. That'll be done once these changes get merged to the master branch.

    2.) Proper feed support was added for the overlay-maker class and
    overlay dictionaries:
        If a user was to run through an interactive overlay maker session and
    specified the feeds to the overlay and wrote the overlay to the file...it
    wouldn't work! Why? Well, it's simple really. The overlay-maker class is an
    interactive session that will create a python dictionary of overlay
    elements. However, due to my clear lack of perfection I used an incorrect
    key for the overlay feeds and therefore the overlay class would totally
    overlook the feeds when creating an overlay object to be written to an
    xml.

3.) Squashfs overlay support:

   For those of you unaware of what squashfs is: it is an archive-like file system. There are absolutely tons of different things about it that I could list but I lack the proper knowledge to continue on by saying anything other than it is like an archiving type similar to tar or zip.  So, in our vast abundance of knowledge we already know that layman already supports tar overlays so is squashfs really all that different? The answer is an emphatic no. It is my own belief that you could probably go even further and say that adding any sort of archive overlay support to layman would be so similar that you might want to make an archive class where all archive overlay types would get their main functions from and go from there based on the little differences that they do have.

    However, this week I added both squashfs overlay support and an external test to see if it works in practice and not just on paper (hint: it does).

Goals for next week:
  • Improve on the archive overlay types and possibly make an archive class to centralize the main functions necessary for each type.
  • Discuss with quantumsummers about moving some of my work to the master branch.
  • Focus on squashing some bugs for layman.
As always, to anyone interested the source code and my commits can be found on git.overlays.gentoo.org/gitweb/[1] or on github.com[2] on layman's gsoc2014 branch.

  [1]http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=shortlog;h=refs/heads/gsoc2014
  [2]https://github.com/twitch153/layman/tree/gsoc2014

With regards,
    Devan Franchini (twitch153) 

Friday, June 27, 2014

GSoC 2014, Week #6: Hit the mid point

You know, they say that the point of no return is when you've gone so far that turning back just seems impossible.

Typically that sounds pretty dismal. But in this case it's the exact opposite!

This week has been a week of good fortune for me and this is why:

1.) I passed my GSoC midterm evaluations! Which means we've hit the midpoint for the GSoC program.

2.) My main computer is alive again! My computer (a.k.a Buff-Kitty) is finally alive after me destroying tons of computer parts (I don't want to talk about it...). It's been awhile but I can confidently say you were missed, Buff-Kitty.

In celebration of new life, a lolcat shall be posted:



You sure do, Buff-Kitty. You sure do.

Enough of that though. Onto the goodies of the week. So what's new?

Recall what I said my plans for this week were:
  • Revamp the overlay definition generator script.
  • Polish up the portage sync module.
  • Begin adding squashfs overlay support. 
 So what was accomplished this week? To all of you who were ecstatic about having squashfs overlay support well I have good news for you. The good news is that you'll get it...eventually. But not this week. Because I was being doing a complete overhaul on the overlay definition generator script and polishing up the portage sync module to add some nifty new features to it.

Let's start with the sync plugin module since it didn't get an entirely new overhaul.

 1.) Portage Sync Module:

  Recall in my previous post how I explained that the sync module made use of two variable methods of running: the API method, and the subprocess method. By default, the sync plugin should run via the API method, however, if something occurs that prevents this from happening then portage will fall back on the subprocess method. Although to be honest with you I don't know what could happen to prevent you from running a program's API yet, still be able to run the subprocess. That's an aside though.

  "Okay, I remember all of this and I remember that it interacts via a file in your repos.conf folder, big deal, what's new?" Nice to see you're just as impatient as I am. So I'll just cut to the chase. You can tell portage to sync a repo that doesn't exist. Just because the repo is listed in the repos.conf config file it doesn't necessarily mean that the repository is installed. This would cause a failure to sync the repo (for obvious reasons).

  Fear not! For a new feature to the API variant of the plugin has been added. This feature will check the configuration for the repository in the repos.conf config file and create a new overlay definition using the newly revamped overlay-maker class. After creating the new overlay definition.xml file it will then install the new repo for you. Then when you go to sync the repo again, it will successfully sync the repo (for obvious reasons).

2.) Overlay-Maker class:

  Previously this was just a simple script to prompt users for overlay information and then to pipe it into a script. Throughout this week that has changed and the overlay-maker has been turned into a little more than that. By making use of the new overlay-maker class you can make layman overlay definitions and write them to a desired file via a script, or an interactive command line interface. Further more the overlay-maker adds auto-completion support for overlays that have mirrors from github.com or from git.overlays.gentoo.org.

  If given a source URL that is from either of those two locations the script will automatically fill out the rest of the available sources for that overlay along with the homepage and feeds available.

  It is possible that before the end of this GSoC that the overlay-maker will be able to be ran through an array of subparser commands from layman, however even if I am not able to get it accomplished prior to the end of the program, I do hope to get it done so that users can add overlay definitions simply by doing something like:

    layman repo --add twitch153

  This would then bring up the interactive interface to add the overlay by the name of twitch153 and add it to a file of your choice. It would also make it easier for developers maintaining large repository.xml files. If they wanted to complete remove a repo from a large repository.xml file and this method of interaction was possible they could run:

    layman repo --location=repository.xml --del twitch153

  And have the peace of mind of knowing it is gone for good. The other positive aspect of this is that you could then create a script or a cron to add/remove repos from a .xml file. The possibilities are exciting for sure.

  For all of you layman users, during this upcoming week or weekend a new release candidate for layman is going to the portage tree and will be available for all to install and test. So enjoy that and I encourage feedback about it including things you would like to see in the next RC of layman (because there will be another one before the end of this GSoC...hint, hint).

Goals for next week:

  • Add finishing touches to portage sync module.
  • Continue to work on overlay-maker class.
  • Hopefully begin adding squashfs overlay support.
As always, to anyone interested the source code and my commits can be found on git.overlays.gentoo.org/gitweb/[1] or on github.com[2] on layman's gsoc2014 branch.

  [1]http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=shortlog;h=refs/heads/gsoc2014
  [2]https://github.com/twitch153/layman/tree/gsoc2014

Hope everyone is enjoying their summers!

With regards,
    Devan Franchini (twitch153)

Friday, June 20, 2014

GSoC 2014, Week #5: Midterm evals approaching

Hello,

     For everyone who hasn't done a Google Summer of Code or known anyone who has I'll explain a little bit about it shortly.

     For the past ten years, Google has offered a program worldwide that allows students the opportunity to get a stipend to write code for open source organizations. This is Google Summer of Code. In order to get in to the Summer of Code you need to supply a proposal which can consist of your project proposal and a time line that you expect to go by in order to break things into manageable pieces. If you get accepted you then begin your summer project!

    It doesn't mean everything is in the clear just because you were accepted though. Throughout the Summer of Code you have to go through two evaluations:
  • The Midterm Evaluation (June 23rd)
  • The Final Evaluation      (August 22nd)
Essentially, these are both evaluations from your project mentor that confirm you are keeping up with your proposed time line. If you do not pass either of these, you don't get to fully finish the Summer of Code. You will be removed and you will cry yourself to sleep thinking about what could've been! (Tragic, right?)

    Never fear though, not only am I keeping up with my proposed time line, but I'm actually ahead of schedule (I also hope to stay ahead of schedule).

This following week the following work has been done for layman:

1.) Minimal changes to documentation and code:

    This week's minimal changes include changes to the manual page formatting to make it a little cleaner when being displayed. As well as changes to the way both config.py and overlay.py handle dictionary logic.

    For those of you who have never coded in python allow me to briefly explain what a dictionary is:

    A python dictionary is a data structure that associates a value with a key, not uncommon to that of an actual dictionary. To grab a value from a dictionary in python you can do a few things, but the most common way of grabbing a specific value from a dictionary is by simply grabbing its value as so:

    dictionary['<key>']

    With that slight crash course on python dictionaries allow me to explain the problem with layman's previous dictionary logic: In some cases layman's code would check dictionaries for values by doing something like this -

        if dictionary['key']:
            ....

    This logic has been tested by me in both py2.7 and py3.x and neither times would anything like this actually end up with anything other than KeyError: 'value' if the value wasn't in the dictionary. Part of me believes that this logic might have worked in previous versions of python but I haven't tested it to confirm. My implemented solution was to change the logic to something like this:

        if 'value' in dictionary:
            ....

This will prevent the code from causing runtime errors and will neatly check to see if the value exists in the keys of the dictionary.

2.) Beginning addition of layman portage sync plugin module:

    Going on the idea that if you're using layman then the chances of you using Gentoo are extremely high. Furthermore, the chances of you using portage is just as high, if not higher.

    In my previous posts I explained how to add a layman overlay, but did I ever mention how to sync the overlay? If I did, then...oh well. Under the assumption that I never explained how to sync layman overlays I will explain now. You can either sync all the installed overlays with the command: layman -S or you can sync an individual overlay with the command: layman -s <overlay>. Simple, no?

    This doesn't take into account that you also sync your main portage overlay via emerge though. So when you want to sync secondary overlays you'll have to do sync them via layman and then your main via emerge. If you're anything like me you sync portage very often and regularly forget to sync your layman overlays. So throughout this week I've been in the process of doing two things, the first of which is working on adding a portage sync plugin module for layman.

How this is done:

    Although the current version of portage does not support sync modules, it is in the works to have a version of portage that does support sync modules. So that's why I'm making one for layman. So until that version of portage becomes available on the portage tree I'll lazily say you don't need to know how I added the module. However, I will explain slightly how I created the module itself.

    You need two things:
  • The __init__.py
  • The module.
    In the __init__.py you need to specify the config_class and the module specifications. To see both, you can look at my source code to get a better look, this part isn't complicated. Even for someone who has never coded before.

    In the module you need to create your config class and have it subclass the SyncBase class. From there you need to specify your __init__() function, your new() function, and your _sync() function. That is the bare minimum requirements for a portage sync plugin.

The layman sync plugin uses two different methods to be ran:
  1. Subprocess method
  2. API method
Firstly, we'll discuss the more common and simplistic of the two, the subprocess method. Portage already has a built in function to execute processes and this is call the portage.process.spawn_bash() function. This function will also return an exit code upon completion of the process. It's really quite beautiful.

For a user to add a sync plugin it'd be as simple as adding the execution of the subprocess for portage to execute.

Secondly, we'll discuss the API method of the layman sync plugin module. This method is slightly more complex than the previous one but is considerably less complex than some other things.

To make use of layman's API and not require a subproccess to be executed, we added this second config_class. This class creates an instance of layman's API and executes it's built-in sync function directly. Multiple checks have been added to ensure the API will be instantiated when necessary in order to become less resource intensive. Why is that?

Well, consider you have 5 overlays installed on your system. Okay, 5 isn't that many. But if you have portage syncing your layman overlays and say you have 50 overlays instead of 5, it would have to create an instance of the layman API 50 times when it might not be necessary.

3.) Overlay definition generator script in the works:

    If you were to look into layman's manual you would see that you can actually create your own overlay definitions in one or many .xml files and layman will pick them up if they are in the correct directory (default is: /etc/layman/overlays, but can be changed via command line or config setting. Multiple examples are also included in the overlay to guide users into making their own overlay.xml definitions.

    For the ease of use for users and developers both, a tool is being created that allows you create an overlay definition via a script that can be ran in the safety and comfort of your terminals.

4.) A note to all Gentoo users:

    This week we also released a test version of layman into the wild for users to hunt bugs with. So for any brave soul that is willing to test this and report back feedback of any kind, it'd be greatly appreciated.

    To install it on your system, simply install the -9999 version of layman in the portage tree and enjoy! Don't be afraid, it shouldn't bite you.

Goals for next week:
  • Revamp the overlay definition generator script.
  • Polish up the portage sync module.
  • Begin adding squashfs overlay support.
As always, to anyone interested the source code and my commits can be found on git.overlays.gentoo.org/gitweb/[1][1] or on github.com[2] on layman's gsoc2014 branch.


  [1]http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=shortlog;h=refs/heads/gsoc2014
  [1][1] Because my main computer has been down I haven't been able to push
            my latest commits to this repo.
  [2]https://github.com/twitch153/layman/tree/gsoc2014

Saturday, June 14, 2014

GSoC 2014, Week #4: The wheels keep spinning

Hello new and old readers all the same,

    Typically I make my posts every Friday but due other pressing matters unrelated to my coding adventures, I was unable to present my weekly achievements for the week.

    Because I know you guys are all very curious about my computer (because you all love it as much as I do, let's be honest), I tested my old motherboard with my new parts and it was a no-go. So I returned my new motherboard I purchased to Newegg and I should expect a new one within the next week or two. We all know how long these things can take...anyway, I'll be sure to keep all of you updated on how that goes.

    Now on to the good stuff, the main course of the post: What's been done to layman?

1.) Implementation of the "with" statement to open files:

    Sometimes it's great to explain things to people, when the changes you make to your code are very specific to your codebase, in this particular case, it isn't necessarily like that and the implementation is quite common. So common in fact, that I shamelessly found a great link that explains exactly what the "with" statement is used for: http://effbot.org/zone/python-with-statement.htm. The author of this page does an exceptional job to explain why this was implemented in later versions of python.

    The short of it: this was implemented in many places in the codebase of layman to make the opening and closing of a file that layman makes use of "safer", in case something doesn't work correctly for whatever reason, which will prevent leaving unused resources on your system open. So that's something everyone can enjoy!

2.) Replaced "subpath" with "branch":

    If anyone has made use of the subpath variable you're in luck! We removed it from layman's latest code! Why are you in luck? Well, because we replaced it with the branch variable. It was discussed between myself and my mentor (Gentoo developer, dol-sen) that using "subpath" would be mildly misleading for the general behaviour of how this variable is going to work. As most VCS's (version control systems) are git based in one way or another we decided using branch just made more sense. While I am currently in a waiting process for my previously mentioned .dtd patch to be submitted, hopefully everything will work out alright before we push out layman's upcoming release candidate

    Along with this change came the addition of alterations to layman's manual page that comes equipped with some good examples of how to make use of this fancy new variable.


3.) Added module branch support:

    Okay, so we have this fancy new variable we called branch. Big deal. How is this variable going to help me? Well, since you're all dying to know (and haven't figured it out already...) that variable can be used in an overlay.xml file. Once layman catches that this variable has a value, the following VCS types can make use of this variable for branch support:

  • Git: When a branch name is given to an overlay that is git based, layman will append the following to the cloning process of the git repo - "-b <branch name>". This allows the user to make custom overlay files that specify repositories and supply them with a particular branch, which is useful if you want the same repository under multiple aliases to be handled by layman.
  • Mercurial: Similarly with git, when a mercurial overlay has a branch defined, layman will append the following to the args for mercurial when cloning - "-r <branch name>" which is actually having the user specify a specific revision for mercurial when cloning that repository.
  • CVS & Tar: For both CVS and Tar overlay types which previously made use of the "subpath" variable, the behaviour of defining a branch in either of their repo definitions will remain the same and the branch will be treated as a subpath for the repo. This note has also been added to layman's manual page.
Note to all readers: if you think I'm doing something incorrect or think there is some branch love I can give to other repository types, I encourage patches. Of course they'll be tested and everything beforehand, but I will accept any patch and test it to be applied to layman for the greater good of the community.

4.) Refined test code:

    When installing layman you can run tests to ensure the test cases work in accordance with how layman claims it does on your system. layman currently supports both doctest testing, and non-doctest testing via a file called external.py (I can only assume this represents "external testing"). This week I worked on refining the external test code in two ways:
  1. I added compatibility for python3.x by changing the "print " declarations to "print()"
  2. One of the test cases is a Unicode test to ensure layman's output is unicode. However, python3.x will not explicitly decode strings when printing them out if they are encoded. So changes were made to ensure that the output from layman when running this test case would remain the same in both python2.7 and python3.x by implicitly decoding the string output.

5.) Adds file:// url support for tar overlays.

    However, when running the test cases I ran into a testing failure that struck me as odd. Until I realized it was partially my fault.

    This test ensures that tar overlays behave correctly by running the add() sync() and delete() functions for a temp created tar overlay. By making use of the tempfile library that python provides you can make....temporary files! (Who would've guessed?) This is particularly useful when doing test cases and just whenever you need to make use of temporary files such as possibly cache and the sort.

    Firstly, this test case initially failed due to the fact that I accidentally removed the tempfile import from the tar.py file (my bad!).

    To my surprise though, the test continued to fail, and it was no longer something that I caused! So why was it failing? Well, thanks to layman's output I was able to trace it down to tar.py's _extract() function. Tar overlays never put into consideration if the user was actually specifying a file:// url instead of an actual url that layman could download a tar from. But this test made use of a file:// temporary.tar.bz2. So I needed to add support for that in tar.py. It was simple enough. If the user specifies file://<tar_name> the just remove the "file://" section from the name and use tar to extract it.

    The test continued to fail though...but why? Where is it failing? By inserting some debug print statements (mostly saying "Are we here yet?!") I was able to see that layman was actually deleting the file after extracting it. Which makes sense if you consider it wasn't supporting local tar overlays, why keep a tar you can just download again on sync? But if we're keeping this tar overlay locally on the machine then that's just no good.

    To fix this issue a boolean was created called "clean_tar". In _extract() it will first check this boolean to see if it is True. If it is, then layman will get the okay to delete the file and purge it from this cruel, cruel, virtual world. For local files, this variable is hard-coded to False, and layman will never have permission to clean up local tar files unless the user themselves modify the code (modifying open source code?! What's wrong with you!?). Fear not though! Users do have some choice in their lives when it comes to this variable. Users can modify the configuration option: clean_tar to either yes or no. If yes, layman will delete downloaded tar overlay files after extracting them, and obviously the opposite effect will happen if users set the option to no; giving them the choice to keep downloaded tar overlays on their system to collect precious hard drive space.

Goals for next week:

    • Push out a new release candidate for layman (along with possibly changelog?)
    • Begin migrating from a docstring tests to a full test suite.
    To anyone interested the source code and my commits can be found on
    git.overlays.gentoo.org/gitweb/[1][1] or on github.com[2] on layman's gsoc2014 branch.


      [1]http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=shortlog;h=refs/heads/gsoc2014
      [1][1] Because my main computer has been down I haven't been able to push
                the commits to this repo. My mentor dol-sen should be pushing these to
                this repo some time this upcoming week.
      [2]https://github.com/twitch153/layman/tree/gsoc2014

     See you next week!

    With regards,
        Devan Franchini (twitch153) 

    Friday, June 6, 2014

    GSoC 2014, Week #3: Going good

    Hello again everyone,

    This week went fairly smooth. I got my computer parts in and to my despair there is an issue with the motherboard. So! Hopefully this Sunday I'll be able to see if I can't solve this problem and have my main computer alive and functional once and for all!

    Not much can be listed as being accomplished but a decent amount of work was done this week regarding layman:

    1.) Refined current code:

           I'm sure you're all thinking: "But Devan, didn't you do that last week? How much code could you possibly refine before it's perfect?". Well, forget that. Because code can always be refine in some way. Especially with something as expansive as layman. Throughout this week if I had to think about it I would probably say that I used git far more than I did anything else throughout this week.

          To avoid dragging out ideas and beating them into your brain to the point where your eyes glaze over I'll spare you most of the details on my git adventures and cover the main things that I've been getting familiar with throughout this GSoC involving git.

    • Using git rebase: Although I know git rebase is used for far more than I use it for, I have been using git rebase to handle my commits. If I broke something in a previous commit I would find the necessary SHA of the commit before the commit I wanted to repair and then I would run: git rebase -i <SHA>, once run it will bring up a text editor that will list all the commits up to that SHA. If I wanted to reword a commit I would just replace pick with reword, if I wanted to repair my mistakes from any commit I would replace pick with edit. This would also allow me to reword a commit if I so desired by using the command git commit --amend. After finishing all my repairs I would run git rebase --continue which will take me to my next edit, reword,... until it hit pick which will just continue on until you successfully rebase. After doing that you have to push all your commits to the branch by running git push --force and you'll have fixed your commits and pushed them to your remote repository!
    •  Breaking up a commit into two commits: So say I made a commit that I thought at the time was good but then I realized it'd be better as two separate commits. Well, I would rebase and edit the commit I wanted to break up into two (or more). Once you get to that commit you should run git reset HEAD~ which will reset your current HEAD to the one prior to that commit. So now your changes are "unrecorded". You can then continue to make your changes and break them up into multiple commits as you would normally. Once you're all done simple run git rebase --continue, and feel good about yourself for doing a job well done!
    By making use of these two topics I've been fixing up and refining the code without having to make different commits admitting I messed up (I mean, come on! Who wants to admit that they forgot an indentation here or there on multiple occasions?).

    2.) Updated the repository.dtd file:

           Although my understanding and experience with XML is slim to none, I can at least explain what was done here and why. If you look here you will see the overlay where the layman overlay repositories get their XML definitions. The structure of the repositories.xml is defined in its .dtd file. The changes I made to the repository.dtd include changes to add information for IRC channels, and overlay branches.

    3.) Documentation updates:

           If you're using layman then it's extremely likely that you're also using Linux. More specifically, Gentoo. So you should know that if you run man layman you'll get the manual for layman which includes pretty much all you need to know about how layman works, and the configuration options you can modify to do certain things.

          In preparation for the new release of layman, the documentation has been modified to reflect the changes I've been adding to layman throughout these past weeks and some cleaning up for the man page as well.

    Goals for next week:
    • Finish adding branch support for overlay installations (testing included).
    • Get the patch I created for the .dtd modifications to be applied to the repository.
    • Prepare for a new layman release.
    To anyone interested the source code and my commits can be found on
    git.overlays.gentoo.org/gitweb/[1][1] or on github.com[2] on layman's gsoc2014 branch.


      [1]http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=shortlog;h=refs/heads/gsoc2014
      [1][1] Because my main computer has been down I haven't been able to push
                the commits to this repo.
      [2]https://github.com/twitch153/layman/tree/gsoc2014

     See you next week!

    With regards,
        Devan Franchini (twitch153)

    Friday, May 30, 2014

    GSoC 2014, Week #2: Slight woes

    Hello readers,

    This week started with a bumpy start.

    Essentially, any horrible thing that could happen with my main desktop, ended up happening. All short from a micro-nuke dropping on the computer.

    So that ate up about one and a half days of possible work that I could've put toward layman while I worked on trying to diagnose whether it was a dead CPU or a motherboard issue. I ended up getting a CPU/Motherboard combo to save time diagnosing and ensuring that I'll have a working main desktop by next week. Fingers crossed that nothing else happens and I throw something...

    On a brighter note, a lot of work was done this week and I am not really far behind on my timeline at all (thanks to a few days of working longer than usual).

    Although the list of what was accomplished isn't as long as last week (for a multitude of reasons) I accomplished what I set out to accomplish.

    The following is what I accomplished this week:

    1.) Added a re-add overlay command line option:

          In my last post I showed you how to add an overlay using layman, this new command line option will do something similar (hopefully self-explanatory as well).

    2.) Added overlay type checking:

           In the event that your repository changes overlay types (ie. from git to cvs) layman will have to handle that. Previously no existing code in layman was set to handle this event. Now, when syncing overlays via the command line option: layman -S or layman -s <overlay>, layman will check the overlay type of the overlay on your local machine and the remote overlay that goes by the same name.

          Under that circumstance, layman will give a warning to the user, notifying them of the change and will then proceed to re-add the overlay with the code provided by the re-add function.

    3.) Added overlay URL updating capabilities for all supported repository types:

          Adding the support for this was a fun activity that gave me a little insight on how layman handles different overlay actions as well as the methods that one could take when updating the repository:

          To start, I'll begin by explaining the inheritance of the classes and how this allows them to interact in a neat fashion.

    Below, I will depict the inheritance tree for you:

                                         Overlay
                                               |
                                          Source
                                               |
                                       Overlay type

    So for example, we want to add my overlay to a local machine with layman (<sarcasm>because I don't do much to the ebuilds it'll ensure longterm stability! </sarcasm>) we will invoke layman as so:

            layman -a twitch153

    Hopefully you remember this. Now I'm going to explain in further detail as to how it all works (not entirely, I'm kind of lying to you).

    The overlay object will call it's add function, which goes through each available source and attempts to add them by calling source.add():

         def add(self, base):
                res = 1
                first_s = True
                for s in self.sources:
                    if not first_s:
                        self.output.info("\nTrying next source of listed sources...", 4)
                    try:
                        res = s.add(base)
                        if res == 0:
                            # Worked, throw other sources away
                            self.sources = [s]
                            break
                    except Exception as error:
                        self.output.warn(str(error), 4)
                    first_s = False
                return res


    This then traverses into the source class where you look to see what happens:

        def add(self, base):
            '''Add the overlay.'''

            mdir = path([base, self.parent.name])

            if os.path.exists(mdir):
                self.output.error('Directory ' + mdir +
                    ' already exists. Will not overwrite its contents!')
                return False

            os.makedirs(mdir)
            return True


    layman will check to see if the path already exists and to prompt the user if it does. So where does the actual action of syncing the overlay come in?

    The trick behind it is by looking back at the Overlay class:

        res = s.add(base)

    This doesn't really go straight to the source class. In fact, if we were to look at this in a level type scheme, the Overlay class would be level 1, and the Overlay_type class would be your level 2. So what about source? Well, source would be considered your level 1.5.

    The overlay_type class inherits all the functions given to it by the Source class:

        class GitOverlay(OverlaySource)

    Doing this allows any overlay type to make use of the code in the Source class while also executing its own add() function.

    After all of this, what does that have to do with URL updating? Now that you understand the inheritance behind each overlay_type it allows us to make sense of how each overlay type can cleanly have its own updating methods.

    The overlay class has a list of available overlay types that allow for a custom method of URL updating, these available types (Bzr, Cvs, Git, Mercurial, and Subversion) all run their own separate functions to update their URLs.

    Bzr: To update the repository URL in a Bzr overlay you need to run the bind command:

        bzr bind <source_url>

    Cvs: To update the repository URL in a Cvs overlay you need to echo the new repostiory URL into the CVS/Root file of the overlay, and then (if the repository location has changed) you need to replace the old repository location with the new one.

    Git:  By running git remote set-url <remote name> <new_url> <old_url> you can update the URL from which git will pull from.

    Mercurial: You can update the URL for a mercurial overlay by replacing the old url with the new url in the .hg/hgrc of the overlay. In layman, we make use of sed to do this:

         sed -i 's/oldurl/newurl/' <overlay_location>/.hg/hgrc

    Subversion: To update the src-url of an svn overlay you simply need to run svn switch --relocate, followed by the old_url and then the new_url.

    For all other overlay types, layman syncs the overlay by grabbing the source url from the installed.xml file in /var/lib/layman/, so when the overlay class recognizes an that an overlay type isn't in the list of supported types, it will simply set the source of the object to one of the new sources reported by the remote database and re-sync the overlay with the newly reported source url.

    4.) Polished code already in layman:

    A little self explanatory as well, but I cleaned up some of my mess along the way this week as well so you guys can all enjoy clean and bug free (hopefully...) code!

    Goals for next week:

    • Continue to refine the code already in layman - This goal will be ongoing throughout the entire GSoC and will never stop throughout my entire life. I will always have to go back and clean up my messes.
    • Add updates to the DTD to add IRC channel information for overlays in the repository.xml.
    • Hopefully add custom config type plugin support (it's being put off...I know).

    To anyone interested the source code and my commits can be found on
    git.overlays.gentoo.org/gitweb/[1] or on github.com[2] on layman's gsoc2014 branch.


      [1]http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=shortlog;h=refs/heads/gsoc2014
      [2]https://github.com/twitch153/layman/tree/gsoc2014

    See you guys next week!

    With regards,
        Devan Franchini (twitch153) 

    Friday, May 23, 2014

    GSoC 2014, Week #1: Off to a good start

    Hello everybody,

    This year I am working with the Gentoo organization again on a quest to improve the overlay manager, layman.

    Before I go into this week's success let me give you a little understanding about what layman is.

    Essentially, layman is a tool that manages overlays that can contain experimental or third-party packages for Gentoo, while integrating these overlays into the main system. It can also serve as a manager for version control repositories.

    To further embed the idea, imagine you are running a Gentoo system and want to add one of these third party overlays so you can install one of their packages because it's not on Gentoo's main distribution.

    You would first install layman on your system and then run:

    layman -L:

             * triquetra                 [Git       ] (git://git.o.g.o/user/triquetra.git, http://git.o.g.o/gitroot/user/triquetra.git, git+ssh://git@git.o.g.o/user/triquetra.git                               )
             * tryton                    [Mercurial ] (http://www.tryton.org/hg/tryton-overlay/                                                                                                                  )
             * turbogears2               [Git       ] (git://git.o.g.o/proj/turbogears2.git, http://git.o.g.o/gitroot/proj/turbogears2.git, git+ssh://git@git.o.g.o/proj/turbogears2.git                         )
             * twitch153                 [Git       ] (git://github.com/twitch153/ebuilds.git                                                                                                                    )
             * ub0rlay                   [Git       ] (git://repo.or.cz/ub0rlay.git                                                                                                                              )


    This would give you a list of all the available overlays that you can install. I just snagged a piece out to show you.

    They are listed by name, repo type, and repo url.

    From here you'll notice that I have an overlay on there! So I want to add that overlay to inflate my already large ego by calling layman again:

            layman -a twitch153

    After this is accomplished you install the packages that are on my repository.


    However, this is not a crash course on layman, but instead it is a post on the progress that I've made so far throughout this week along with some of the knowledge I acquired by working on this project.


    1.) python2.7/python3.x compatibility:

       
          The current version of layman on the portage tree only has support for python2.7. To add longevity into the life of layman it needed to have python3.x compatibility. So over the span of a few days I added support by doing the following:

    •   Running a python tool called 2to3, this will point all things (plus maybe even more than you'd need) to get a python program up and running for python3.x. By running this I was able to get some of the little stuff out of the way, but more needed to be done.

    • Migration of optparse to argparse:
           In order to parse out the command line arguments you give python a class was created called optparse. However, in python3.6, it is going to be deprecated, so for the sake of longevity migration to another class which is almost identical to optparse was necessary. argparse is pretty similar aside from a few minute details that I noticed (there are probably more, but in layman's case, I noticed these):
        - Option groups: Managing and handling option groups with argparser was much easier than with optparser, simply assign a variable to the add_argument_group(groupname):

              actions = self.parser.add_argument_group('<Actions>')

     and add an argument to the group:

            actions.add_argument('-a', '--add', ...)

    for length reasons I'm not going to go over everything, but I will say that argparser is a nice alteration to optparse and it was much easier to migrate than I thought it'd be. So two thumbs up there!
    • SSL-Fetch code migration:
         The ssl-fetch is a python library created in order to conveniently download things with verified ssl connections.

        The migration was simple enough, since the code was originally from layman, but made to be a little more broad so other packages could use it as well. This was added to allow ssl downloads of overlays for layman's remote database as well as tar archived overlays.

       The source code for ssl-fetch can be found here:
           https://github.com/dol-sen/ssl-fetch

     2.) Repos.conf support has been added:


    In any Gentoo system, if you look at a file located in /etc/portage/repos.conf/gentoo.conf

    You will find a configuration file that looks very similar to this format:

    [DEFAULT]
    main-repo = gentoo

    [gentoo]
    location = /usr/portage
    sync-type = rsync
    sync-uri = rsync://rsync.gentoo.org/gentoo-portage


    However, this config type is not currently supported by layman and instead there is a file in /var/lib/layman/ called make.conf, its contents are the directories of every overlay installed by layman and looks like this:

    PORTDIR_OVERLAY="
    /var/lib/layman/twitch153
    $PORTDIR_OVERLAY
    "

    This tells portage which sources the make.conf in /var/lib/layman that there is an overlay at this directory that also holds packages for portage.

    repos.conf support has been added to allow layman to write to a config file that follows the same format of gentoo.conf. For example, if I had repos.conf support and installed the twitch153 overlay it would be added to a file called /etc/portage/repos.conf/layman.conf and look like so:

    [twitch153]
    sync-type = None
    auto-sync = No
    sync-uri = git://github.com/twitch153/ebuilds.git
    location = /var/lib/layman/twitch153



    This support was added by making use of the configparser library. When an overlay object is passed down to the reposconf.py file it will break the overlay object into the pieces it needs (overlay name, sync-type, auto-sync, sync-uri, and the location in which it is installed) and then it will add those values to the config file layman.conf via a ConfigParser object.

    ex.)

    repo_config = ConfigParser.ConfigParser()

    repo_config.add_section(overlay.name)
    repo_config.set(overlay.name, 'location', <installed location>)
    ...

    return write()

    This simple to use interface allows the code to become easy to read and maintainable for anyone who is unfamiliar with layman's codebase.

    However, now layman has more than one configuration option: make.conf, and repos.conf. How does layman know which config option to execute?
    This leads us into the next topic...

    3.) RepoConfManager:

    In order to handle multiple config type plugins such as make.conf and repos.conf a class was created that would interface with the databasing portion of layman, repoconfmanager.py.

    This portion of the work I did throughout this week was something I typically don't do. Through a good portion of my coding career I have done my own python coding in a procedural style so I typically don't work a lot in python classes. That is going to change for sure, but that doesn't mean that what I've learned isn't new to me.

    So how does RepoConfManager handle multiple config types? Well, you need initialized functions of the available configuration objects:

            import layman.reposconf as reposconf
            import layman.makeconf as makeconf

    This code imports the classes to allow me to create objects of that type.

    Then (this is what I was really impressed by), a python dictionary is created with these values:

        modules = {'make.conf': (makeconf, 'ConfigHandler'), 'repos.conf': (reposconf, 'ConfigHandler')}

    and it is then run through a for loop of the given config types.

            for types in conf_types:
                config = getattr(modules[types][0], modules[types][1])(config, overlays)

    this beautiful loop creates a config object of any associated modules of that type by associating the object string, and the class name with the module types in a tuple. From there you can continue with any function that the object holds.

    There are a few things about this method of instantiating an object that are great:

    1. It allows the code to be easily maintainable.
    2. It allows for custom config type plugins. 
    Although no support for custom config type plugins is added yet, I'm sure before the end of this summer there will be another post announcing the addition of that feature ;)

    So what am I currently working on? What new improvements should you expect to see next week?

    One thing that I spent that last day or two working on is this:

    4.) URL Updating:

    What is it?

    Well, remember how layman has to grab the repositories from an overlay list? When the overlay is installed on the system the source url is recorded to a file called installed.xml, along with a few other locations in which this link is recorded.

    Why does this matter?

    The source url is necessary in order to sync the contents of the overlay and keep them up to date. In certain cases though something can happen that creates a situation where your recorded local source url is not the same as the remote source url.

    When this happens it needs to be corrected. Currently layman's code supports notifying a user if their local source differs, so why shouldn't it be corrected for them instead? That's exactly what I have been working on and plan to continue working on into next week.

    I have added support for URL updating of git repositories, but as of right now that's all I've accomplished. That leaves me with about 9 more repository types to add URL updating for...

    To end this post I'll give you a list what to expect for next week:

    •  Continuing to refine code already in layman.
    • Adding url update support for more overlay types.
    • Hopefully custom config type plugin support for RepoConfManager.
    To anyone interested the source code and my commits can be found on
    git.overlays.gentoo.org/gitweb/[1] or on github.com[2] on layman's gsoc2014 branch.


      [1]http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=shortlog;h=refs/heads/gsoc2014
      [2]https://github.com/twitch153/layman/tree/gsoc2014


    I'll see you guys next week!

    With regards,
        Devan Franchini (twitch153)