SilverWav's Journal

The best is yet to come…

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.'

Advertisements

Written by SilverWav

May 8, 2010 at 10:25 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: