SilverWav's Journal

The best is yet to come…

Posts Tagged ‘getPublishedSources

Copy Packages from ‘ubuntu-mozilla-daily’ to your PPA with Python

leave a comment »

Now that the Lucid rush is over and all the builders have been reassigned to the PPA duties I can get on with finishing this little project :-)

Quick and Dirty code for Displaying packages in a PPA, Then Copy from PPA ‘A’ to PPA ‘B’.

Bear in mind that the posted code is just a place holder and will be getting updated.

lp-getPubSo-and-Copy_odam-test.py

#! /usr/bin/env python

#123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
#         1         2         3         4         5         6         7         8
#silverwave OpenPGP key 03187548
#
print
print 'Connect to Service and Register Application.'
from launchpadlib.launchpad import Launchpad
lp_ = Launchpad.login_with('sapp2', 'edge')
print
print 'Check Configuration.'
this_distro = lp_.distributions["ubuntu"]
print 'Distribution: ' + this_distro.display_name
umd_achive = lp_.people['ubuntu-mozilla-daily'].archive
print 'Copy From Archive: '
print umd_achive.displayname
print

# function #0 - confirm
## {{{ http://code.activestate.com/recipes/541096/ (r1)
def confirm(prompt=None, resp=False):
    """prompts for yes or no response from the user.
    Returns True for yes and False for no.
    'resp' should be set to the default value

    >>> confirm(prompt='Create Directory?', resp=True)
    Create Directory? [y]|n:
    True
    >>> confirm(prompt='Create Directory?', resp=False)
    Create Directory? [n]|y:
    False
    >>> confirm(prompt='Create Directory?', resp=False)
    Create Directory? [n]|y: y
    True

    """

    if prompt is None:
        prompt = 'Confirm'

    if resp:
        prompt = '%s [%s]|%s: ' % (prompt, 'y', 'n')
    else:
        prompt = '%s [%s]|%s: ' % (prompt, 'n', 'y')

    while True:
        ans = raw_input(prompt)
        if not ans:
            return resp
        if ans not in ['y', 'Y', 'n', 'N']:
            print 'please enter y or n.'
            continue
        if ans == 'y' or ans == 'Y':
            return True
        if ans == 'n' or ans == 'N':
            return False
## end of http://code.activestate.com/recipes/541096/ }}}

# function #1 - getps
def getps(this_seriesname, this_source):
    get_this_series = this_distro.getSeries(name_or_version = this_seriesname)

    last_pubapp = umd_achive.getPublishedSources(
		exact_match=True,
		source_name=this_source,
		distro_series=get_this_series
		)[0]
    result = last_pubapp.source_package_version

    print result
    return result

# function #2 - copypackage
def copypackage(copy_to_this_ppa,copy_this_souce,copy_this_version):
    target = lp_.me.getPPAByName(name=copy_to_this_ppa)

    target.syncSource(
    source_name=copy_this_souce,
    version=copy_this_version,
    from_archive=umd_achive,
    include_binaries=True,
    to_series=None,
    to_pocket='Release',
    )

    print 'Copied to: ' + target.displayname
    print 'Package: ' + copy_this_souce + ' - ' + copy_this_version
    print

print 'Retrieve the list of Published Packages.'
print

# Main
print 'Copy To TEST Archive:'
print 'Firefox-3.6 Lucid: ' + 'ppa:silverwave/one-daily-a-month'
print 'Firefox-3.7 Lucid: ' + 'ppa:silverwave/one-daily-a-month'
print 'Firefox-3.6 Karmic: ' + 'ppa:silverwave/ppa'
print 'Firefox-3.7 Karmic: ' + 'ppa:silverwave/ppa'
print

'''http://releases.ubuntu.com/releases/lucid/

ubuntu-10.04-desktop-amd64.iso
ubuntu-10.04-desktop-i386.iso

    1. Copy to 'one-daily-a-month' which is the Testing PPA for Lucid.
    2. TestDrive in Lucid amd64 (add ppa and install updates).
    3. TestDrive in Lucid i386  (add ppa and install updates).'''

# List and Copy Lucid
if confirm(prompt='List UMD - FF3.6 *Lucid?', resp=True):
    applff36 = getps('lucid','firefox')
    applxu92 = getps('lucid','xulrunner-1.9.2')
    print
    if confirm(prompt='Copy to odam?', resp=False):
        copypackage('one-daily-a-month','firefox', applff36)
        copypackage('one-daily-a-month','xulrunner-1.9.2', applxu92)
    else : print

if confirm(prompt='List UMD - FF3.7 *Lucid?', resp=True):
    applff37 = getps('lucid','firefox-3.7')
    applxu93 = getps('lucid','xulrunner-1.9.3')
    print
    if confirm(prompt='Copy to odam?', resp=False):
        copypackage('one-daily-a-month','firefox-3.7', applff37)
        copypackage('one-daily-a-month','xulrunner-1.9.3', applxu93)
    else : print    

