Example #1
0
    def build(self, box, name_suffix='', stdout=None):
        appname = self.get_var('BPT_APP_NAME')
        version = self.get_var('BPT_APP_VERSION')

        # Check last box the sourcedir was built in
        bpt_status_file = os.path.join(self.path, '.bpt_status')
        if os.path.exists(bpt_status_file):
            bpt_status = load_info(bpt_status_file)
            last_box_id = bpt_status.get('last_box_id', box.box_id)
            if last_box_id != box.box_id:
                log.info(
                    'Intermediate files built for another package box. Cleaning first.'
                )
                self.clean()

        # Write the current box_id
        store_info(bpt_status_file, dict(last_box_id=box.box_id))

        if not box.check_platform():
            raise UserError(
                'Current platform is different from box\'s platform')

        pkg_name = '%s-%s%s' % (appname, version, name_suffix)
        pkg = box.create_package(pkg_name,
                                 app_name=appname,
                                 app_version=version,
                                 enabled=False)
        log.info('Building application %s, in sourcedir %s', appname,
                 self._sourcedir)

        # Build
        sh_line = ('source "%s";' % BASE_SH_SCRIPT +
                   'cd "%s";' % self._sourcedir +
                   'export BPT_PKG_PREFIX="%s";' % pkg.path +
                   'export BPT_CPU_COUNT="%d";' % cpu_count() +
                   'source bpt-rules;' + 'bpt_download;' + 'bpt_unpack;' +
                   'bpt_build;')
        retcode = call(['bash', '-e', box.env_script, sh_line], stdout=stdout)
        if retcode != 0:
            raise UserError('FATAL: build script exited with status %s' %
                            retcode)

        box.enable_package(pkg)
        return pkg
Example #2
0
File: build.py Project: ot/bpt
    def build(self, box, name_suffix='', stdout=None):
        appname = self.get_var('BPT_APP_NAME')
        version = self.get_var('BPT_APP_VERSION')

        # Check last box the sourcedir was built in
        bpt_status_file = os.path.join(self.path, '.bpt_status')
        if os.path.exists(bpt_status_file):
            bpt_status = load_info(bpt_status_file)
            last_box_id = bpt_status.get('last_box_id', box.box_id)
            if last_box_id != box.box_id:
                log.info('Intermediate files built for another package box. Cleaning first.')
                self.clean()

        # Write the current box_id
        store_info(bpt_status_file, dict(last_box_id=box.box_id))

        if not box.check_platform():
            raise UserError('Current platform is different from box\'s platform')

        pkg_name = '%s-%s%s' % (appname, version, name_suffix)
        pkg = box.create_package(pkg_name,
                                 app_name=appname,
                                 app_version=version,
                                 enabled=False)
        log.info('Building application %s, in sourcedir %s', appname, self._sourcedir)

        # Build
        sh_line = ('source "%s";' % BASE_SH_SCRIPT
                   + 'cd "%s";' % self._sourcedir
                   + 'export BPT_PKG_PREFIX="%s";' % pkg.path
                   + 'export BPT_CPU_COUNT="%d";' % cpu_count()
                   + 'source bpt-rules;'
                   + 'bpt_download;'
                   + 'bpt_unpack;'
                   + 'bpt_build;'
                   )
        retcode = call(['bash', '-e', box.env_script, sh_line], stdout=stdout)
        if retcode != 0:
            raise UserError('FATAL: build script exited with status %s' % retcode)

        box.enable_package(pkg)
        return pkg
Example #3
0
    def build(self, box, name_suffix="", stdout=None):
        appname = self.get_var("BPT_APP_NAME")
        version = self.get_var("BPT_APP_VERSION")

        # Check last box the sourcedir was built in
        bpt_status_file = os.path.join(self.path, ".bpt_status")
        if os.path.exists(bpt_status_file):
            bpt_status = load_info(bpt_status_file)
            last_box_id = bpt_status.get("last_box_id", box.box_id)
            if last_box_id != box.box_id:
                log.info("Intermediate files built for another package box. Cleaning first.")
                self.clean()

        # Write the current box_id
        store_info(bpt_status_file, dict(last_box_id=box.box_id))

        if not box.check_platform():
            raise UserError("Current platform is different from box's platform")

        pkg_name = "%s-%s%s" % (appname, version, name_suffix)
        pkg = box.create_package(pkg_name, app_name=appname, app_version=version, enabled=False)
        log.info("Building application %s, in sourcedir %s", appname, self._sourcedir)

        # Build
        sh_line = (
            'source "%s";' % BASE_SH_SCRIPT
            + 'cd "%s";' % self._sourcedir
            + 'export BPT_PKG_PREFIX="%s";' % pkg.path
            + "source bpt-rules;"
            + "bpt_download;"
            + "bpt_unpack;"
            + "bpt_build;"
        )
        retcode = call(["bash", "-e", box.env_script, sh_line], stdout=stdout)
        if retcode != 0:
            raise UserError("FATAL: build script exited with status %s" % retcode)

        box.enable_package(pkg)
        return pkg
