Archive for April 2010
Listing latest published packages in a PPA
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 $
___
Launchpad syncSources missing “from series”
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 :-)
Note: Using the launchpad API for copying
Saved for reference.
Celso Providelo said on 2009-03-20:
It will probably get too boring, at this point you might consider writing a script using the launchpad API for copying your stuff. Check the API guide at https://help.launchpad.net/API and try something along these lines:
{{{
from_archive = launchpad.me.archive
to_archive = launchpad.people['kde3-maintainers'].archive
sources_to_be_copied = ['x', 'y', 'z']
print to_archive.syncSources(
source_names=sources_to_be_copied,
from_archive=from_archive,
to_pocket='release',
to_series=None,
include_binaries=True,
)
}}}
Note: getPublishedSources
Saved for reference.
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
Note: syncSource
Saved for reference.
An authenticated user may copy sources (including their binaries or not) from any public archive to any PPA he has permission to upload using syncSource
One practical example is backporting recent SRUs to LTS series using your PPAs. Let say, we want the latest libvirt version available for testing in your Hardy instance.
libvirt – 0.6.1-0ubuntu5.1 will be rebuilt in your PPA for hardy and if everything is compatible in few minutes you will be able to use and share it with other users.
{{{
ubuntu = lp.distributions['ubuntu']
primary, partner = ubuntu.archives
ppa = lp.me.getPPAByName(name='ppa')
ppa.syncSource(
source_name='libvirt', version='0.6.1-0ubuntu5.1',
from_archive=primary, include_binaries=False,
to_series='hardy', to_pocket='Release')
}}}
Note: Add Shred to Nautilus with nautilus-actions
apt-get install nautilus-actions
>System > Preferences > Nautilus Actions Configuration
Add button > create a new action
Action:
* Label: Shred
* Tooltip: Shred a file
* Icon: gtk-media-record
Command:
* Path: /usr/bin/shred
* Parameters: -f -u -z %M
Right click on a file and select Shred when needed.
Note: md5sum for each file in directory
md5sum
This is a recursive command, that is, it will create a md5 for all files in sub directories as well.
1. Create md5sum’s for each file in the directory and output to the file check.md5.
find . -type f 2>/dev/null -exec md5sum {} \; >check.md5
Note: You may need to run from root e.g sudo -i, which is not best practice.
2. Confirm files in the directory against check.md5 and output to the file results.md5
md5sum -c check.md5 > results.md5
Note: Shred All Files in a Directory
Important – Could Delete Your System!
Make sure you use “Open in Terminal” or cd to the correct directory before running this command.
Or you will be sorry.
______________________________
Overwrite then Delete All Files in a Directory
find -type f -execdir shred -u -z '{}' \;
Explanation
The find command itself is used to find files matching a certain expression, on a certain path.
The the path argument is omitted, so find starts the search from the default current working directory.
The next argument to find, -type f, tells find to match only regular files (as we can’t shred directories).
The -execdir argument tells find to execute the command following the argument on each file matched (from that file’s parent directory).
We could alternatively have used the -exec argument, but -execdir is more secure because it changes directories before executing the command.
The remaining arguments are taken as the command to execute, until a terminating ‘;’ character is encountered.
We tell find to execute the shred command (with options) on each file matched.
The -u option to shred tells it to remove the file after shredding.
Find replaces the ‘{}’ string with the current file name being processed.
Note the braces are quoted to prevent expansion by the shell.
Finally, a semi-colon terminates the -execdir command.
The ; character is again escaped, this time with a ‘\’, to prevent expansion by the shell.
______________________________
Important – Could Kill Your Cat!
I don’t use this command, added for completeness.
If you do use it, ensure you have important data backed-up and a way of reinstalling your system.
I use Nautilus to delete directories as its safer :-)
______________________________
Delete a Tree of Directories.
Quote from opentux:
After executing the first command, all files in the directory tree have been securely shredded and removed, and all that is left is a tree of empty directories. Since the directories themselves contain no sensitive information (they are just a list of names and i-node numbers), they can be safely removed with rm.
I specified using the command
$>rm -rf *
to recursively (-r) remove all the directories without prompt (-f), since I knew all sensitive files to have been securely removed already. But alternatively if you wanted to make doubly sure you weren’t unsecurely removing any missed files, you could invoke rmdir on each remaining directory (from the bottom up).
Avidemux vob to avi, lightning fast
Avidemux is a fantastic piece of kit.
Transcoding takes a lot of time and CPU, whereas this application moves the content from one container (vob) to another (avi) instead.
Usage:
Open
select vob
e.g. VTS_01_1.VOB
Save
name the file
e.g. file.avi
Note: Remuxing mkv to avi for the Xbox 360
Thanks to Zeroshade, details here.
Packages Needed:
mkvmerge, mkvextract (package mkvtoolnix), bbe, mplayer, normalize-audio, neroAacEnc, and mp4creator
Install command:
sudo apt-get update && sudo apt-get install mkvtoolnix bbe mplayer normalize-audio mpeg4ip-server
Get neroAacEnc here.
Manual Install:
unzip NeroDigitalAudio.zip cd linux sudo mv neroAacEnc /usr/bin sudo chmod +x /usr/bin/neroAacEnc
vidconv.sh here.
Example Usage:
./vidconv.sh file1.mkv
#!/bin/bash
# zeroshade's script for remuxing mkv to mp4
# http://cantthinkofa.com
VERSION="1.0"
## remuxer to remux AVC mkv videos to mp4's that can be sent to xbox 360.
# requires: mkvmerge, mkvextract (package mkvtoolnix), bbe, mplayer, normalize-audio
# neroAacEnc (http://www.nero.com/eng/downloads-nerodigital-nero-aac-codec.php)
# mp4creator (package mpeg4ip-server)
MKV=$1
if [ -z "$MKV" ]; then
echo "Usage: `basename $0` <MKV>";
exit 5
fi
# using a tmp file allows for extensibility
# if desired, the script can be extended using the audio track
# and codec by uncommenting the lines below
mkvmerge -i "$MKV" > /tmp/info.$$.txt
VID=`grep "Track ID .: video" /tmp/info.$$.txt | awk '{ print sprintf("%d",$3) }'`
#AUDINF=`grep "Track ID .: audio"`/tmp/info.$$.txt`
#AUD=`echo $AUDINF | awk '{ print sprintf("%d",$3) }'`
#AEXT=`echo $AUDINF | awk '{ print $5 }' | sed 's/(A_\|)//g' | awk '{ print tolower($1) }'`
FPS=`mplayer -identify "$MKV" -vc null -ao null -vo null -frames 0 2>/dev/null | grep ^ID_VIDEO_FPS | sed -e 's/^.*=//'`
rm /tmp/info.$$.txt
echo "------Zeroshade's remux script. MKV to mp4 V.$VERSION"
echo
if [ -z "$VID" ]; then
echo "Error getting video track from mkvmerge."
exit 5
fi
if [ -z "$FPS" ]; then
echo "Error getting framerate from mplayer"
exit 5
fi
BASE=`echo $MKV | sed 's/\.mkv//'`
echo "------Extracting video track-----------"
mkvextract tracks "$MKV" "$VID:$BASE.h264"
echo "------Changing Profile-----------------"
bbe -e "r 7 \41" --output="$BASE.tmp.h264" "$BASE.h264"
rm "$BASE.h264"
echo "------Extracting audio track-----------"
mplayer "$MKV" -novideo -vc null -vo null -ao pcm:fast:file="$BASE.wav" -channels 2
echo "------Normalizing audio----------------"
normalize-audio "$BASE.wav"
echo "------Encoding audio to m4a------------"
neroAacEnc -lc -ignorelength -q 0.50 -if "$BASE.wav" -of "$BASE.m4a"
echo "------Removing origingal audio dump----"
rm "$BASE.wav"
echo "------Converting m4a to aac"
mp4creator --extract=1 "$BASE.m4a" "$BASE.aac"
echo "------Cleaning up m4a------------------"
rm "$BASE.m4a"
echo "------Creating mp4 video---------------"
mp4creator --create="$BASE.tmp.h264" -rate=$FPS "$BASE.mp4"
echo "------Adding audio to the video--------"
mp4creator --create="$BASE.aac" -rate=$FPS "$BASE.mp4"
echo "------Removing h264 and aac------------"
rm "$BASE.tmp.h264" "$BASE.aac"
echo "------Done! Enjoy your video! =)-------"
___
*Ignore this* Working example of WordPress sourcecode: [sourcecode light="true"] [sourcecode language="bash" collapse="true"]