Skip to content

Instantly share code, notes, and snippets.

@thiblahute
Created September 9, 2015 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thiblahute/38d91d6f269f8ccb7fb8 to your computer and use it in GitHub Desktop.
Save thiblahute/38d91d6f269f8ccb7fb8 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
""" update_pitivi_bundle
Usage:
update_pitivi_bundle [--choose]
Options:
-c --choose Choose the bundle version to download
-h --help Show this screen.
-h --help Show this screen.
--version Show version.
"""
from docopt import docopt
import os
import time
import datetime
import platform
import tempfile
import tarfile
from html.parser import HTMLParser
bitness = platform.architecture()[0]
arch = "x86" if bitness == "32bit" else "x86_64"
# create a subclass and override the handler methods
class MyHTMLParser(HTMLParser):
def __init__(self, basepath):
super(MyHTMLParser, self).__init__()
self.archives = []
self.basepath = basepath
def handle_data(self, data):
if "pitivi-latest" in data:
self.archives.append(os.path.join(self.basepath, data.strip()))
def download_bundle(arguments):
tmpfile = tempfile.NamedTemporaryFile(suffix="pitivi_bundle")
if arguments.get("--choose"):
indexf = tempfile.NamedTemporaryFile(suffix="pitivi_bundle")
index = "http://pitivi.ecchi.ca/bundles/daily/%ss/archives/" % (bitness)
os.system("wget %s -O %s" % (index, indexf.name))
parser = MyHTMLParser(index)
parser.feed(open(indexf.name).read())
print("Avalaible bundles:")
i = 0
for a in parser.archives:
bname = os.path.basename(a)
tstruct = time.strptime(bname.split("-pitivi-latest")[0], "%Y%m%d-%H%M%S")
dtime = datetime.datetime(*tstruct[:6])
print("[%d] From %s -> %s" % (i, dtime.strftime("%d %B %y - %H:%m"), bname))
i += 1
i = int(input("What bundle do you what do use? "))
if i > len(parser.archives):
print("Wrong answer %d > number of acrhive: %d" % (i, len(parser.archives)))
bundle = parser.archives[i]
else:
bundle = "http://pitivi.ecchi.ca/bundles/daily/%ss/pitivi-latest-%s.tar.xz" % (
bitness, arch)
os.system("wget %s -O %s" % (bundle, tmpfile.name))
return tmpfile
if __name__ == "__main__":
arguments = docopt(__doc__, version='update_pitivi_bundle')
tmpfile = download_bundle(arguments)
cdir = os.path.abspath(os.path.dirname(__file__))
print(cdir)
slink = os.path.join(cdir, "pitivi-0.94-%s" % arch)
print(slink)
bundle = os.path.realpath(slink)
md5 = slink + ".md5sum"
try:
os.remove(md5)
except FileNotFoundError:
pass
try:
os.remove(slink)
except FileNotFoundError:
pass
try:
os.remove(bundle)
except FileNotFoundError:
pass
tarfile.open(tmpfile.name).extractall()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment