def get_packages(self): pkgs = [] for (name, fields) in self.config.iteritems(): for (k, v) in fields.iteritems(): if k == 'packages': if type(v) is list: pkgs = pkgs + list(onlu.sflatten(v)) else: pkgs = pkgs + v.split() return pkgs
def get_packages(self): pkgs = [] for (name, fields) in self.config.iteritems(): for (k,v) in fields.iteritems(): if k == 'packages': if type(v) is list: pkgs = pkgs + list(onlu.sflatten(v)) else: pkgs = pkgs + v.split() return pkgs
def generate_handle(self, handle): for (name, fields) in self.config.iteritems(): handle.write("[%s]\n" % name) for (k,v) in fields.iteritems(): if type(v) is bool: v = 'true' if v == True else 'false' if type(v) is list: v = " ".join(onlu.sflatten(v)) if k == 'source' and os.path.exists(v): self.localrepos.append(v) v = "copy:%s ./" % v if k == 'packages' and type(v) is list: raise OnlRfsError("packages=%s" % v) handle.write("%s=%s\n" % (k, v)) handle.write("\n")
def generate_handle(self, handle): for (name, fields) in self.config.iteritems(): handle.write("[%s]\n" % name) for (k, v) in fields.iteritems(): if type(v) is bool: v = 'true' if v == True else 'false' if type(v) is list: v = " ".join(onlu.sflatten(v)) if k == 'source' and os.path.exists(v): self.localrepos.append(v) v = "copy:%s ./" % v if k == 'packages' and type(v) is list: raise OnlRfsError("packages=%s" % v) handle.write("%s=%s\n" % (k, v)) handle.write("\n")
def prerequisite_packages(self): return list(onlu.sflatten(self._pkgs.get("prerequisites", {}).get("packages", [])))
def build(self, dir_=None): """Build the debian package. When this method is called it is assumed that all file prerequisites for the package have already been built or met. This is simply the packaging stage. 'dir_' : This is the output directory in which the package should be left. If unspecified the package's local directory will contain the package file.""" if "external" in self.pkg: # Package file built externally epkg = self.pkg["external"] if os.path.exists(epkg): return epkg else: raise OnlPackageError("The external package file '%s' does not exist." % epkg) # Make sure all required files exist if "files" in self.pkg: self._validate_files() # If dir_ is not specified, leave package in local package directory. if dir_ is None: dir_ = self.dir workdir = tempfile.mkdtemp() root = os.path.join(workdir, "root") os.mkdir(root) # The package file will be built into the workdir self.pkg["__workdir"] = workdir for (src, dst) in self.pkg.get("files", {}): OnlPackage.copyf(src, dst, root) for (link, src) in self.pkg.get("links", {}).iteritems(): logger.info("Linking %s -> %s..." % (link, src)) link = os.path.join(root, link) os.symlink(src, link) # # FPM doesn't seem to have a doc option so we copy documentation # files directly into place. # docpath = os.path.join(root, "usr/share/doc/%(name)s" % self.pkg) if not os.path.exists(docpath): os.makedirs(docpath) for src in self.pkg.get("docs", []): if not os.path.exists(src): raise OnlPackageError("Documentation source file '%s' does not exist." % src) shutil.copy(src, docpath) changelog = os.path.join(workdir, "changelog") copyright_ = os.path.join(workdir, "copyright") # # Export changelog and copyright files from the PKG dict # to the workdir for processing. # # The copyright and changelog data can be embedded directly # int the PKG file or kept as separate files. # def copy_str_or_file(src, dst): if os.path.exists(src): shutil.copyfile(src, dst) else: with open(dst, "w") as f: f.write(src) f.write("\n") copy_str_or_file(self.pkg["copyright"], copyright_) copy_str_or_file(self.pkg["changelog"], changelog) ############################################################ # # Invoke fpm with all necessary options. # ############################################################ self.pkg["__root"] = root command = ( """fpm -p %(__workdir)s -f -C %(__root)s -s dir -t deb -n %(name)s -v %(version)s -a %(arch)s -m %(maintainer)s --description "%(description)s" --url "%(url)s" --license "%(license)s" --vendor "%(vendor)s" """ % self.pkg ) for dep in self.pkg.get("depends", []): command = command + "-d %s " % dep for provides in onlu.sflatten(self.pkg.get("provides", [])): command = command + "--provides %s " % provides for conflicts in onlu.sflatten(self.pkg.get("conflicts", [])): command = command + "--conflicts %s " % conflicts for replaces in onlu.sflatten(self.pkg.get("replaces", [])): command = command + "--replaces %s " % replaces if "virtual" in self.pkg: command = command + "--provides %(v)s --conflicts %(v)s --replaces %(v)s " % dict(v=self.pkg["virtual"]) if "priority" in self.pkg: command = command + "--deb-priority %s " % self.pkg["priority"] if "init" in self.pkg: if not os.path.exists(self.pkg["init"]): raise OnlPackageError("Init script '%s' does not exist." % self.pkg["init"]) command = command + "--deb-init %s " % self.pkg["init"] if self.pkg.get("init-after-install", True): command = ( command + "--after-install %s " % OnlPackageAfterInstallScript(self.pkg["init"], dir=workdir).name ) if self.pkg.get("init-before-remove", True): command = ( command + "--before-remove %s " % OnlPackageBeforeRemoveScript(self.pkg["init"], dir=workdir).name ) if self.pkg.get("init-after-remove", True): command = ( command + "--after-remove %s " % OnlPackageAfterRemoveScript(self.pkg["init"], dir=workdir).name ) if self.pkg.get("asr", True): # Generate the ASR documentation for this package. sys.path.append("%s/sm/infra/tools" % os.getenv("ONL")) import asr asro = asr.AimSyslogReference() asro.extract(workdir) asro.format(os.path.join(docpath, asr.AimSyslogReference.ASR_NAME), "json") ############################################################ if logger.level < logging.INFO: command = command + "--verbose " onlu.execute(command) # Grab the package from the workdir. There can be only one. files = glob.glob(os.path.join(workdir, "*.deb")) if len(files) == 0: raise OnlPackageError("No debian package.") elif len(files) > 1: raise OnlPackageError("Too many packages.") else: # Move to the target directory shutil.copy(files[0], dir_) # Remove entire work directory. shutil.rmtree(workdir) # Return the path to the final built package return os.path.join(dir_, os.path.basename(files[0]))
def prerequisite_packages(self): rv = [] for e in list(onlu.sflatten(self._pkgs.get('prerequisites', {}).get('packages', []))): rv += e.split(',') return rv
def build(self, dir_=None): """Build the debian package. When this method is called it is assumed that all file prerequisites for the package have already been built or met. This is simply the packaging stage. 'dir_' : This is the output directory in which the package should be left. If unspecified the package's local directory will contain the package file.""" if 'external' in self.pkg: # Package file built externally epkg = self.pkg['external'] if os.path.exists(epkg): return epkg else: raise OnlPackageError("The external package file '%s' does not exist." % epkg); # Make sure all required files exist if 'files' in self.pkg: self._validate_files() # If dir_ is not specified, leave package in local package directory. if dir_ is None: dir_ = self.dir workdir = tempfile.mkdtemp() root = os.path.join(workdir, "root"); os.mkdir(root); # The package file will be built into the workdir self.pkg['__workdir'] = workdir for (src,dst) in self.pkg.get('files', {}): if dst.startswith('/'): dst = dst[1:] if os.path.isdir(src): # # Copy entire src directory to target directory # dstpath = os.path.join(root, dst) logger.debug("Copytree %s -> %s" % (src, dstpath)) shutil.copytree(src, dstpath) else: # # If the destination ends in a '/' it means copy the filename # as-is to that directory. # # If not, its a full rename to the destination. # if dst.endswith('/'): dstpath = os.path.join(root, dst) if not os.path.exists(dstpath): os.makedirs(dstpath) shutil.copy(src, dstpath) else: dstpath = os.path.join(root, os.path.dirname(dst)) if not os.path.exists(dstpath): os.makedirs(dstpath) shutil.copyfile(src, os.path.join(root, dst)) shutil.copymode(src, os.path.join(root, dst)) for (link,src) in self.pkg.get('links', {}).iteritems(): logger.info("Linking %s -> %s..." % (link, src)) link = os.path.join(root, link) os.symlink(src, link) # # FPM doesn't seem to have a doc option so we copy documentation # files directly into place. # for src in self.pkg.get('docs', []): if not os.path.exists(src): raise OnlPackageError("Documentation source file '%s' does not exist." % src) dstpath = os.path.join(root, "usr/share/doc/%(name)s" % self.pkg) if not os.path.exists(dstpath): os.makedirs(dstpath) shutil.copy(src, dstpath) changelog = os.path.join(workdir, 'changelog') copyright_ = os.path.join(workdir, 'copyright') # # Export changelog and copyright files from the PKG dict # to the workdir for processing. # # The copyright and changelog data can be embedded directly # int the PKG file or kept as separate files. # def copy_str_or_file(src, dst): if os.path.exists(src): shutil.copyfile(src, dst) else: with open(dst, "w") as f: f.write(src) f.write("\n") copy_str_or_file(self.pkg['copyright'], copyright_) copy_str_or_file(self.pkg['changelog'], changelog) ############################################################ # # Invoke fpm with all necessary options. # ############################################################ self.pkg['__root'] = root command = """fpm -p %(__workdir)s -f -C %(__root)s -s dir -t deb -n %(name)s -v %(version)s -a %(arch)s -m %(maintainer)s --description "%(description)s" --url "%(url)s" --license "%(license)s" --vendor "%(vendor)s" """ % self.pkg for dep in self.pkg.get('depends', []): command = command + "-d %s " % dep for provides in onlu.sflatten(self.pkg.get('provides', [])): command = command + "--provides %s " % provides if 'init' in self.pkg: if not os.path.exists(self.pkg['init']): raise OnlPackageError("Init script '%s' does not exist." % self.pkg['init']) command = command + "--deb-init %s" % self.pkg['init'] if 'post-install' in self.pkg: if not os.path.exists(self.pkg['post-install']): raise OnlPackageError("Post-install script '%s' does not exist." % self.pkg['post-install']) command = command + "--after-install %s" % self.pkg['post-install'] if logger.level < logging.INFO: command = command + "--verbose " onlu.execute(command) # Grab the package from the workdir. There can be only one. sys.stdout.write(workdir) files = glob.glob(os.path.join(workdir, '*.deb')) if len(files) == 0: raise OnlPackageError("No debian package.") elif len(files) > 1: raise OnlPackageError("Too many packages.") else: # Move to the target directory shutil.copy(files[0], dir_) # Remove entire work directory. shutil.rmtree(workdir) # Return the path to the final built package return os.path.join(dir_, os.path.basename(files[0]))
def build(self, dir_=None): """Build the debian package. When this method is called it is assumed that all file prerequisites for the package have already been built or met. This is simply the packaging stage. 'dir_' : This is the output directory in which the package should be left. If unspecified the package's local directory will contain the package file.""" if 'external' in self.pkg: # Package file built externally epkg = self.pkg['external'] if os.path.exists(epkg): return epkg else: raise OnlPackageError("The external package file '%s' does not exist." % epkg); # Make sure all required files exist if 'files' in self.pkg: self._validate_files('files', True) if 'optional-files' in self.pkg: self._validate_files('optional-files', False) # If dir_ is not specified, leave package in local package directory. if dir_ is None: dir_ = self.dir workdir = tempfile.mkdtemp() root = os.path.join(workdir, "root"); os.mkdir(root); # The package file will be built into the workdir self.pkg['__workdir'] = workdir for (src,dst) in self.pkg.get('files', {}): OnlPackage.copyf(src, dst, root) for (src,dst) in self.pkg.get('optional-files', {}): if os.path.exists(src): OnlPackage.copyf(src, dst, root) for (link,src) in self.pkg.get('links', {}).iteritems(): logger.info("Linking %s -> %s..." % (link, src)) link = os.path.join(root, link) os.symlink(src, link) # # FPM doesn't seem to have a doc option so we copy documentation # files directly into place. # docpath = os.path.join(root, "usr/share/doc/%(name)s" % self.pkg) if not os.path.exists(docpath): os.makedirs(docpath) for src in self.pkg.get('docs', []): if not os.path.exists(src): raise OnlPackageError("Documentation source file '%s' does not exist." % src) shutil.copy(src, docpath) changelog = os.path.join(workdir, 'changelog') copyright_ = os.path.join(workdir, 'copyright') # # Export changelog and copyright files from the PKG dict # to the workdir for processing. # # The copyright and changelog data can be embedded directly # int the PKG file or kept as separate files. # def copy_str_or_file(src, dst): if os.path.exists(src): shutil.copyfile(src, dst) else: with open(dst, "w") as f: f.write(src) f.write("\n") copy_str_or_file(self.pkg['copyright'], copyright_) copy_str_or_file(self.pkg['changelog'], changelog) ############################################################ # # Invoke fpm with all necessary options. # ############################################################ self.pkg['__root'] = root command = """fpm -p %(__workdir)s -f -C %(__root)s -s dir -t deb -n %(name)s -v %(version)s -a %(arch)s -m %(maintainer)s --description "%(description)s" --url "%(url)s" --license "%(license)s" --vendor "%(vendor)s" """ % self.pkg for dep in self.pkg.get('depends', []): command = command + "-d %s " % dep for provides in onlu.sflatten(self.pkg.get('provides', [])): command = command + "--provides %s " % provides for conflicts in onlu.sflatten(self.pkg.get('conflicts', [])): command = command + "--conflicts %s " % conflicts for replaces in onlu.sflatten(self.pkg.get('replaces', [])): command = command + "--replaces %s " % replaces if 'virtual' in self.pkg: command = command + "--provides %(v)s --conflicts %(v)s --replaces %(v)s " % dict(v=self.pkg['virtual']) if 'priority' in self.pkg: command = command + "--deb-priority %s " % self.pkg['priority'] if 'init' in self.pkg: if not os.path.exists(self.pkg['init']): raise OnlPackageError("Init script '%s' does not exist." % self.pkg['init']) command = command + "--deb-init %s " % self.pkg['init'] if self.pkg.get('init-after-install', True): command = command + "--after-install %s " % OnlPackageAfterInstallScript(self.pkg['init'], dir=workdir).name if self.pkg.get('init-before-remove', True): command = command + "--before-remove %s " % OnlPackageBeforeRemoveScript(self.pkg['init'], dir=workdir).name if self.pkg.get('init-after-remove', True): command = command + "--after-remove %s " % OnlPackageAfterRemoveScript(self.pkg['init'], dir=workdir).name if self.pkg.get('asr', False): with onlu.Profiler() as profiler: # Generate the ASR documentation for this package. sys.path.append("%s/sm/infra/tools" % os.getenv('ONL')) import asr asro = asr.AimSyslogReference() asro.extract(workdir) asro.format(os.path.join(docpath, asr.AimSyslogReference.ASR_NAME), 'json') profiler.log("ASR generation for %(name)s" % self.pkg) ############################################################ if logger.level < logging.INFO: command = command + "--verbose " onlu.execute(command) # Grab the package from the workdir. There can be only one. files = glob.glob(os.path.join(workdir, '*.deb')) if len(files) == 0: raise OnlPackageError("No debian package.") elif len(files) > 1: raise OnlPackageError("Too many packages.") else: # Move to the target directory shutil.copy(files[0], dir_) # Remove entire work directory. shutil.rmtree(workdir) # Return the path to the final built package return os.path.join(dir_, os.path.basename(files[0]))
nargs='+', default=[]) ap.add_argument("--without-vs", action='store_true', help='Skip adding VS') ops = ap.parse_args() if os.path.exists(ops.platforms): platforms = onlyaml.loadf(ops.platforms) else: platforms = ops.platforms.split(',') if not ops.without_vs: platforms.append('vs') # # The following ONL packages are needed for each platform: # # The platform-config package # The ONLP package # ONL_PATTERNS = ["goldstone-platform-config-%(platform)s"] PATTERNS = list(onlu.sflatten(ops.add_patterns)) if not ops.no_builtins: PATTERNS = ONL_PATTERNS + PATTERNS for p in platforms: for pattern in PATTERNS: print "-", pattern % dict(platform=p)
ops = ap.parse_args() if os.path.exists(ops.platforms): platforms = onlyaml.loadf(ops.platforms) else: platforms = ops.platforms.split(',') # # The following ONL packages are needed for each platform: # # The platform-config package # The ONLP package # ONL_PATTERNS = [ "onlp-%(platform)s", "onl-platform-config-%(platform)s" ] PATTERNS = list(onlu.sflatten(ops.add_patterns)) if not ops.no_builtins: PATTERNS = ONL_PATTERNS + PATTERNS for p in platforms: for pattern in PATTERNS: print "- ", pattern % dict(platform=p)
def prerequisite_packages(self): return list( onlu.sflatten( self._pkgs.get('prerequisites', {}).get('packages', [])))
def build(self, dir_=None): """Build the debian package. When this method is called it is assumed that all file prerequisites for the package have already been built or met. This is simply the packaging stage. 'dir_' : This is the output directory in which the package should be left. If unspecified the package's local directory will contain the package file.""" if 'external' in self.pkg: # Package file built externally epkg = self.pkg['external'] if os.path.exists(epkg): return epkg else: raise OnlPackageError( "The external package file '%s' does not exist." % epkg) # Make sure all required files exist if 'files' in self.pkg: self._validate_files() # If dir_ is not specified, leave package in local package directory. if dir_ is None: dir_ = self.dir workdir = tempfile.mkdtemp() root = os.path.join(workdir, "root") os.mkdir(root) # The package file will be built into the workdir self.pkg['__workdir'] = workdir for (src, dst) in self.pkg.get('files', {}): if dst.startswith('/'): dst = dst[1:] if os.path.isdir(src): # # Copy entire src directory to target directory # dstpath = os.path.join(root, dst) logger.debug("Copytree %s -> %s" % (src, dstpath)) shutil.copytree(src, dstpath) else: # # If the destination ends in a '/' it means copy the filename # as-is to that directory. # # If not, its a full rename to the destination. # if dst.endswith('/'): dstpath = os.path.join(root, dst) if not os.path.exists(dstpath): os.makedirs(dstpath) shutil.copy(src, dstpath) else: dstpath = os.path.join(root, os.path.dirname(dst)) if not os.path.exists(dstpath): os.makedirs(dstpath) shutil.copyfile(src, os.path.join(root, dst)) shutil.copymode(src, os.path.join(root, dst)) for (link, src) in self.pkg.get('links', {}).iteritems(): logger.info("Linking %s -> %s..." % (link, src)) link = os.path.join(root, link) os.symlink(src, link) # # FPM doesn't seem to have a doc option so we copy documentation # files directly into place. # for src in self.pkg.get('docs', []): if not os.path.exists(src): raise OnlPackageError( "Documentation source file '%s' does not exist." % src) dstpath = os.path.join(root, "usr/share/doc/%(name)s" % self.pkg) if not os.path.exists(dstpath): os.makedirs(dstpath) shutil.copy(src, dstpath) changelog = os.path.join(workdir, 'changelog') copyright_ = os.path.join(workdir, 'copyright') # # Export changelog and copyright files from the PKG dict # to the workdir for processing. # # The copyright and changelog data can be embedded directly # int the PKG file or kept as separate files. # def copy_str_or_file(src, dst): if os.path.exists(src): shutil.copyfile(src, dst) else: with open(dst, "w") as f: f.write(src) f.write("\n") copy_str_or_file(self.pkg['copyright'], copyright_) copy_str_or_file(self.pkg['changelog'], changelog) ############################################################ # # Invoke fpm with all necessary options. # ############################################################ self.pkg['__root'] = root command = """fpm -p %(__workdir)s -f -C %(__root)s -s dir -t deb -n %(name)s -v %(version)s -a %(arch)s -m %(maintainer)s --description "%(description)s" --url "%(url)s" --license "%(license)s" --vendor "%(vendor)s" """ % self.pkg for dep in self.pkg.get('depends', []): command = command + "-d %s " % dep for provides in onlu.sflatten(self.pkg.get('provides', [])): command = command + "--provides %s " % provides if 'init' in self.pkg: if not os.path.exists(self.pkg['init']): raise OnlPackageError("Init script '%s' does not exist." % self.pkg['init']) command = command + "--deb-init %s " % self.pkg['init'] if 'post-install' in self.pkg: if not os.path.exists(self.pkg['post-install']): raise OnlPackageError( "Post-install script '%s' does not exist." % self.pkg['post-install']) command = command + "--after-install %s " % self.pkg['post-install'] if logger.level < logging.INFO: command = command + "--verbose " onlu.execute(command) # Grab the package from the workdir. There can be only one. sys.stdout.write(workdir) files = glob.glob(os.path.join(workdir, '*.deb')) if len(files) == 0: raise OnlPackageError("No debian package.") elif len(files) > 1: raise OnlPackageError("Too many packages.") else: # Move to the target directory shutil.copy(files[0], dir_) # Remove entire work directory. shutil.rmtree(workdir) # Return the path to the final built package return os.path.join(dir_, os.path.basename(files[0]))