Move requests code out of common.py, closes #114

This commit is contained in:
Daniel Martí 2015-08-31 17:05:08 -07:00
parent 3bc0d43786
commit 04e6f2ebfd
4 changed files with 42 additions and 17 deletions

View file

@ -17,12 +17,14 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# common.py is imported by all modules, so do not import third-party
# libraries here as they will become a requirement for all commands.
import os
import sys
import re
import shutil
import glob
import requests
import stat
import subprocess
import time
@ -1916,20 +1918,6 @@ def string_is_integer(string):
return False
def download_file(url, local_filename=None, dldir='tmp'):
filename = url.split('/')[-1]
if local_filename is None:
local_filename = os.path.join(dldir, filename)
# the stream=True parameter keeps memory usage low
r = requests.get(url, stream=True)
with open(local_filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
f.flush()
return local_filename
def get_per_app_repos():
'''per-app repos are dirs named with the packageName of a single app'''