import re, base64
import ConfigParser
-username = ""
-password = ""
+USERNAME = ""
+PASSWORD = ""
+CACHE_DIR = "cache"
def read_config(config_file):
config_file = os.path.expanduser(config_file)
def http_get(url):
print "Downloading %s" %url
request = urllib2.Request(url)
- if username and password:
- base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
+ if USERNAME and PASSWORD:
+ base64string = base64.encodestring('%s:%s' % (USERNAME, PASSWORD)).replace('\n', '')
request.add_header("Authorization", "Basic %s" % base64string)
html_page = urllib2.urlopen(request)
return html_page
else:
print "Already exists: %s" % out
-def get_package_list2(image_name, base_url, build_id):
- cache_dir = "cache"
- if not os.path.exists(cache_dir):
- os.makedirs(cache_dir)
- cache_file = "%s/%s-%s.packages" %(cache_dir, image_name, build_id )
+def get_package_list(image_name, base_url, build_id, cachedir):
+ cache_file = "%s/%s-%s.packages" %(cachedir, image_name, build_id )
package_file = None
if not os.path.exists(cache_file):
image_packages = "%s/%s/images/%s/%s-%s.packages" %(base_url, build_id, image_name, image_name, build_id )
release_url = "%s/%s" %(BASE, SNAPSHOTS)
if options.username:
- username = options.username
+ USERNAME = options.username
elif config.has_option('DEFAULT', 'username'):
- username = config.get('DEFAULT', 'username')
+ USERNAME = config.get('DEFAULT', 'username')
if options.password:
- password = options.password
+ PASSWORD = options.password
elif config.has_option('DEFAULT', 'password'):
- password = config.get('DEFAULT', 'password')
-
-p1 = get_package_list2(options.image, release_url, options.old)
-p2 = get_package_list2(options.image, release_url, options.new)
+ PASSWORD = config.get('DEFAULT', 'password')
+# Initialize cache dir
+if config.has_option('DEFAULT', 'cache-dir'):
+ CACHE_DIR = config.get('DEFAULT', 'cache-dir')
+CACHE_DIR = os.path.abspath(os.path.expanduser(CACHE_DIR))
+packages_files_dir = os.path.join(CACHE_DIR, 'packages-files')
+if not os.path.exists(packages_files_dir):
+ os.makedirs(packages_files_dir)
+
+p1 = get_package_list(options.image, release_url, options.old, packages_files_dir)
+p2 = get_package_list(options.image, release_url, options.new, packages_files_dir)
pkgs1 = {'%s|%s' % (pkg, attr['arch']) for pkg, attr in p1.iteritems()}
pkgs2 = {'%s|%s' % (pkg, attr['arch']) for pkg, attr in p2.iteritems()}
pkgs2 = {'%s|%s' % (pkg, attr['version']) for pkg, attr in p2.iteritems()}
changedpkgs = [pkg.split('|')[0] for pkg in pkgs2.difference(pkgs1) if pkg.split('|')[0] in p1]
-if not os.path.exists('old'):
- os.makedirs('old')
+old_pkgs_dir = os.path.join(CACHE_DIR, 'rpms')
+if not os.path.exists(old_pkgs_dir):
+ os.makedirs(old_pkgs_dir)
if not os.path.exists('new'):
os.makedirs('new')
if not os.path.exists('rpms'):
for p in changedpkgs:
rpm = "%s-%s.%s.rpm" % (p, p1[p]['version'], p1[p]['arch'])
arch = p1[p]['arch']
- download("%s/%s/repos/pc/x86_64/packages/%s/%s" % (release_url, options.old, arch, rpm), "old/%s" % rpm)
+ download("%s/%s/repos/pc/x86_64/packages/%s/%s" % (release_url, options.old, arch, rpm), os.path.join(old_pkgs_dir, rpm))
rpm = "%s-%s.%s.rpm" % (p, p2[p]['version'], p2[p]['arch'])
download("%s/%s/repos/pc/x86_64/packages/%s/%s" %(release_url, options.new, arch, rpm), "rpms/%s" % rpm)