def tempdir(): # This seems like it was only added in python 3.2 # Make it since its useful... tdir = tempfile.mkdtemp() try: yield tdir finally: sh.deldir(tdir)
def tempdir(): # This seems like it was only added in python 3.2 # Make it since its useful... # See: http://bugs.python.org/file12970/tempdir.patch tdir = tempfile.mkdtemp() try: yield tdir finally: sh.deldir(tdir)
def _uninstall_dirs(self): dirsmade = self.tracereader.dirs_made() if dirsmade: dirsmade = [sh.abspth(d) for d in dirsmade] if self.keep_old: places = set() for (pth_loc, _) in self.tracereader.download_locations(): places.add(pth_loc) LOG.info("Keeping %s download directories [%s]", len(places), ",".join(sorted(places))) for download_place in places: dirsmade = sh.remove_parents(download_place, dirsmade) for dirname in dirsmade: LOG.info("Removing created directory (%s)", dirname) sh.deldir(dirname, run_as_root=True)
def _config_adjust_api(self, contents, fn): with io.BytesIO(contents) as stream: config = cfg.IgnoreMissingConfigParser() config.readfp(stream) img_store_dir = self._get_image_dir() config.set('DEFAULT', 'debug', True) config.set('DEFAULT', 'verbose', True) config.set('DEFAULT', 'default_store', 'file') config.set('DEFAULT', 'filesystem_store_datadir', img_store_dir) config.remove_option('DEFAULT', 'log_file') config.set('paste_deploy', 'flavor', 'keystone') LOG.info("Ensuring file system store directory %r exists and is empty." % (img_store_dir)) sh.deldir(img_store_dir) self.tracewriter.dirs_made(*sh.mkdirslist(img_store_dir)) return config.stringify(fn)
def _uninstall_dirs(self): dirs_made = self.tracereader.dirs_made() if dirs_made: dirs_made = [sh.abspth(d) for d in dirs_made] if self.keep_old: download_places = [path_location[0] for path_location in self.tracereader.download_locations()] if download_places: utils.log_iterable(download_places, logger=LOG, header="Keeping %s download directories (and there children directories)" % (len(download_places))) for download_place in download_places: dirs_made = sh.remove_parents(download_place, dirs_made) if dirs_made: utils.log_iterable(dirs_made, logger=LOG, header="Removing %s created directories" % (len(dirs_made))) for dir_name in dirs_made: sh.deldir(dir_name, run_as_root=True)
def _uninstall_dirs(self): dirsmade = self.tracereader.dirs_made() if dirsmade: dirsmade = [sh.abspth(d) for d in dirsmade] if self.keep_old: downloads = (self.tracereader.downloaded()) places = set() for info in downloads: download_place = info.get('target') if download_place: places.add(download_place) LOG.info("Keeping %s download directories [%s]" % (len(places), ",".join(sorted(places)))) for download_place in places: dirsmade = sh.remove_parents(download_place, dirsmade) for dirname in dirsmade: LOG.info("Removing created directory (%s)" % (dirname)) sh.deldir(dirname, run_as_root=True)
def _config_adjust_api(self, contents, fn): with io.BytesIO(contents) as stream: config = cfg.IgnoreMissingConfigParser() config.readfp(stream) img_store_dir = self._get_image_dir() config.set('DEFAULT', 'debug', True) config.set('DEFAULT', 'verbose', True) config.set('DEFAULT', 'default_store', 'file') config.set('DEFAULT', 'filesystem_store_datadir', img_store_dir) config.remove_option('DEFAULT', 'log_file') config.set('paste_deploy', 'flavor', 'keystone') LOG.info( "Ensuring file system store directory %r exists and is empty." % (img_store_dir)) sh.deldir(img_store_dir) self.tracewriter.dirs_made(*sh.mkdirslist(img_store_dir)) return config.stringify(fn)
def _config_adjust(self, contents, name): # Even bother opening?? if name not in READ_CONFIGS: return contents # Use config parser and # then extract known configs that # will need locations/directories/files made (or touched)... with io.BytesIO(contents) as stream: config = cfg.IgnoreMissingConfigParser() config.readfp(stream) if config.getboolean('default', 'image_cache_enabled'): cache_dir = config.get('default', "image_cache_datadir") if cache_dir: LOG.info("Ensuring image cache data directory %s exists "\ "(and is empty)" % (cache_dir)) # Destroy then recreate the image cache directory sh.deldir(cache_dir) self.tracewriter.dirs_made(*sh.mkdirslist(cache_dir)) if config.get('default', 'default_store') == 'file': file_dir = config.get('default', 'filesystem_store_datadir') if file_dir: LOG.info( "Ensuring file system store directory %s exists and is empty." % (file_dir)) # Delete existing images # and recreate the image directory sh.deldir(file_dir) self.tracewriter.dirs_made(*sh.mkdirslist(file_dir)) log_filename = config.get('default', 'log_file') if log_filename: LOG.info("Ensuring log file %s exists and is empty." % (log_filename)) log_dir = sh.dirname(log_filename) if log_dir: LOG.info("Ensuring log directory %s exists." % (log_dir)) self.tracewriter.dirs_made(*sh.mkdirslist(log_dir)) # Destroy then recreate it (the log file) sh.unlink(log_filename) self.tracewriter.file_touched(sh.touch_file(log_filename)) if config.getboolean('default', 'delayed_delete'): data_dir = config.get('default', 'scrubber_datadir') if data_dir: LOG.info( "Ensuring scrubber data dir %s exists and is empty." % (data_dir)) # Destroy then recreate the scrubber data directory sh.deldir(data_dir) self.tracewriter.dirs_made(*sh.mkdirslist(data_dir)) # Nothing modified so just return the original return contents
def _config_adjust(self, contents, name): #even bother opening?? if name not in READ_CONFIGS: return contents #use config parser and #then extract known configs that #will need locations/directories/files made (or touched)... with io.BytesIO(contents) as stream: config = cfg.IgnoreMissingConfigParser() config.readfp(stream) if config.getboolean('default', 'image_cache_enabled'): cache_dir = config.get('default', "image_cache_datadir") if cache_dir: LOG.info("Ensuring image cache data directory %s exists "\ "(and is empty)" % (cache_dir)) #destroy then recreate the image cache directory sh.deldir(cache_dir) self.tracewriter.make_dir(cache_dir) if config.get('default', 'default_store') == 'file': file_dir = config.get('default', 'filesystem_store_datadir') if file_dir: LOG.info("Ensuring file system store directory %s exists and is empty." % (file_dir)) #delete existing images #and recreate the image directory sh.deldir(file_dir) self.tracewriter.make_dir(file_dir) log_filename = config.get('default', 'log_file') if log_filename: LOG.info("Ensuring log file %s exists and is empty." % (log_filename)) log_dir = sh.dirname(log_filename) if log_dir: LOG.info("Ensuring log directory %s exists." % (log_dir)) self.tracewriter.make_dir(log_dir) #destroy then recreate it (the log file) sh.unlink(log_filename) sh.touch_file(log_filename) self.tracewriter.file_touched(log_filename) if config.getboolean('default', 'delayed_delete'): data_dir = config.get('default', 'scrubber_datadir') if data_dir: LOG.info("Ensuring scrubber data dir %s exists and is empty." % (data_dir)) #destroy then recreate the scrubber data directory sh.deldir(data_dir) self.tracewriter.make_dir(data_dir) #we might need to handle more in the future... #nothing modified so just return the original return contents
def _uninstall_dirs(self): dirsmade = self.tracereader.dirs_made() if dirsmade: LOG.info("Removing %s created directories (%s)" % (len(dirsmade), ", ".join(dirsmade))) for dirname in dirsmade: sh.deldir(dirname)
def _cleanup(self): if self.tmp_folder: shell.deldir(self.tmp_folder) shell.unlink(self.download_file_name)