Skip to content

Commit

Permalink
Merge pull request #54 from lpsinger/http_user
Browse files Browse the repository at this point in the history
Support user and password for http backend
  • Loading branch information
abraithwaite committed May 27, 2015
2 parents cb7e9a4 + 660e2fb commit b6deb1f
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions git_fat/git_fat.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,20 @@ def _obj_dir():
return objdir


def http_get(baseurl, filename):
def http_get(baseurl, filename, user=None, password=None):
''' Returns file descriptor for http file stream, catches urllib2 errors '''
import urllib2
try:
print("Downloading: {0}".format(filename))
geturl = '/'.join([baseurl, filename])
res = urllib2.urlopen(geturl)
if user is None:
res = urllib2.urlopen(geturl)
else:
mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
mgr.add_password(None, baseurl, user, password)
handler = urllib2.HTTPBasicAuthHandler(mgr)
opener = urllib2.build_opener(handler)
res = opener.open(geturl)
return res.fp
except urllib2.URLError as e:
logger.warning(e.reason + ': {0}'.format(geturl))
Expand Down Expand Up @@ -304,13 +311,15 @@ def __init__(self, base_dir, **kwargs):
raise RuntimeError('http remote url must start with http:// or https://')

self.remote_url = remote_url
self.user = kwargs.get('user')
self.password = kwargs.get('password')
self.base_dir = base_dir

def pull_files(self, file_list):
is_success = True

for o in file_list:
stream = http_get(self.remote_url, o)
stream = http_get(self.remote_url, o, self.user, self.password)
blockiter = readblocks(stream)

# HTTP Error
Expand Down

0 comments on commit b6deb1f

Please sign in to comment.