From ef62cec23dc23925816006375fd69833b09c2bc3 Mon Sep 17 00:00:00 2001 From: ponty Date: Wed, 21 Mar 2012 20:47:56 +0100 Subject: [PATCH 01/11] new start method: python -m collective.eggproxy.wsgi --- collective/eggproxy/wsgi.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/collective/eggproxy/wsgi.py b/collective/eggproxy/wsgi.py index 76f7122..c83f532 100644 --- a/collective/eggproxy/wsgi.py +++ b/collective/eggproxy/wsgi.py @@ -149,3 +149,7 @@ def standalone(): #this_dir = os.path.dirname(__file__) #sys.argv.extend(['serve', os.path.join(this_dir, 'wsgi.ini')]) #paste.script.command.run() + + +if __name__=='__main__': + standalone() \ No newline at end of file From 82e5e64f5f44dfe02de27ac1b940b2dcbc46d522 Mon Sep 17 00:00:00 2001 From: ponty Date: Wed, 21 Mar 2012 20:50:57 +0100 Subject: [PATCH 02/11] new config option: create_eggs_directory=0/1 --- collective/eggproxy/config.py | 1 + collective/eggproxy/wsgi.py | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/collective/eggproxy/config.py b/collective/eggproxy/config.py index 014868f..45a0956 100644 --- a/collective/eggproxy/config.py +++ b/collective/eggproxy/config.py @@ -34,6 +34,7 @@ config = ConfigParser() config.add_section("eggproxy") config.set("eggproxy", "eggs_directory", "/var/www") +config.set("eggproxy", "create_eggs_directory", "0") config.set("eggproxy", "index", 'http://pypi.python.org/simple') config.set("eggproxy", "update_interval", '24') config.set("eggproxy", "port", '8888') diff --git a/collective/eggproxy/wsgi.py b/collective/eggproxy/wsgi.py index c83f532..5a19dc7 100644 --- a/collective/eggproxy/wsgi.py +++ b/collective/eggproxy/wsgi.py @@ -46,8 +46,13 @@ def __init__(self, index_url=None, eggs_dir=None): if not eggs_dir: eggs_dir = config.get('eggproxy', 'eggs_directory') if not os.path.isdir(eggs_dir): - print 'You must create the %r directory' % eggs_dir - sys.exit() + create_eggs_directory = config.getboolean('eggproxy', 'create_eggs_directory') + if create_eggs_directory: + print 'Creating the %r directory' % eggs_dir + os.makedirs(eggs_dir) + else: + print 'You must create the %r directory' % eggs_dir + sys.exit() self.eggs_index_proxy = IndexProxy(PackageIndex(index_url=index_url)) self.eggs_dir = eggs_dir From 75ab8ee074e6aa65a817d6456ab3ff632001a328 Mon Sep 17 00:00:00 2001 From: ponty Date: Wed, 21 Mar 2012 20:53:20 +0100 Subject: [PATCH 03/11] new config option: logging=0/1 --- collective/eggproxy/config.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/collective/eggproxy/config.py b/collective/eggproxy/config.py index 45a0956..2233e09 100644 --- a/collective/eggproxy/config.py +++ b/collective/eggproxy/config.py @@ -19,6 +19,7 @@ from ConfigParser import ConfigParser from ConfigParser import NoSectionError +import logging # First try: User-specific config file CONFIG_FILE = os.path.join(os.path.expanduser('~'), 'eggproxy.conf') @@ -40,9 +41,17 @@ config.set("eggproxy", "port", '8888') config.set("eggproxy", "always_refresh", '0') config.set("eggproxy", "timeout", '3') +config.set("eggproxy", "logging", "0") if os.path.exists(CONFIG_FILE): config.readfp(open(CONFIG_FILE)) + + if config.getboolean('eggproxy', 'logging'): + logging.basicConfig( + level=logging.DEBUG, + format='%(asctime)-6s: %(name)30s - %(levelname)s - %(message)s', + ) + # Check for old [default] section that fails with python2.6 had thus has # been changed to [eggproxy] in 0.4 try: From 8bd36551b4a9ec1c9d852e55391c4fe045114d4a Mon Sep 17 00:00:00 2001 From: ponty Date: Wed, 21 Mar 2012 20:58:26 +0100 Subject: [PATCH 04/11] store dead links in cache as empty files During nose install a lot of dead links are scanned each time without this patch. --- collective/eggproxy/wsgi.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/collective/eggproxy/wsgi.py b/collective/eggproxy/wsgi.py index 5a19dc7..0a85283 100644 --- a/collective/eggproxy/wsgi.py +++ b/collective/eggproxy/wsgi.py @@ -115,8 +115,13 @@ def checkEggFor(self, package_name, eggname): try: self.eggs_index_proxy.updateEggFor(package_name, eggname, eggs_dir=self.eggs_dir) - except ValueError: + except Exception as e: + open(filename,'w').write('') return None + + if os.path.getsize(filename)==0: + return None + return filename From 0e6d51c943fc946f34d33270c64337422cab2ad2 Mon Sep 17 00:00:00 2001 From: ponty Date: Wed, 21 Mar 2012 21:01:10 +0100 Subject: [PATCH 05/11] more logging --- collective/eggproxy/config.py | 2 +- collective/eggproxy/utils.py | 13 ++++++++++--- collective/eggproxy/wsgi.py | 8 ++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/collective/eggproxy/config.py b/collective/eggproxy/config.py index 2233e09..922debe 100644 --- a/collective/eggproxy/config.py +++ b/collective/eggproxy/config.py @@ -31,7 +31,7 @@ if not os.path.exists(CONFIG_FILE): CONFIG_FILE = '/etc/eggproxy.conf' -#print "Using config file", CONFIG_FILE +print "Using config file", CONFIG_FILE config = ConfigParser() config.add_section("eggproxy") config.set("eggproxy", "eggs_directory", "/var/www") diff --git a/collective/eggproxy/utils.py b/collective/eggproxy/utils.py index f5ca9c7..a946a0d 100644 --- a/collective/eggproxy/utils.py +++ b/collective/eggproxy/utils.py @@ -33,6 +33,9 @@ from pkg_resources import Requirement from collective.eggproxy.config import config +import logging + +log=logging.getLogger('collective.eggproxy.utils') ALWAYS_REFRESH = config.getboolean('eggproxy', 'always_refresh') EGGS_DIR = config.get("eggproxy", "eggs_directory") @@ -234,8 +237,12 @@ def updateEggFor(self, package_name, eggname, eggs_dir=EGGS_DIR): filename, md5 = egg_info_for_url(dist.location) if filename == eggname: tmp = tempfile.gettempdir() - tmp_location = self.index.download(dist.location, tmp) - shutil.move(tmp_location, file_path) - return + try: + tmp_location = self.index.download(dist.location, tmp) + log.debug('Downloaded %s\n' % dist.location) + shutil.move(tmp_location, file_path) + return + except Exception, err: + log.debug('Error downloading %s: \n\t%s\n' % (dist.location, err)) raise ValueError, "Egg '%s' not found in index" % eggname diff --git a/collective/eggproxy/wsgi.py b/collective/eggproxy/wsgi.py index 0a85283..685c0db 100644 --- a/collective/eggproxy/wsgi.py +++ b/collective/eggproxy/wsgi.py @@ -27,6 +27,9 @@ from collective.eggproxy import IndexProxy from collective.eggproxy import PackageNotFound from collective.eggproxy.config import config +import logging + +log=logging.getLogger('collective.eggproxy.wsgi') ALWAYS_REFRESH = config.getboolean('eggproxy', 'always_refresh') if ALWAYS_REFRESH: @@ -111,13 +114,18 @@ def checkPackageIndex(self, package_name): def checkEggFor(self, package_name, eggname): filename = os.path.join(self.eggs_dir, package_name, eggname) + log.debug('Asking for package:%s egg:%s'% (package_name, eggname)) if not os.path.exists(filename): + log.debug('Not in cache, start downloading..') try: self.eggs_index_proxy.updateEggFor(package_name, eggname, eggs_dir=self.eggs_dir) except Exception as e: open(filename,'w').write('') + log.debug('Download error:%s'% (e)) return None + else: + log.debug('Found in cache:%s'% (filename)) if os.path.getsize(filename)==0: return None From 9404243136593b99a511021465a424b3aae1e933 Mon Sep 17 00:00:00 2001 From: ponty Date: Tue, 27 Mar 2012 21:00:43 +0200 Subject: [PATCH 06/11] pep8 formatting --- collective/eggproxy/config.py | 8 ++++---- collective/eggproxy/wsgi.py | 18 +++++++++--------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/collective/eggproxy/config.py b/collective/eggproxy/config.py index 922debe..207360f 100644 --- a/collective/eggproxy/config.py +++ b/collective/eggproxy/config.py @@ -48,10 +48,10 @@ if config.getboolean('eggproxy', 'logging'): logging.basicConfig( - level=logging.DEBUG, - format='%(asctime)-6s: %(name)30s - %(levelname)s - %(message)s', - ) - + level=logging.DEBUG, + format='%(asctime)-6s: %(name)30s - %(levelname)s - %(message)s', + ) + # Check for old [default] section that fails with python2.6 had thus has # been changed to [eggproxy] in 0.4 try: diff --git a/collective/eggproxy/wsgi.py b/collective/eggproxy/wsgi.py index 685c0db..bd8eb63 100644 --- a/collective/eggproxy/wsgi.py +++ b/collective/eggproxy/wsgi.py @@ -29,7 +29,7 @@ from collective.eggproxy.config import config import logging -log=logging.getLogger('collective.eggproxy.wsgi') +log = logging.getLogger('collective.eggproxy.wsgi') ALWAYS_REFRESH = config.getboolean('eggproxy', 'always_refresh') if ALWAYS_REFRESH: @@ -114,20 +114,20 @@ def checkPackageIndex(self, package_name): def checkEggFor(self, package_name, eggname): filename = os.path.join(self.eggs_dir, package_name, eggname) - log.debug('Asking for package:%s egg:%s'% (package_name, eggname)) + log.debug('Asking for package:%s egg:%s' % (package_name, eggname)) if not os.path.exists(filename): log.debug('Not in cache, start downloading..') try: self.eggs_index_proxy.updateEggFor(package_name, eggname, eggs_dir=self.eggs_dir) except Exception as e: - open(filename,'w').write('') - log.debug('Download error:%s'% (e)) + open(filename, 'w').write('') + log.debug('Download error:%s' % (e)) return None else: - log.debug('Found in cache:%s'% (filename)) - - if os.path.getsize(filename)==0: + log.debug('Found in cache:%s' % (filename)) + + if os.path.getsize(filename) == 0: return None return filename @@ -169,5 +169,5 @@ def standalone(): #paste.script.command.run() -if __name__=='__main__': - standalone() \ No newline at end of file +if __name__ == '__main__': + standalone() From f41fa9f576ec363dd2e95f4244d554c6d4634d00 Mon Sep 17 00:00:00 2001 From: ponty Date: Tue, 27 Mar 2012 21:01:02 +0200 Subject: [PATCH 07/11] catch only ValueError --- collective/eggproxy/wsgi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collective/eggproxy/wsgi.py b/collective/eggproxy/wsgi.py index bd8eb63..12de9b2 100644 --- a/collective/eggproxy/wsgi.py +++ b/collective/eggproxy/wsgi.py @@ -120,7 +120,7 @@ def checkEggFor(self, package_name, eggname): try: self.eggs_index_proxy.updateEggFor(package_name, eggname, eggs_dir=self.eggs_dir) - except Exception as e: + except ValueError as e: open(filename, 'w').write('') log.debug('Download error:%s' % (e)) return None From 2bb296134ef4a56c1d9a9280373a2bb3302c84a9 Mon Sep 17 00:00:00 2001 From: ponty Date: Tue, 27 Mar 2012 21:07:25 +0200 Subject: [PATCH 08/11] logger renamed --- collective/eggproxy/wsgi.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/collective/eggproxy/wsgi.py b/collective/eggproxy/wsgi.py index 12de9b2..b146c34 100644 --- a/collective/eggproxy/wsgi.py +++ b/collective/eggproxy/wsgi.py @@ -29,7 +29,7 @@ from collective.eggproxy.config import config import logging -log = logging.getLogger('collective.eggproxy.wsgi') +logger = logging.getLogger(__name__) ALWAYS_REFRESH = config.getboolean('eggproxy', 'always_refresh') if ALWAYS_REFRESH: @@ -114,18 +114,18 @@ def checkPackageIndex(self, package_name): def checkEggFor(self, package_name, eggname): filename = os.path.join(self.eggs_dir, package_name, eggname) - log.debug('Asking for package:%s egg:%s' % (package_name, eggname)) + logger.debug('Asking for package:%s egg:%s' % (package_name, eggname)) if not os.path.exists(filename): - log.debug('Not in cache, start downloading..') + logger.debug('Not in cache, start downloading..') try: self.eggs_index_proxy.updateEggFor(package_name, eggname, eggs_dir=self.eggs_dir) except ValueError as e: open(filename, 'w').write('') - log.debug('Download error:%s' % (e)) + logger.debug('Download error:%s' % (e)) return None else: - log.debug('Found in cache:%s' % (filename)) + logger.debug('Found in cache:%s' % (filename)) if os.path.getsize(filename) == 0: return None From 9b6ff329d3fd1158a0ccdbbaa0eb63c21efff389 Mon Sep 17 00:00:00 2001 From: ponty Date: Sat, 21 Apr 2012 11:57:15 +0200 Subject: [PATCH 09/11] git ignore hidden files --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 5c77ab2..5288ff5 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,6 @@ develop-eggs parts dist build + +.* +!.gitignore From 84852dbf41eb16f210ea56d49aa16550d2ed3d21 Mon Sep 17 00:00:00 2001 From: ponty Date: Sun, 13 Jan 2013 09:04:14 +0100 Subject: [PATCH 10/11] bugfix: no exception if 2 instances downloading the same package --- collective/eggproxy/utils.py | 7 +++++++ collective/eggproxy/wsgi.py | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/collective/eggproxy/utils.py b/collective/eggproxy/utils.py index a946a0d..fc8c484 100644 --- a/collective/eggproxy/utils.py +++ b/collective/eggproxy/utils.py @@ -240,6 +240,13 @@ def updateEggFor(self, package_name, eggname, eggs_dir=EGGS_DIR): try: tmp_location = self.index.download(dist.location, tmp) log.debug('Downloaded %s\n' % dist.location) + + # BUG: + # 2 instances are downloading "traits" package. + # First instance removes the file + # from /tmp with "shutil.move", + # second instance can not find it -> + # "shutil.move" raises exception shutil.move(tmp_location, file_path) return except Exception, err: diff --git a/collective/eggproxy/wsgi.py b/collective/eggproxy/wsgi.py index b146c34..d0169e3 100644 --- a/collective/eggproxy/wsgi.py +++ b/collective/eggproxy/wsgi.py @@ -121,8 +121,10 @@ def checkEggFor(self, package_name, eggname): self.eggs_index_proxy.updateEggFor(package_name, eggname, eggs_dir=self.eggs_dir) except ValueError as e: - open(filename, 'w').write('') logger.debug('Download error:%s' % (e)) + if not os.path.exists(filename): + open(filename, 'w').write('') + logger.debug('Writing empty file at:%s' % (filename)) return None else: logger.debug('Found in cache:%s' % (filename)) From 1968f02ac52f6adbc704745f374220c4801526b6 Mon Sep 17 00:00:00 2001 From: ponty Date: Thu, 9 Jan 2014 16:13:22 +0100 Subject: [PATCH 11/11] set more params in httpserver --- collective/eggproxy/wsgi.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/collective/eggproxy/wsgi.py b/collective/eggproxy/wsgi.py index d0169e3..5184a63 100644 --- a/collective/eggproxy/wsgi.py +++ b/collective/eggproxy/wsgi.py @@ -161,7 +161,15 @@ def standalone(): port = config.get('eggproxy', 'port') # 0.2.0 way of starting the httpserver, but using the config'ed port # number instead of a hardcoded 8888. - httpserver.serve(EggProxyApp(), host='127.0.0.1', port=port) + httpserver.serve(EggProxyApp(), + host='127.0.0.1', + port=port, + socket_timeout=5*60, + use_threadpool=False, + threadpool_workers=10, + threadpool_options=None, + request_queue_size=5 + ) # Post-0.2.0 way of starting the server using hardcoded config by means of # the package-internal .ini file. This does not allow starting it on a # different port, so I [reinout] commented it out for now.