Example #4
0
class Package(object):
    '''A package installed in a box, i.e. a subdirectory of
    <box>/pkgs. The attributes are kept in sync with the stored
    pkg_info'''

    _PackagePool = dict()

    def __new__(cls, pkgdir):
        # Ensure that there is only one instance of Package for every
        # directory, so that no other instance can change pkg_info
        # contents, invalidating our _dict.

        # XXX(ot): This is obviously not thread safe
        # XXX(ot): This keeps all the packages in memory. Use a
        # weakrefdict instead?

        return Package._PackagePool.setdefault(pkgdir, object.__new__(cls))

    def __init__(self, pkgdir):
        # XXX(ot): better exceptions? metadata version handling?

        self._path = pkgdir
        self._name = os.path.basename(pkgdir)
        self._dict = load_info(_pkg_info_file(pkgdir))

        # Sanity check
        for k in ['app_name', 'app_version', 'enabled']:
            if k not in self._dict:
                raise UserError('Invalid package')

    @classmethod
    def create(cls, pkgdir, **kwArgs):
        try:
            os.makedirs(os.path.join(pkgdir, 'bpt_meta'))
        except OSError, exc:
            if exc.errno != 17:  # directory exists
                raise

        store_info(_pkg_info_file(pkgdir), kwArgs)
        return cls(pkgdir)
Example #5
0
File: box.py Project: ot/bpt
        if os.path.exists(dest_path):
            raise UserError('Destination already exists')

        try:
            os.makedirs(dest_path)
            for directory in STANDARD_DIRS:
                os.makedirs(os.path.join(dest_path, directory))
        except OSError, exc:
            raise UserError('Impossible to create destination directories: "%s"' %
                            str(exc))

        box_info = dict()
        box_info['id'] = str(uuid1())
        box_info['platform'] = _get_platform()
        box_info['bpt_version'] = bpt.__version__
        store_info(os.path.join(dest_path, 'bpt_meta', 'box_info'), box_info)

        box = cls(dest_path)
        box.sync()
        log.info('Created box with id %s in directory %s', box.box_id, box.path)
        return box

    def sync(self):
        '''Recreate all the symlinks and the env script, restoring the
        consistency of the box.'''

        # Clean all symlinks
        for d in DYN_DIRS:
            d_path = os.path.join(self.path, d)
            shutil.rmtree(d_path)
            os.makedirs(d_path)
Example #6
0
            raise UserError('Destination already exists')

        try:
            os.makedirs(dest_path)
            for directory in STANDARD_DIRS:
                os.makedirs(os.path.join(dest_path, directory))
        except OSError, exc:
            raise UserError(
                'Impossible to create destination directories: "%s"' %
                str(exc))

        box_info = dict()
        box_info['id'] = str(uuid1())
        box_info['platform'] = _get_platform()
        box_info['bpt_version'] = bpt.__version__
        store_info(os.path.join(dest_path, 'bpt_meta', 'box_info'), box_info)

        box = cls(dest_path)
        box.sync()
        log.info('Created box with id %s in directory %s', box.box_id,
                 box.path)
        return box

    def sync(self):
        '''Recreate all the symlinks and the env script, restoring the
        consistency of the box.'''

        # Clean all symlinks
        for d in DYN_DIRS:
            d_path = os.path.join(self.path, d)
            shutil.rmtree(d_path)
Example #7
0
    def __setattr__(self, attr, value):
        if attr.startswith('_'):
            return object.__setattr__(self, attr, value)

        self._dict[attr] = value
        store_info(_pkg_info_file(self._path), self._dict)
Example #8
0
    def __setattr__(self, attr, value):
        if attr.startswith("_"):
            return object.__setattr__(self, attr, value)

        self._dict[attr] = value
        store_info(_pkg_info_file(self._path), self._dict)
Example #9
0
File: box.py Project: davidk01/bpt
        # Safety checks
        if os.path.exists(dest_path):
            raise UserError("Destination already exists")

        try:
            os.makedirs(dest_path)
            for directory in STANDARD_DIRS:
                os.makedirs(os.path.join(dest_path, directory))
        except OSError, exc:
            raise UserError('Impossible to create destination directories: "%s"' % str(exc))

        box_info = dict()
        box_info["id"] = str(uuid1())
        box_info["platform"] = _get_platform()
        box_info["bpt_version"] = bpt.__version__
        store_info(os.path.join(dest_path, "bpt_meta", "box_info"), box_info)

        box = cls(dest_path)
        box.sync()
        log.info("Created box with id %s in directory %s", box.box_id, box.path)
        return box

    def sync(self):
        """Recreate all the symlinks and the env script, restoring the
        consistency of the box."""

        # Clean all symlinks
        for d in DYN_DIRS:
            d_path = os.path.join(self.path, d)
            shutil.rmtree(d_path)
            os.makedirs(d_path)