[120392] branches/gsoc14-pip2port/tester.py
gaurav at macports.org
gaurav at macports.org
Mon May 26 23:24:25 PDT 2014
Revision: 120392
https://trac.macports.org/changeset/120392
Author: gaurav at macports.org
Date: 2014-05-26 23:24:25 -0700 (Mon, 26 May 2014)
Log Message:
-----------
Added fetching function for egg files. argparse needs to be modified.
Modified Paths:
--------------
branches/gsoc14-pip2port/tester.py
Modified: branches/gsoc14-pip2port/tester.py
===================================================================
--- branches/gsoc14-pip2port/tester.py 2014-05-27 06:24:11 UTC (rev 120391)
+++ branches/gsoc14-pip2port/tester.py 2014-05-27 06:24:25 UTC (rev 120392)
@@ -13,6 +13,7 @@
import argparse
import sys
import os
+import zipfile
from progressbar import *
try:
import xmlrpclib
@@ -80,7 +81,7 @@
pbar.start()
file_size_dl = 0
- block_sz = 8192
+ block_sz = 1024
while True:
buffer = u.read(block_sz)
if not buffer:
@@ -105,6 +106,65 @@
print "Error: %s - %s." % (e.filename,e.strerror)
+
+def fetch_egg(url):
+ checksum_md5 = url.split('#')[-1].split('=')[-1]
+ parent_dir = './sources/'
+ pkg_name = url.split('/')[-2]
+ src_dir = parent_dir +pkg_name+"/"
+ if not os.path.exists(parent_dir):
+ os.makedirs(parent_dir)
+ if not os.path.exists(src_dir):
+ os.makedirs(src_dir)
+
+ file_name = src_dir + url.split('/')[-1].split('#')[0]
+ print file_name
+
+
+ u = urllib2.urlopen(url)
+ f = open(file_name,'wb')
+ meta = u.info()
+ file_size = int(meta.getheaders("Content-Length")[0])
+
+ widgets = ['Fetching: ', Percentage(), ' ', Bar(marker=RotatingMarker(),left='[',right=']'), ' ', ETA(), ' ', FileTransferSpeed()]
+ pbar = ProgressBar(widgets=widgets, maxval=int(file_size))
+ pbar.start()
+
+ file_size_dl = 0
+ block_sz = 1024
+ while True:
+ buffer = u.read(block_sz)
+ if not buffer:
+ break
+
+ file_size_dl += len(buffer)
+ f.write(buffer)
+ pbar.update(file_size_dl)
+
+ pbar.finish()
+ print
+ f.close()
+
+ checksum_md5_calc = hashlib.md5(open(file_name).read()).hexdigest()
+ if str(checksum_md5_calc) == str(checksum_md5):
+ print 'Successfully fetched\n'
+ zip = zipfile.ZipFile(file_name)
+ for name in zip.namelist():
+ if name.split("/")[0] == "EGG-INFO":
+ print name
+ zip.extract(name,src_dir)
+
+ else:
+ print 'Aborting due to inconsistency on checksums\n'
+ try:
+ os.remove(file_name)
+ except OSError, e:
+ print "Error: %s - %s." % (e.filename,e.strerror)
+
+ return
+
+
+
def main():
parser = argparse.ArgumentParser(description='pip2port tester script.')
@@ -129,6 +189,9 @@
parser.add_argument('-f', '--fetch', action='store_const',
dest='action', const='fetch', required=False,
help='Fetches distfile for a package by <package_url>')
+ parser.add_argument('-fe', '--fetch_egg', action='store_const',
+ dest='action', const='fetch_egg', required=False,
+ help='Fetches distfile for a package by <package_url>')
options=parser.parse_args()
@@ -169,6 +232,15 @@
# print options
fetch(options.package_name,options.package_url)
return
+
+ if options.action == 'fetch_egg':
+# print options,"\n"
+ if options.package_name == None:
+ parser.error("No <package>.egg url specified")
+ else:
+# print options
+ fetch_egg(options.package_name)
+ return
else:
parser.print_help()
parser.error("No input specified")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/macports-changes/attachments/20140526/def3ebe3/attachment-0001.html>
More information about the macports-changes
mailing list