This repository has been archived by the owner on Sep 2, 2021. It is now read-only.
/
sabayon.py
82 lines (71 loc) · 2.33 KB
/
sabayon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# -*- coding: utf-8 -*-
import sqlite3
import datetime
import time
import subprocess
from .utils import helper
from .utils.db import downstream
from .utils.types import Repo, DownstreamRelease
distro_id = downstream.distro("sabayon", "", "A binary distribution derived from Gentoo.", "http://www.sabayonlinux.org")
MIRROR = "mirror.internode.on.net"
HTTP_START_DIR = "pub/SabayonLinux"
FTP_START_DIR = "pub/sabayonlinux"
VERSIONS = ["3.5", "4", "5"]
CURRENT = "4"
FUTURE = "5"
ARCHES = ["amd64", "x86"]
# return a list of ["ubuntu", branch, codename, component, arch, None, None]
def get_repos(test):
repos = []
for v in VERSIONS:
for a in ARCHES:
branch = "past"
if v==CURRENT:
branch = "current"
elif v==FUTURE:
branch = "future"
repo = Repo()
repo.distro_id = distro_id
repo.codename = v
repo.component = ""
repo.architecture = a
downstream.repo(repo, test)
downstream.add_branch(repo, branch, test)
repos.append(repo)
return repos
# return a list of [name, version, revision, epoch, time, extra]
def crawl_repo(repo):
fn = "".join(("files/sabayon/packages-",repo.codename,"-",repo.architecture,"-",str(time.time()),".db"))
url = "".join(("ftp://",MIRROR,"/",FTP_START_DIR,"/entropy/standard/sabayonlinux.org/database/", repo.architecture, "/", repo.codename, "/packages.db.bz2"))
#print "open url"
t = helper.open_url(url,fn+".bz2", repo.last_crawl)
if t==None:
return (repo.last_crawl, [])
#print "extract"
try:
p = subprocess.Popen(("bunzip2",fn+".bz2"),stdout=None)
x = p.wait()
except OSError, e:
print e
x=-1
#print "sql stuff"
conn = sqlite3.connect(fn)
c = conn.cursor()
#print "go sql"
c.execute("SELECT baseinfo.name, baseinfo.version, baseinfo.revision, baseinfo.branch, extrainfo.datecreation FROM baseinfo, extrainfo WHERE baseinfo.idpackage = extrainfo.idpackage;")
#print "sql done"
rels = []
for name, version, revision, branch, date in c:
dt = datetime.datetime.fromtimestamp(float(date))
if repo.last_crawl==None or repo.last_crawl<dt:
#print version
if "-" in version and "-" == version[-3]:
version, gentoo_revision = version.rsplit("-")
revision = str(gentoo_revision[1:]) + "." + str(revision)
rel = DownstreamRelease()
rel.package = name
rel.version = version
rel.revision = revision
rel.released = dt
rels.append(rel)
return t, rels