Skip to content

Commit

Permalink
1.Remove version in requirements.txt 2.Fix gevent patch problem
Browse files Browse the repository at this point in the history
  • Loading branch information
carlcarl committed Sep 26, 2013
1 parent 2b6e826 commit 35061e4
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 28 deletions.
9 changes: 9 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
0.0.2
-----
* Fix gevent download complete error
* Remove the version with required modules

0.0.1
------
* Initial release.

1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ gevent
~~~~~~
* 1:13.83
* 1:10.13
* 1:04.73
64 changes: 41 additions & 23 deletions grabflickr/grabflickr.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
pass
else:
from gevent import monkey
# Workround for multiprocess download method
monkey.patch_all(socket=False, thread=False, time=False)
import sys
import os
import md5
Expand All @@ -30,6 +28,10 @@
api_key = ''
api_secret = ''

SINGLE_PROCESS = 0
MULTIPROCESS = 1
GEVENT = 2


def read_config():
parser = SafeConfigParser()
Expand Down Expand Up @@ -145,7 +147,7 @@ def download_photo(photo):
photo_format = download_url.split('.')[-1]
photo_title = photo_title + '.' + photo_format
file_path = directory + os.sep + photo_title
logger.info('Download {photo_title}...'.format(photo_title=photo_title))
logger.info('Download {photo_title}...'.format(photo_title=photo_title.encode('utf-8')))
resp = requests.get(download_url)
with open(file_path, 'w') as f:
f.write(resp.content)
Expand Down Expand Up @@ -190,16 +192,15 @@ def event_download_photos(photos):
gevent.joinall(jobs)


def _init_logger():
def init_logger():
formatter = logging.Formatter('%(levelname)s: %(message)s')
console = logging.StreamHandler(stream=sys.stdout)
console.setLevel(logging.INFO)
console.setFormatter(formatter)
logger.addHandler(console)


def main():
_init_logger()
def _parse_cli_args():
parser = argparse.ArgumentParser()
parser.add_argument(
'-g',
Expand Down Expand Up @@ -249,34 +250,51 @@ def main():
)
args = parser.parse_args()
logger.debug(args)
return args


def set_image_size_mode(s):
global image_size_mode
image_size_mode = s


def _gevent_patch():
try:
assert gevent
except NameError:
logger.warn('gevent not exist, fallback to multiprocess...')
return MULTIPROCESS
else:
monkey.patch_all() # Must patch before get_photos_info
return GEVENT


def main():

init_logger()
args = _parse_cli_args()

if args.u:
enter_api_key()
return
read_config()

if args.O == GEVENT:
args.O = _gevent_patch()

read_config()
set_image_size_mode(args.s)
photoset_id = args.g
photos = get_photos_info(photoset_id)
global image_size_mode
image_size_mode = args.s
d = args.d if args.d else photoset_id
global directory
directory = d
create_dir(d)
directory = args.d if args.d else photoset_id
create_dir(directory)

if args.O == 0:
if args.O == SINGLE_PROCESS:
single_download_photos(photos)
elif args.O == 1:
elif args.O == MULTIPROCESS:
multiple_download_photos(photos)
elif args.O == 2:
try:
assert gevent
except NameError:
logger.warn('gevent not exist, fallback to multiprocess...')
multiple_download_photos(photos)
else:
monkey.patch_all()
event_download_photos(photos)
elif args.O == GEVENT:
event_download_photos(photos)
else:
logger.error('Unknown Error')

Expand Down
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
gevent==0.13.8
greenlet==0.4.1
requests==1.2.3
wsgiref==0.1.2
gevent
greenlet
requests
wsgiref
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
name='grabflickr',
description='Download photoset of flickr, support single process, multiprocess and gevent(Asynchronous I/O)',
long_description=open('README.rst').read(),
version='0.0.1',
version='0.0.2',
author='carlcarl',
author_email='carlcarlking@gmail.com',
url='https://github.com/carlcarl/grabflickr',
Expand Down

0 comments on commit 35061e4

Please sign in to comment.