def get (self, pkginst, show_progress = False): """Copy `pkginst` file from remote depot to local depot. :Parameters: `pkginst`: string Path to remote pkginst file relative to remote repository. `show_progress`: boolean True if a `TextProgressMeter` should be used as `pkginst` is downloaded. :Attributes: `verify_checksum`: boolean If True, then a checksum file is also fetched as part of the same file group (sharing the same `progressmeter`). """ fetched_bytes = 0 if show_progress: progressmeter = TextProgressMeter (self.indent_progressmeter) else: progressmeter = None # fetch a copy of the remote file mysig.register (os.remove, os.path.join (self.local_path, pkginst)) try: fetched_bytes = self.fetch (pkginst, progressmeter, 0, CHECKSUM_FILESIZE) except depot.DepotError, msg: mysig.unregister (os.remove) raise
def set (self, depot_names, options = []): valid_depots = [] # depots we can use search_depots = False search_package_names = [] # packages to search for # make copy as invalid_package_callback might modify in place for package_name in self.package_names[:]: if not package_name.isfile (): # Unless we already have a local file, try to fetch the file from # (remote) url into a temporary local depot for processing later on. try: self.temp_package_dir = misclib.mkstempdir () except misclib.MisclibTempDirCreationError, msg: raise DepotTempdirCreationError (src (msg)) mysig.register (self.remove_temp_package_dir) dep = init (None, self.temp_package_dir, package_name.remote_depot ()) dep.indent_progressmeter = 2 dep.verify_checksum = False self.depot_init (dep) if dep.exists (package_name.remote_path ()): # mysig.register() call above avoids a race if the program # exits with a signal, and the atexit.register() call below # ensures we also clean up when the program exits normally. atexit.register (self.remove_temp_package_dir, self.msg_callback) # To minimize chatter, only admit that we created a temporary # directory if we actually need it... self.msg_callback ('begin', 'creating temporary \ directory', 0, VERBOSE_LOCAL_DEPOT) self.msg_callback ('end', self.temp_package_dir, 0, VERBOSE_LOCAL_DEPOT) io.stdout (0, '', 'retrieving ' + package_name.geturl () + ' ...\n') elif package_name.getscheme () != 'file': raise DepotFileNotFoundError ('%s: File not found.' % package_name.geturl ()) else: # ...otherwise, quietly remove it and pretend it was never # here (in which case we won't be needing the atexit handler # either): self.remove_temp_package_dir () self.assign_depot_vars (dep) # If we successfully fetched a local copy of the remote file, # replace the remote package_name object with a file:// scheme # package_name: pkgfile = package_name.basename () if dep.exists (pkgfile): dep.get (pkgfile, show_progress = True) package_name = \ PackageName (os.path.join (self.temp_package_dir, pkgfile)) if package_name.isfile (): path = package_name.normpath () dep = init (None, self.local_depot, os.path.dirname (path)) self.assign_depot_vars (dep) self.msg_callback ('begin', 'reading ' + urljoin (dep.pkg_url, os.path.basename (path)), 0, VERBOSE_DEPOT) try: archive = self.archive_init (path) if archive: archive.path = path # set depot path to the archive file dep.local_path = path dep.url = package_name.getscheme () + "://" + path dep.archive = archive if archive.exists (self.XML_FILE): db_entry = self.read_db_xml (archive, dep, self.XML_FILE) elif archive.exists (os.path.basename (path)): db_entry = self.read_db_xml (archive, dep, os.path.basename (path)) else: if self.invalid_package_callback: self.invalid_package_callback (package_name.name) self.msg_callback ('end', 'failed', 0, VERBOSE_DEPOT) self.msg_callback ('error', 'an input archive \ was specified but did not contain either a "%s" or "%s". Archives \ must contain one of these files. skipping.' % (self.XML_FILE, os.path.basename (path))) continue else: db_entry = self.read_db_xml (dep, dep, path) if not db_entry: self.msg_callback ('end', 'failed', 0, VERBOSE_DEPOT) self.msg_callback ('error', 'unable to parse the \ XML file. please check "%s". it does not appear to follow \ %s(4). skipping.' % (path, self.XML_FILE)) continue except DepotArchiveInitError, msg: if self.invalid_package_callback: self.invalid_package_callback (package_name.name) self.msg_callback ('end', 'failed', 0, VERBOSE_DEPOT) self.msg_callback ('error', str (msg)) continue except XMLError, msg: self.msg_callback ('end', 'failed', 0, VERBOSE_DEPOT) self.msg_callback ('error', str (msg)) continue
# initialize depots if search_depots and depot_names: for depot_name in depot_names: # create temp directory for local depot if is_remote (depot_name) and not self.local_depot: self.msg_callback ('begin', 'creating temporary \ local depot directory', 0, VERBOSE_LOCAL_DEPOT) try: self.local_depot = misclib.mkstempdir (self.tmpbasedir) self.local_depot_is_temporary = True except misclib.MisclibTempdirCreationError, msg: raise DepotNoLocalDepot (str (msg)) mysig.register (self.remove_local_depot, None) self.msg_callback ('end', self.local_depot, 0, VERBOSE_LOCAL_DEPOT) try: dep = init (self.var, self.local_depot, depot_name) except DepotProtocolUnsupportedError, msg: self.msg_callback ('end', 'failed', 0, VERBOSE_DEPOT) self.msg_callback ('error', str (msg) + ' removing ' + depot_name + ' from list of depots.') continue if dep.is_remote () and not self.local_depot: raise DepotNoLocalDepot ('remote depots were specified but a \ --local-depot option was not given. please rerun specifying a local \ path where packages from remote repositories can be copied to.')
else: progressmeter = None # fetch a copy of the remote file mysig.register (os.remove, os.path.join (self.local_path, pkginst)) try: fetched_bytes = self.fetch (pkginst, progressmeter, 0, CHECKSUM_FILESIZE) except depot.DepotError, msg: mysig.unregister (os.remove) raise if self.verify_checksum: # fetch the associated checksum file pkginst += '.md5' mysig.register (os.remove, os.path.join (self.local_path, pkginst)) try: self.fetch (pkginst, progressmeter, fetched_bytes, 0) except depot.DepotError: mysig.unregister (os.remove) mysig.unregister (os.remove) raise mysig.unregister (os.remove) mysig.unregister (os.remove) if show_progress: progressmeter.end () def is_remote (self): """Return True if a depot with this transport is on a remote server."""