SilverWav's Journal

The best is yet to come…

Archive for the ‘Project’ Category

A simple alternative to Hacktheweb, aardvark, platypus or Tampermonkey.

leave a comment »

Because I hate ugly distracting cruft on websites. :-)

History:

I loved Platypus but moved on to Aardvark when it died, then created Hacktheweb to enable aardvark to save scripts to Stylish (recreating most of the platypus functionality with out the risks).

But while creating extensions can be a lot of fun, maintaining them… not so much.

Each time Stylish changes you need to update Hacktheweb to match. Tried that for a few years and… meh. So instead I just used Hacktheweb with the old 1.4.1.1 Stylish.

Also Hacktheweb was created on Firefox and I have moved to Chrome… but the Stylish scripts were usable on both, so I was still using Hacktheweb when I needed a quick and dirty script.

On Chrome the closest extension I could see was Stylebot, but with no easy saving to Stylish and a quirky interface, it was not something I could live with.

So looking around for something simple and safe, I looked at Tampermonkey which seems great but requires a lot of trust… and is probably overkill for my needs.

The Binding Flash of Inspiration:

But I had a revelation… Adblock Plus! Never really considered it after ruling it out a while ago (no widthify, no stylish, and I had hid the ABP button so out of sight out of mind).

But looking at it in this new light (looking for Simple, Quick and Good Enough, rather than Perfect).

I turned the ABP button back on then hid the distracting ‘Shown number of ads blocked’ badge.

In testing ABP, I found it to be a good fit for my requirements; the block element function does 90% of what I wanted. Just getting rid of sidebars was my main aim, the filters are not synced but easily cut and pasted.

As this looked to be a wining solution, it was worth thinking of a way around the ‘Site Not Centred ‘issue, resulting from blocking sidebars…

My solution:

  1. Create Stylish scripts to change margin-left to 10%, 20% etc…
  2. Upload the Scripts to https://userstyles.org/users/98352 so that I can install on all of my browsers.

So on each browser on the ABP Options page, I just paste the filter text into the ‘Your Own Filters’ tab.

Then I go to userstyles.org and install the scripts I need e.g. ‘0sw_MLeft10percentWhite’ and I am done.

The Benefits for me are:

No extra extensions, I am using ABP and Stylish already, so no extra trust needed. Also both extensions are backed by big name developers.

ABP block element is quick and easy to use, as is transferring filters.

The Result:

Fantastic clean, distraction free, easy reading of my favourite web sites… without having to build and maintain my own extension.

Looks like a plan :-)

Written by SilverWav

July 21, 2015 at 3:09 pm

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

Launchpad syncSources missing “from series”

leave a comment »

OK a new project involving PPA’s, Launchpad, launchpadlib, Soyuz.

Lets start documenting some of this stuff while its fresh.

Tag the project “onedailyamonth” so I can find it later.

This may be a rather brutal introduction to python for me…
Oh well learning something new is always fun :-)

It works… everything else is bonus points.

Onwards…

$ python
##Start up the Launchpad command line.
>>> from launchpadlib.launchpad import Launchpad

##Start up your application and login.
launchpad = Launchpad.login_with('bot100', 'edge')
##Authorise the app in Launchpad and away you go...

Run the script or paste each command in turn to test it.

#! /usr/bin/env python

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

{{{
    from_archive = launchpad.people['ubuntu-mozilla-daily'].archive
    to_archive = launchpad.me.getPPAByName(name='one-daily-a-month')
    sources_to_be_copied = ['firefox','xulrunner-1.9.2']
    print to_archive.syncSources(
        source_names=sources_to_be_copied,
        from_archive=from_archive,
        to_pocket='release',
        to_series=None,include_binaries=True,
        )
    sources_to_be_copied = ['firefox-3.7', 'xulrunner-1.9.3']
    to_archive = launchpad.me.getPPAByName(name='one-daily-a-month-1')
    print to_archive.syncSources(
        source_names=sources_to_be_copied,
        from_archive=from_archive,
        to_pocket='release',
        to_series=None,
        include_binaries=True,
        )
}}}

___

This is great except it will not do a series, e.g. karmic, separately :-(
“API for copying packages (syncSources) needs a “from series” parameter” Bug #493914

So I will need to use syncSource instead.

This further means, that I will need a way to find the specific version name, for each of the packages.

Looking at the examples gives me something I can use…

“Listing the current package versions in a particular distroseries” here API/Examples.

OK we have a plan :-)

Written by SilverWav

April 29, 2010 at 1:42 pm

ShelveLogger 4.3.1

leave a comment »

ShelveLogger.html 4.3.1 – (Download).

Just click the download link to see a working example.
(It also allows you to see the lightning fast Filtering in action).

______________________________

Below is the sourcecode for ShelveLogger.html

Note: After the big changes in 4.3, 4.3.1 is mainly code clean-up.

Read the rest of this entry »

Written by SilverWav

March 16, 2010 at 12:43 pm

Posted in Project

Tagged with , , ,

ShelveLogger 4.3

leave a comment »

ShelveLogger.html 4.3 – (Download).

Just click the download link to see a working example.
(It also allows you to see the lightning fast Filtering in action).

______________________________

Below is the sourcecode for ShelveLogger.html

Note: The priority for this version was to add the built-in help and to integrate the filtering code.

Read the rest of this entry »

Written by SilverWav

March 14, 2010 at 4:12 pm

Posted in Project

Tagged with , , ,