def _load_old_formats(self): data = None filepath = os.path.join(self.path, "release.yaml") if os.path.isfile(filepath): # rez<2.0.BETA.16 data = load_from_file(filepath, FileFormat.yaml, update_data_callback=self._update_changelog) else: path_ = os.path.join(self.path, ".metadata") if os.path.isdir(path_): # rez-1 data = {} filepath = os.path.join(path_, "changelog.txt") if os.path.isfile(filepath): data["changelog"] = load_from_file( filepath, FileFormat.txt, update_data_callback=self._update_changelog) filepath = os.path.join(path_, "release_time.txt") if os.path.isfile(filepath): value = load_from_file(filepath, FileFormat.txt) try: data["timestamp"] = int(value.strip()) except: pass return data
def from_path(cls, path): """Load a developer package. A developer package may for example be a package.yaml or package.py in a user's source directory. Args: path: Directory containing the package definition file. Returns: `Package` object. """ name = None data = None for name_ in config.plugins.package_repository.filesystem.package_filenames: for format_ in (FileFormat.py, FileFormat.yaml): filepath = os.path.join(path, "%s.%s" % (name_, format_.extension)) if os.path.isfile(filepath): data = load_from_file(filepath, format_) break if data: name = data.get("name") if name is not None or isinstance(name, basestring): break if data is None: raise PackageMetadataError("No package definition file found at %s" % path) if name is None or not isinstance(name, basestring): raise PackageMetadataError( "Error in %r - missing or non-string field 'name'" % filepath) package = create_package(name, data, package_cls=cls) # preprocessing result = package._get_preprocessed(data) if result: package, data = result package.filepath = filepath # find all includes, this is needed at install time to copy the right # py sourcefiles into the package installation package.includes = set() def visit(d): for k, v in d.iteritems(): if isinstance(v, SourceCode): package.includes |= (v.includes or set()) elif isinstance(v, dict): visit(v) visit(data) package._validate_includes() return package
def _load(self): format_ = FileFormat[self.ext] data = load_from_file( self.filepath, format_, disable_memcache=self._repository.disable_memcache ) check_format_version(self.filepath, data) return data
def _load(self): if self.filepath is None: raise PackageDefinitionFileMissing( "Missing package definition file: %r" % self) data = load_from_file(self.filepath, self.file_format) if "timestamp" not in data: # old format support data_ = self._load_old_formats() if data_: data.update(data_) return data
def get_developer_package(path): """Load a developer package. A developer package may for example be a package.yaml or package.py in a user's source directory. Note: The resulting package has a 'filepath' attribute added to it, that does not normally appear on a `Package` object. A developer package is the only case where we know we can directly associate a 'package.*' file with a package - other packages can come from any kind of package repo, which may or may not associate a single file with a single package (or any file for that matter - it may come from a database). Args: path: Directory containing the package definition file. Returns: `Package` object. """ name = data = None for name_ in config.plugins.package_repository.filesystem.package_filenames: for format_ in (FileFormat.py, FileFormat.yaml): filepath = os.path.join(path, "%s.%s" % (name_, format_.extension)) if os.path.isfile(filepath): data = load_from_file(filepath, format_) break if data: name = data.get("name") if name is not None or isinstance(name, basestring): break if data is None: raise PackageMetadataError("No package definition file found at %s" % path) if name is None or not isinstance(name, basestring): raise PackageMetadataError( "Error in %r - missing or non-string field 'name'" % filepath) package = create_package(name, data) setattr(package, "filepath", filepath) return package
def _load(self): if self.filepath is None: raise PackageDefinitionFileMissing( "Missing package definition file: %r" % self) data = load_from_file( self.filepath, self.file_format, disable_memcache=self._repository.disable_memcache ) check_format_version(self.filepath, data) if "timestamp" not in data: # old format support data_ = self._load_old_formats() if data_: data.update(data_) return data
def from_path(cls, path, format=None): """Load a developer package. A developer package may for example be a package.yaml or package.py in a user's source directory. Args: path: Directory containing the package definition file, or file path for the package file itself format: which FileFormat to use, or None to check both .py and .yaml Returns: `Package` object. """ name = None data = None if format is None: formats = (FileFormat.py, FileFormat.yaml) else: formats = (format, ) try: mode = os.stat(path).st_mode except (IOError, OSError): raise PackageMetadataError( "Path %r did not exist, or was not accessible" % path) is_dir = stat.S_ISDIR(mode) for name_ in config.plugins.package_repository.filesystem.package_filenames: for format_ in formats: if is_dir: filepath = os.path.join( path, "%s.%s" % (name_, format_.extension)) exists = os.path.isfile(filepath) else: # if format was not specified, verify that it has the # right extension before trying to load if format is None: if os.path.splitext(path)[1] != format_.extension: continue filepath = path exists = True if exists: data = load_from_file(filepath, format_, disable_memcache=True) break if data: name = data.get("name") if name is not None or isinstance(name, basestring): break if data is None: raise PackageMetadataError( "No package definition file found at %s" % path) if name is None or not isinstance(name, basestring): raise PackageMetadataError( "Error in %r - missing or non-string field 'name'" % filepath) package = create_package(name, data, package_cls=cls) # set filepath in case preprocessor needs to do something on disk (eg # check the git repo) package.filepath = filepath # preprocessing result = package._get_preprocessed(data) if result: package, data = result # set filepath back in case preprocessor changed it package.filepath = filepath # find all includes, this is needed at install time to copy the right # py sourcefiles into the package installation package.includes = set() def visit(d): for k, v in d.items(): if isinstance(v, SourceCode): package.includes |= (v.includes or set()) elif isinstance(v, dict): visit(v) visit(data) package._validate_includes() return package
def from_path(cls, path): """Load a developer package. A developer package may for example be a package.yaml or package.py in a user's source directory. Args: path: Directory containing the package definition file. Returns: `Package` object. """ name = None data = None for name_ in config.plugins.package_repository.filesystem.package_filenames: for format_ in (FileFormat.py, FileFormat.yaml): filepath = os.path.join(path, "%s.%s" % (name_, format_.extension)) if os.path.isfile(filepath): data = load_from_file(filepath, format_) break if data: name = data.get("name") if name is not None or isinstance(name, basestring): break if data is None: raise PackageMetadataError( "No package definition file found at %s" % path) if name is None or not isinstance(name, basestring): raise PackageMetadataError( "Error in %r - missing or non-string field 'name'" % filepath) package = create_package(name, data, package_cls=cls) # preprocessing result = package._get_preprocessed(data) if result: package, data = result package.filepath = filepath # find all includes, this is needed at install time to copy the right # py sourcefiles into the package installation package.includes = set() def visit(d): for k, v in d.iteritems(): if isinstance(v, SourceCode): package.includes |= (v.includes or set()) elif isinstance(v, dict): visit(v) visit(data) package._validate_includes() return package
def _load(self): format_ = FileFormat[self.ext] data = load_from_file(self.filepath, format_) check_format_version(self.filepath, data) return data
def from_path(cls, path, format=None): """Load a developer package. A developer package may for example be a package.yaml or package.py in a user's source directory. Args: path: Directory containing the package definition file, or file path for the package file itself format: which FileFormat to use, or None to check both .py and .yaml Returns: `Package` object. """ name = None data = None if format is None: formats = (FileFormat.py, FileFormat.yaml) else: formats = (format,) try: mode = os.stat(path).st_mode except (IOError, OSError): raise PackageMetadataError( "Path %r did not exist, or was not accessible" % path) is_dir = stat.S_ISDIR(mode) for name_ in config.plugins.package_repository.filesystem.package_filenames: for format_ in formats: if is_dir: filepath = os.path.join(path, "%s.%s" % (name_, format_.extension)) exists = os.path.isfile(filepath) else: # if format was not specified, verify that it has the # right extension before trying to load if format is None: if os.path.splitext(path)[1] != format_.extension: continue filepath = path exists = True if exists: data = load_from_file(filepath, format_, disable_memcache=True) break if data: name = data.get("name") if name is not None or isinstance(name, basestring): break if data is None: raise PackageMetadataError("No package definition file found at %s" % path) if name is None or not isinstance(name, basestring): raise PackageMetadataError( "Error in %r - missing or non-string field 'name'" % filepath) package = create_package(name, data, package_cls=cls) # preprocessing result = package._get_preprocessed(data) if result: package, data = result package.filepath = filepath # find all includes, this is needed at install time to copy the right # py sourcefiles into the package installation package.includes = set() def visit(d): for k, v in d.iteritems(): if isinstance(v, SourceCode): package.includes |= (v.includes or set()) elif isinstance(v, dict): visit(v) visit(data) package._validate_includes() return package
def _load(self): format_ = FileFormat[self.ext] data = load_from_file(self.filepath, format_) return data