³ò KKc @s³dZdZdZddkZddkZddkZddkZddkZddkZddk Z ei e ƒZ dad„Zdd„Zdefd„ƒYZd efd „ƒYZe d joæddkZei ƒZeiƒZeieiƒeid ƒZeieƒeieƒeieiƒed dƒddkZeiGeiGHeidjpt ‚eƒi!i"Z#e#eijpt de#eif‚ndS(s package loader for auto installing Python packages. A package loader in the spirit of Zero Install that can be used to inject dependencies into the import process. To install:: easy_install -U autoinstall or download, unpack, python setup.py install or try the bootstrap loader. See below. To use:: # You can bind any package name to a URL pointing to something # that can be imported using the zipimporter. autoinstall.bind("pymarc", "http://pypi.python.org/packages/2.5/p/pymarc/pymarc-2.1-py2.5.egg") import pymarc print pymarc.__version__, pymarc.__file__ Changelog:: - added support for non top level packages. - cache files now use filename part from URL. - applied patch from Eric Seidel to add support for loading modules where the module is not at the root of the .zip file. TODO:: - a description of the intended use case - address other issues pointed out in: http://mail.python.org/pipermail/python-dev/2008-March/077926.html Scribbles:: pull vs. push user vs. system web vs. filesystem auto vs. manual manage development sandboxes optional interfaces... def get_data(pathname) -> string with file data. Return the data associated with 'pathname'. Raise IOError if the file wasn't found."); def is_package, "is_package(fullname) -> bool. Return True if the module specified by fullname is a package. Raise ZipImportError is the module couldn't be found."); def get_code, "get_code(fullname) -> code object. Return the code object for the specified module. Raise ZipImportError is the module couldn't be found."); def get_source, "get_source(fullname) -> source string. Return the source code for the specified module. Raise ZipImportError is the module couldn't be found, return None if the archive does contain the module, but has no source for it."); Autoinstall can also be bootstraped with the nascent package loader bootstrap module. For example:: # or via the bootstrap # loader. try: _version = "0.2" import autoinstall if autoinstall.__version__ != _version: raise ImportError("A different version than expected found.") except ImportError, e: # http://svn.python.org/projects/sandbox/trunk/bootstrap/bootstrap.py import bootstrap pypi = "http://pypi.python.org" dir = "packages/source/a/autoinstall" url = "%s/%s/autoinstall-%s.tar.gz" % (pypi, dir, _version) bootstrap.main((url,)) import autoinstall References:: http://0install.net/ http://www.python.org/dev/peps/pep-0302/ http://svn.python.org/projects/sandbox/trunk/import_in_py http://0install.net/injector-find.html http://roscidus.com/desktop/node/903 s0.2srestructuredtext eniÿÿÿÿNcCs.tdjotƒatiitƒntS(N(t _importertNonetImportertsyst meta_pathtappend(((sN/usr/local/google/WebKitToT/WebKit/WebKitTools/Scripts/webkitpy/autoinstall.pyt _getImporter s  cCstƒi|||ƒdS(sbind a top level package name to a URL. The package name should be a package name and the url should be a url to something that can be imported using the zipimporter. Optional zip_subpath parameter allows searching for modules below the root level of the zip file. N(Rtbind(t package_nameturlt zip_subpath((sN/usr/local/google/WebKitToT/WebKit/WebKitTools/Scripts/webkitpy/autoinstall.pyR§s tCachecBs&eZdd„Zd„Zd„ZRS(cCsž|pd|_yBtii|iƒp(tid|iƒti|iƒnWn1tj o%}ti|ƒt i ƒ|_ nXti d|iƒdS(Ns./autoinstall.cache.d/sCreating cache directory '%s'.sUsing cache directory '%s'.( t directorytostpathtexistst_loggertdebugtmkdirt Exceptiont exceptionttempfiletmkdtemptcache_directrytinfo(tselfR terr((sN/usr/local/google/WebKitToT/WebKit/WebKitTools/Scripts/webkitpy/autoinstall.pyt__init__µs cCsåtid|ƒ|idƒd}tii|idt|ƒƒ}tii|ƒpti |ƒntii||ƒ}tii|ƒoti d|ƒn;ti d|ƒt |dƒ}|i ||ƒ|i ƒ|S(NsGetting '%s' from cache.t/iÿÿÿÿs%ss ... already cached in file '%s'.s"... not in cache. Caching in '%s'.twb(RRtrsplitR RtjoinR thashRRRtfiletdownloadtclose(RR tfilenametdtstream((sN/usr/local/google/WebKitToT/WebKit/WebKitTools/Scripts/webkitpy/autoinstall.pytgetÀs" c Cstid|ƒykti|ƒ}d}t|dƒo|iƒ}nd|jo djnptd|ƒ‚nWn"tj o}ti|ƒnXd }d}xDt o<|i |ƒ}|pPn|i |ƒ|t |ƒ7}q°W|i ƒtid |ƒdS( NsDownloading: %siÈtgetcodei,sHTTP Error code %sii isDownloaded %d bytes.i (RRturllibturlopenthasattrR(t ValueErrorRRtTruetreadtwritetlenR#( RR R&t netstreamtcodeRtBUFSIZEtsizetdata((sN/usr/local/google/WebKitToT/WebKit/WebKitTools/Scripts/webkitpy/autoinstall.pyR"Ôs*  N(t__name__t __module__RRR'R"(((sN/usr/local/google/WebKitToT/WebKit/WebKitTools/Scripts/webkitpy/autoinstall.pyR ³s RcBs\eZd„Zd„ZeeƒZd„Zd„ZeeeƒZdd„Z d„Z RS(cCsh|_d|_dS(N(tpackagesRt_Importer__cache(R((sN/usr/local/google/WebKitToT/WebKit/WebKitTools/Scripts/webkitpy/autoinstall.pyRîs cCs|iS(N(t_Importer__store(R((sN/usr/local/google/WebKitToT/WebKit/WebKitTools/Scripts/webkitpy/autoinstall.pyt __get_storeòscCs'|idjotƒ|_n|iS(N(R9RR (R((sN/usr/local/google/WebKitToT/WebKit/WebKitTools/Scripts/webkitpy/autoinstall.pyt _get_cacheöscCs ||_dS(N(R9(Rtcache((sN/usr/local/google/WebKitToT/WebKit/WebKitTools/Scripts/webkitpy/autoinstall.pyt _set_cacheúsc Csàtid||fƒ||ijoµ|i|\}}|ii|ƒ}|od||fn|}tid||||fƒy$ti|ƒ}tid|ƒWn&tj o}ti|ƒdSnX|SndS(sm-> self or None. Search for a module specified by 'fullname'. 'fullname' must be the fully qualified (dotted) module name. It returns the zipimporter instance itself if the module was found, or None if it wasn't. The optional 'path' argument is ignored -- it's there for compatibility with the importer protocol."); sfind_module(%s, path=%s)s%s/%ss*fullname: %s url: %s path: %s zip_path: %ss returning: %sN( RRR8R=R't zipimportt zipimporterRRR( RtfullnameRR R R$tzip_pathtloaderte((sN/usr/local/google/WebKitToT/WebKit/WebKitTools/Scripts/webkitpy/autoinstall.pyt find_moduleþs   cCs1tid|||fƒ||f|i| %s subpath: %s(RRR8(RRR R ((sN/usr/local/google/WebKitToT/WebKit/WebKitTools/Scripts/webkitpy/autoinstall.pyRsN( R6R7Rt_Importer__get_storetpropertytstoreR<R>R=RRER(((sN/usr/local/google/WebKitToT/WebKit/WebKitTools/Scripts/webkitpy/autoinstall.pyRìs      t__main__s(%(name)-12s: %(levelname)-8s %(message)stpymarcsAhttp://pypi.python.org/packages/2.5/p/pymarc/pymarc-2.1-py2.5.eggs2.1s&'%s' not found in pymarc.__file__ (%s)($t__doc__t __version__t __docformat__R tnewRR)tloggingRR?t getLoggerR6RRRRRtobjectR Rtloggert StreamHandlertconsoletsetLeveltDEBUGt Formattert formattert setFormattert addHandlertINFORJt__file__tAssertionErrorR=R R%(((sN/usr/local/google/WebKitToT/WebKit/WebKitTools/Scripts/webkitpy/autoinstall.pysŽs<         90