forked from javiplx/repomirror
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildlive
executable file
·163 lines (124 loc) · 6.07 KB
/
buildlive
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/python
# Copyright (C) 2011 Javier Palacios
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License Version 2
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
__version__ = "0.5"
__usage__ = """%prog [options] reponame"""
import debian_bundle.deb822 , debian_bundle.debian_support
import repolib.lists.debian
from repolib.debian import debian_component_repository
import repolib
import os , sys , platform
import optparse
def option_parser () :
version_string = "%%prog %s" % __version__
parser = optparse.OptionParser( usage=__usage__ , version=version_string )
parser.set_defaults( status_file = "/var/lib/dpkg/status" )
parser.set_defaults( architecture = platform.machine() )
guess = platform.platform().split('-')
pos = guess.index('with')
parser.set_defaults( breed = guess[pos+1].lower() )
offsite = optparse.OptionGroup( parser , "Off-site parameters" ,
"Parameters required when running out of the original node" )
offsite.add_option( "--status-file" , metavar="FILENAME" ,
help="off-tree dpkg status file" )
offsite.add_option( "--breed" , metavar="BREED" ,
help="group of source repositories to use (debian/ubuntu)" )
offsite.add_option( "--architecture" , metavar="ARCHNAME" ,
help="select architecture for repository" )
parser.add_option( "--repo-version" , metavar="VERSION" ,
help="version identification for the new repo (defaults to name)" )
parser.add_option_group( offsite )
return parser
def buildpath ( pkg , compname ) :
if pkg.has_key( 'Source' ) :
name = pkg['Source'].split()[0]
else :
name = pkg['Package']
if name.find( "lib" ) == 0 :
subdir = name[:4]
else :
subdir = name[0]
return "%s/%s/%s/" % ( compname , subdir , name )
def buildname ( pkg ) :
version = pkg['Version']
if version.find(':')!=-1 :
version = version.split(':',1)[1]
return "%s_%s_%s.deb" % ( pkg['Package'] , version , pkg['Architecture'] )
def main ( all_sources ) :
parser = option_parser()
opts , args = parser.parse_args()
if not args or len(args)>1:
parser.print_help()
sys.exit(1)
repo_name = args[0]
if not opts.repo_version :
repolib.logger.warning( "No version supplied, using '%s'" % repo_name )
opts.repo_version = repo_name
if not all_sources.has_key( opts.breed ) :
repolib.logger.critical( "Breed '%s' unknow. Select one from %s" % ( opts.breed , " ".join(all_sources.keys()) ) )
sys.exit(3)
sources = all_sources[opts.breed]
try :
config = { 'force':True , 'type':"apt" , 'version':opts.repo_version ,
'architectures':opts.architecture , 'components':"-" }
newrepo = repolib.BuildRepository.new( repo_name , config )
except Exception , ex :
repolib.logger.critical( "Repo %s : %s" % ( repo_name , ex ) )
sys.exit(2)
packages = debian_bundle.debian_support.PackageFile( opts.status_file )
for pkg in packages :
pkginfo = debian_bundle.deb822.Deb822Dict( pkg )
if pkginfo['Status'] == "purge ok not-installed" :
repolib.logger.info( "Package %s was removed" % pkginfo['Package'] )
continue
filename = buildname( pkginfo )
for compname in ( "main" , "contrib" , "non-free" ,
"universe" , "multiverse" , "restricted" ) :
path = buildpath( pkginfo , compname )
for repo,(name,baseurl) in sources.items() :
filepath = repolib.urljoin( name , path )
pkginfo['Filename'] = repolib.urljoin( filepath , filename )
if pkginfo.has_key('Conffiles') : pkginfo.pop('Conffiles')
url = repolib.urljoin( baseurl , pkginfo['Filename'] )
request = repolib.download_head( url )
response = repolib.download( request )
if response :
if compname not in newrepo.components :
repolib.logger.info( "Adding component %s/%s" % ( opts.architecture , compname ) )
newrepo.components.append( compname )
newrepo.feeds.append( debian_component_repository( newrepo , opts.architecture , compname ) )
pkginfo['Size'] = response.headers['Content-Length']
pos = newrepo.components.index( compname )
for pkgsfile in newrepo.feeds[pos].outchannels :
repolib.lists.debian.dump_package( pkginfo , pkgsfile )
break
else :
compname = ""
if compname :
break
else :
repolib.logger.warning( "Failed %s %s" % ( pkginfo['Package'] , pkginfo['Version'] ) )
newrepo.post_build()
if __name__ == "__main__" :
sources = {}
sources['ubuntu'] = {}
sources['ubuntu']['ubuntu'] = ( 'pool/' , "http://es.archive.ubuntu.com/ubuntu/" )
sources['ubuntu']['ubuntu-security'] = ( 'pool/' , "http://security.ubuntu.com/ubuntu/" )
sources['ubuntu']['ubuntu-partner'] = ( 'pool/' , "http://archive.canonical.com/ubuntu/" )
sources['ubuntu']['netbook-ppa'] = ( 'pool/' , "http://ppa.launchpad.net/netbook-remix-team/ubuntu" )
sources['debian'] = {}
sources['debian']['debian'] = ( 'pool/' , "http://ftp.es.debian.org/debian/" )
sources['debian']['debian-security'] = ( 'pool/updates/' , "http://security.debian.org/" )
sources['debian']['debian-volatile'] = ( 'pool/volatile/' , "http://volatile.debian.org/debian-volatile/" )
sources['debian']['backports'] = ( 'pool/' , "http://backports.debian.org/debian-backports/" )
sources['debian']['archive'] = ( 'pool/' , "http://archive.debian.org/debian/" )
sources['debian']['archive-security'] = ( 'pool/updates/' , "http://archive.debian.org/debian-security/" )
main( sources )