'''http://releases.ubuntu.com/releases/lucid/

ubuntu-10.04-desktop-amd64.iso
ubuntu-10.04-desktop-i386.iso

    1. Copy to 'ppa' which is the Testing PPA for Karmic.
    2. TestDrive in Karmic amd64 (add ppa and install updates).
    3. TestDrive in Karmic i386  (add ppa and install updates).'''
# List and Copy Karmic
if confirm(prompt='List UMD - FF3.6 Karmic?', resp=True):
    appkff36 = getps('karmic','firefox')
    appkxu92 = getps('karmic','xulrunner-1.9.2')
    print
    if confirm(prompt='Copy to ppa?', resp=False):
        copypackage('ppa','firefox', appkff36)
        copypackage('ppa','xulrunner-1.9.2', appkxu92)
    else : print

if confirm(prompt='List UMD - FF3.7 Karmic?', resp=True):
    appkff37 = getps('karmic','firefox-3.7')
    appkxu93 = getps('karmic','xulrunner-1.9.3')
    print
    if confirm(prompt='Copy to ppa?', resp=False):
        copypackage('ppa','firefox-3.7', appkff37)
        copypackage('ppa','xulrunner-1.9.3', appkxu93)
    else : print

print 'done.'

lp-getPubSo-and-Copy_odam-prod.py

#! /usr/bin/env python

#123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
#         1         2         3         4         5         6         7         8
#silverwave OpenPGP key 03187548
#
print
print 'Connect to Service and Register Application.'
from launchpadlib.launchpad import Launchpad
lp_ = Launchpad.login_with('sapp3', 'edge')
print
print 'Check Configuration.'
this_distro = lp_.distributions["ubuntu"]
print 'Distribution: ' + this_distro.display_name
umd_achive = lp_.people['ubuntu-mozilla-daily'].archive
print 'Copy From Archive: '
print umd_achive.displayname
print

# function #0 - confirm
## {{{ http://code.activestate.com/recipes/541096/ (r1)
def confirm(prompt=None, resp=False):
    """prompts for yes or no response from the user.
    Returns True for yes and False for no.
    'resp' should be set to the default value

    >>> confirm(prompt='Create Directory?', resp=True)
    Create Directory? [y]|n:
    True
    >>> confirm(prompt='Create Directory?', resp=False)
    Create Directory? [n]|y:
    False
    >>> confirm(prompt='Create Directory?', resp=False)
    Create Directory? [n]|y: y
    True

    """

    if prompt is None:
        prompt = 'Confirm'

    if resp:
        prompt = '%s [%s]|%s: ' % (prompt, 'y', 'n')
    else:
        prompt = '%s [%s]|%s: ' % (prompt, 'n', 'y')

    while True:
        ans = raw_input(prompt)
        if not ans:
            return resp
        if ans not in ['y', 'Y', 'n', 'N']:
            print 'please enter y or n.'
            continue
        if ans == 'y' or ans == 'Y':
            return True
        if ans == 'n' or ans == 'N':
            return False
## end of http://code.activestate.com/recipes/541096/ }}}

# function #1 - getps
def getps(this_seriesname, this_source):
    get_this_series = this_distro.getSeries(name_or_version = this_seriesname)

    last_pubapp = umd_achive.getPublishedSources(
		exact_match=True,
		source_name=this_source,
		distro_series=get_this_series
		)[0]
    result = last_pubapp.source_package_version

    print result
    return result

# function #2 - copypackage
def copypackage(copy_to_this_ppa,copy_this_souce,copy_this_version):
    target = lp_.me.getPPAByName(name=copy_to_this_ppa)

    target.syncSource(
    source_name=copy_this_souce,
    version=copy_this_version,
    from_archive=umd_achive,
    include_binaries=True,
    to_series=None,
    to_pocket='Release',
    )

    print 'Copied to: ' + target.displayname
    print 'Package: ' + copy_this_souce + ' - ' + copy_this_version
    print

print 'Retrieve the list of Published Packages.'
print

# Main
print 'Copy To PROD Archive:'
print 'Firefox-3.6 Lucid: ' + 'ppa:silverwave/one-daily-a-month-0'
print 'Firefox-3.7 Lucid: ' + 'ppa:silverwave/one-daily-a-month-1'
print 'Firefox-3.6 Karmic: ' + 'ppa:silverwave/one-daily-a-month-2'
print 'Firefox-3.7 Karmic: ' + 'ppa:silverwave/one-daily-a-month-3'
print

# Copy to 'one-daily-a-month-0' which is the FF3.6 PPA for Lucid.
# Copy to 'one-daily-a-month-1' which is the FF3.7 PPA for Lucid.

# List and Copy Lucid
if confirm(prompt='List UDM - FF3.6 *Lucid?', resp=True):
    applff36 = getps('lucid','firefox')
    applxu92 = getps('lucid','xulrunner-1.9.2')
    print
    if confirm(prompt='Copy to ODAM0?', resp=False):
        copypackage('one-daily-a-month-0','firefox', applff36)
        copypackage('one-daily-a-month-0','xulrunner-1.9.2', applxu92)
    else : print

