This repository has been archived by the owner on Sep 2, 2021. It is now read-only.
/
arch.py
121 lines (107 loc) · 3.08 KB
/
arch.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# -*- coding: utf-8 -*-
import subprocess
import time
import datetime
import os
from .utils import helper
from .utils.db import downstream
from .utils.types import Repo, DownstreamRelease
MIRROR = "ftp.archlinux.org"
HTTP_START_DIR = None
FTP_START_DIR = None
ARCHES = ["i686","x86_64"]
distro_id = downstream.distro("arch", "", "A rolling release binary distribution.", "http://www.archlinx.org")
# return a list of ["ubuntu", branch, codename, component, arch, None, None]
def get_repos(test):
repos = []
for comp in ["core","extra"]:
for a in ARCHES:
repo = Repo()
repo.distro_id = distro_id
repo.component = comp
repo.architecture = a
repo.codename = ""
repos.append(repo)
downstream.repo(repo, test)
downstream.add_branch(repo, "current", test)
for comp in ["testing"]:
for a in ARCHES:
repo = Repo()
repo.distro_id = distro_id
repo.component = comp
repo.architecture = a
repo.codename = ""
repos.append(repo)
downstream.repo(repo, test)
downstream.add_branch(repo, "future", test)
for comp in ["community"]:
for a in ARCHES:
repo = Repo()
repo.distro_id = distro_id
repo.component = comp
repo.architecture = a
repo.codename = ""
repos.append(repo)
downstream.repo(repo, test)
downstream.add_branch(repo, "experimental", test)
return repos
# return a list of [name, version, revision, epoch, time, extra]
def crawl_repo(repo):
rels = []
fn = "".join(("files/arch/",repo.component,"-",str(time.time()),".db.tar.gz"))
url = "".join(("http://",MIRROR,"/",repo.component,"/os/",repo.architecture,"/",repo.component,".db.tar.gz"))
new_dir = "".join(("files/arch/",repo.component,"-",str(time.time()),"/"))
os.mkdir(new_dir)
t = helper.open_url(url,fn,repo.last_crawl)
if t:
try:
#print " ".join(("/bin/tar","-xzf ",fn,"-C",new_dir))
p = subprocess.Popen(("/bin/tar","-xzf",fn,"-C",new_dir),stdout=None)
x = p.wait()
except OSError, e:
print e
x=-1
for d in os.listdir(new_dir):
fn = "".join((new_dir,d,"/desc"))
try:
last = os.stat(fn)
except OSError:
print "no cache"
last = None
if last:
last = last.st_mtime
last = datetime.datetime.fromtimestamp(last)
# ignore if its not new
if last and repo.last_crawl!=None and last<repo.last_crawl:
continue
pkg = {}
key = None
for line in open(fn):
if line[0]=="%":
key = line.strip("\n%")
pkg[key] = []
elif line=="\n":
if key:
pkg[key] = "".join(pkg[key]).strip()
key = None
else:
pkg[key].append(line)
version, revision = pkg["VERSION"].rsplit("-",1)
if " " in pkg["BUILDDATE"]:
try:
released = datetime.datetime.strptime(pkg["BUILDDATE"],"%a %b %d %H:%M:%S %Y")
except:
#print "ERROR: cannot parse",pkg["BUILDDATE"]
pass
else:
released = datetime.datetime.fromtimestamp(long(pkg["BUILDDATE"]))
rel = DownstreamRelease()
rel.repo_id = repo.id
rel.package = pkg["NAME"]
rel.version = version
rel.revision = revision
rel.released = released
rels.append(rel)
if t == None:
t = repo.last_crawl
return (t, rels)