def deprecated_file_path(self, deprecated_spec, deprecator_spec=None): """Gets full path to spec file for deprecated spec If the deprecator_spec is provided, use that. Otherwise, assume deprecated_spec is already deprecated and its prefix links to the prefix of its deprecator.""" _check_concrete(deprecated_spec) if deprecator_spec: _check_concrete(deprecator_spec) # If deprecator spec is None, assume deprecated_spec already deprecated # and use its link to find the file. base_dir = self.path_for_spec( deprecator_spec ) if deprecator_spec else os.readlink(deprecated_spec.prefix) yaml_path = os.path.join(base_dir, self.metadata_dir, self.deprecated_dir, deprecated_spec.dag_hash() + '_' + self._spec_file_name_yaml) json_path = os.path.join(base_dir, self.metadata_dir, self.deprecated_dir, deprecated_spec.dag_hash() + '_' + self.spec_file_name) if (os.path.exists(yaml_path) and fs.can_write_to_dir(yaml_path)): self.write_spec(deprecated_spec, json_path) try: os.remove(yaml_path) except (IOError, OSError) as err: tty.debug('Could not remove deprecated {0}'.format(yaml_path)) tty.debug(err) elif os.path.exists(yaml_path): return yaml_path return json_path
def spec_file_path(self, spec): """Gets full path to spec file""" _check_concrete(spec) # Attempts to convert to JSON if possible. # Otherwise just returns the YAML. yaml_path = os.path.join( self.metadata_path(spec), self._spec_file_name_yaml) json_path = os.path.join(self.metadata_path(spec), self.spec_file_name) if os.path.exists(yaml_path) and fs.can_write_to_dir(yaml_path): self.write_spec(spec, json_path) try: os.remove(yaml_path) except OSError as err: tty.debug('Could not remove deprecated {0}'.format(yaml_path)) tty.debug(err) elif os.path.exists(yaml_path): return yaml_path return json_path
def _can_revert_update(scope_dir, cfg_file, bkp_file): dir_ok = fs.can_write_to_dir(scope_dir) cfg_ok = not os.path.exists(cfg_file) or fs.can_access(cfg_file) bkp_ok = fs.can_access(bkp_file) return dir_ok and cfg_ok and bkp_ok
def _can_update_config_file(scope_dir, cfg_file): dir_ok = fs.can_write_to_dir(scope_dir) cfg_ok = fs.can_access(cfg_file) return dir_ok and cfg_ok