if confirm(prompt='List UDM - FF3.7 *Lucid?', resp=True):
    applff37 = getps('lucid','firefox-3.7')
    applxu93 = getps('lucid','xulrunner-1.9.3')
    print
    if confirm(prompt='Copy to ODAM1?', resp=False):
        copypackage('one-daily-a-month-1','firefox-3.7', applff37)
        copypackage('one-daily-a-month-1','xulrunner-1.9.3', applxu93)
    else : print    

# Copy to 'one-daily-a-month-2' which is the FF3.6 PPA for Karmic.
# Copy to 'one-daily-a-month-3' which is the FF3.7 PPA for Karmic.

# List and Copy Karmic
if confirm(prompt='List ODAM2 - FF3.6 Karmic?', resp=True):
    appkff36 = getps('karmic','firefox')
    appkxu92 = getps('karmic','xulrunner-1.9.2')
    print
    if confirm(prompt='Copy to ODAM2?', resp=False):
        copypackage('one-daily-a-month-2','firefox', appkff36)
        copypackage('one-daily-a-month-2','xulrunner-1.9.2', appkxu92)
    else : print

if confirm(prompt='List ODAM3 - FF3.7 Karmic?', resp=True):
    appkff37 = getps('karmic','firefox-3.7')
    appkxu93 = getps('karmic','xulrunner-1.9.3')
    print
    if confirm(prompt='Copy to ODAM3?', resp=False):
        copypackage('one-daily-a-month-3','firefox-3.7', appkff37)
        copypackage('one-daily-a-month-3','xulrunner-1.9.3', appkxu93)
    else : print

print 'done.'

Written by SilverWav

May 8, 2010 at 10:25 am

Listing latest published packages in a PPA

leave a comment »

OK so now I have a way of listing the latest published packages in a PPA. :-)

The key is that I can specify the series e.g. lucid or karmic and get results for each.

Note: Learning python as I go… :-)
Yes a better function is called for but this will do for now.

Advantages over the web interface:
It is easy to see the 8 packages I am interested in (out of the 50 in the ppa).
I can also quickly confirm when all the packages have been built (I just check the date).

___

Code

#! /usr/bin/env python

from launchpadlib.launchpad import Launchpad
launchpad = Launchpad.login_with('bot100', 'edge')

distro = launchpad.distributions["ubuntu"]
ppa = launchpad.people['ubuntu-mozilla-daily'].archive

def getPS(seri, source):
    series = distro.getSeries(name_or_version = seri)

    last_app = ppa.getPublishedSources(
		exact_match=True,
		source_name=source,
		distro_series=series
		)[0]
    apptemp = last_app.source_package_version

    print apptemp
    return apptemp

appff10 = getPS('lucid','firefox')
appff20 = getPS('lucid','firefox-3.7')
appff30 = getPS('lucid','xulrunner-1.9.2')
appff40 = getPS('lucid','xulrunner-1.9.3')
print
appff1 = getPS('karmic','firefox')
appff2 = getPS('karmic','firefox-3.7')
appff3 = getPS('karmic','xulrunner-1.9.2')
appff4 = getPS('karmic','xulrunner-1.9.3')

___

Results:

$ ./lp-getPublishedSources_one-daily-a-month.py
3.6.5~hg20100428r34143+nobinonly-0ubuntu1~umd1
3.7~a5~hg20100429r41513+nobinonly-0ubuntu1~umd1
1.9.2.5~hg20100428r34143+nobinonly-0ubuntu1~umd1
1.9.3~a5~hg20100429r41513+nobinonly-0ubuntu1~umd1

3.6.5~hg20100428r34143+nobinonly-0ubuntu1~umd1~karmic
3.7~a5~hg20100429r41513+nobinonly-0ubuntu1~umd1~karmic
1.9.2.5~hg20100428r34143+nobinonly-0ubuntu1~umd1~karmic
1.9.3~a5~hg20100429r41513+nobinonly-0ubuntu1~umd1~karmic
$

___

Written by SilverWav

April 29, 2010 at 5:28 pm

Note: getPublishedSources

leave a comment »

Saved for reference.

Celso Providelo

Sources can be found, basically, by name, version, distroseries and status by calling getPublishedSources on a target archive.

When it run, the output is:

firefox-3.5 3.5~b4~hg20090415r24712+nobinonly-0ubuntu1~umd1 in jaunty

 >>> def test_source_lookup(lp):
     ppa = lp.people['ubuntu-mozilla-daily'].archive
     ubuntu = lp.distributions['ubuntu']
     jaunty = ubuntu.getSeries(name_or_version='jaunty')
     last_firefox = ppa.getPublishedSources(
         source_name='firefox-3.5', status='Published', distro_series=jaunty,
         exact_match=True)[0]
     print last_firefox.displayname

______________________________

Note: displayname gives an error message, use this instead:

print last_firefox.source_package_version

Written by SilverWav

April 27, 2010 at 2:58 pm

Follow

Get every new post delivered to your Inbox.