[133320] contrib/pypi2port/pypi2port.py
gaurav at macports.org
gaurav at macports.org
Wed Feb 25 12:26:06 PST 2015
Revision: 133320
https://trac.macports.org/changeset/133320
Author: gaurav at macports.org
Date: 2015-02-25 12:26:06 -0800 (Wed, 25 Feb 2015)
Log Message:
-----------
contrib/pypi2port: Removed progressbar as a dependency
Modified Paths:
--------------
contrib/pypi2port/pypi2port.py
Modified: contrib/pypi2port/pypi2port.py
===================================================================
--- contrib/pypi2port/pypi2port.py 2015-02-25 17:57:49 UTC (rev 133319)
+++ contrib/pypi2port/pypi2port.py 2015-02-25 20:26:06 UTC (rev 133320)
@@ -6,7 +6,6 @@
import os
import hashlib
import zipfile
-import progressbar as pb
import requests
try:
import xmlrpclib
@@ -18,6 +17,7 @@
import re
import difflib
import subprocess
+import time
client = xmlrpclib.ServerProxy('http://pypi.python.org/pypi')
@@ -99,40 +99,36 @@
url = dict['url']
file_name = src_dir + '/' + dict['filename']
- # print("HERE")
r = requests.get(url)
-
if r.status_code == 200 :
with open(file_name, 'wb') as f:
meta = r.headers['content-length']
file_size = int(meta)
- widgets = ['Fetching: ', pb.Percentage(), ' ',
- pb.Bar(marker=pb.RotatingMarker(), left='[', right=']'),
- ' ', pb.ETA(), ' ', pb.FileTransferSpeed()]
- pbar = pb.ProgressBar(widgets=widgets, maxval=int(file_size))
- pbar.start()
-
+ pattern = ["-","\\", "|", "/"]
+ patternIndex = 0
file_size_dl = 0
block_sz = 1024
-
+ toolbar_width = int(file_size/block_sz)+1
+ sys.stdout.write("["+"-"*int(file_size_dl/block_sz)+pattern[patternIndex]+" "*int((file_size-file_size_dl)/block_sz-1)+"] "+" "+"(%5d Kb of %5d Kb)"% (file_size_dl, file_size))
+ sys.stdout.flush()
+ # sys.stdout.write("\b" * (toolbar_width+1)) # return to start of line, after '['
for chunk in r.iter_content(block_sz):
if file_size_dl+block_sz > file_size:
file_size_dl = file_size
else:
file_size_dl += block_sz
f.write(chunk)
- pbar.update(file_size_dl)
+ time.sleep(0.1)
+ sys.stdout.write("\b" * (toolbar_width+22+1)) # return to start of line, after '['
+ sys.stdout.write("-"*int(file_size_dl/block_sz)+pattern[patternIndex]+" "*int((file_size-file_size_dl)/block_sz-1)+"] "+" "+"(%5d Kb of %5d Kb)"% (file_size_dl, file_size))
+ sys.stdout.flush()
+ patternIndex = (patternIndex + 1)%4
+ # sys.stdout.write("\b" * (toolbar_width+22+1)) # return to start of line, after '['
+ sys.stdout.write(" OK\n")
+ sys.stdout.flush()
- pbar.finish()
-
checksum_md5_calc = hashlib.md5(open(file_name,'rb').read()).hexdigest()
- # print(file_name)
- # sys.exit(1)
- # command = "openssl md5 "+file_name
- # command = command.split()
- # checksum_md5_calc = str(subprocess.check_output(command, stderr=subprocess.STDOUT)).split('=')[1][1:-3]
- # print(checksum_md5_calc)
if str(checksum_md5) == str(checksum_md5_calc):
print('Successfully fetched')
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/macports-changes/attachments/20150225/e7073dfc/attachment.html>
More information about the macports-changes
mailing list