Пример #1
0
    def log(self, elem):
        '''
        .. seealso:: :attr:`log`
        '''

        if elem:
            self.__meta['log'].update({get_timestamp(precice=True): elem})
        mfile = self.__meta['header']['stage']

        self.__lock.acquire()
        try:
            j = read_json(mfile)
            if j != self.__meta:
                write_json(mfile, self.__meta)
        finally:
            self.__lock.release()
Пример #2
0
    def log(self, elem):
        '''
        .. seealso:: :attr:`log`
        '''

        if elem:
            self.__meta['log'].update({get_timestamp(precice=True): elem})
        mfile = self.__meta['header']['stage']

        self.__lock.acquire()
        try:
            j = read_json(mfile)
            if j != self.__meta:
                write_json(mfile, self.__meta)
        finally:
            self.__lock.release()
Пример #3
0
def gen_info(images, ccmd, start=None, finish=None):
    '''
    Before the build gets started, :ref:`bconf` starts the ``info.json``
    with some general information.
    It's purpose is to provide a single file to easily include links to the
    latest firmware in foreign websites.

    This file gets extended here, to hold a dictionary mapping each
    router-model (keys) to appropriate `factory` and `sysupgrade` image
    files with checksums.

    To produce checksums, gluon's ``scripts/sha512sum.sh`` is used.
    It is possible to change this using the ``-c`` command line flag.

    .. seealso:: :func:`common.info_args` for command line syntax
    '''
    photon, settings = pinit('gen_info', verbose=True)

    info = read_json(path.join(
        settings['prepare']['stage_dir'],
        settings['prepare']['info']
    ))
    images = path.abspath(images)

    if start and finish:
        try:
            seconds = abs(int(finish) - int(start))
        except (TypeError, ValueError):
            seconds = None
        if seconds:
            info['_info']['build_seconds'] = seconds
            build_time = []
            for name, val in [
                ('d', 60*60*24),
                ('h', 60*60),
                ('m', 60),
                ('s', 1)
            ]:
                if seconds > val:
                    pval, seconds = divmod(seconds, val)
                    build_time.append('%d%s' % (pval, name))
            info['_info']['build_time'] = ' '.join(build_time)

    for variety in ['factory', 'sysupgrade']:
        image_dir = path.join(images, variety)
        if info and path.exists(image_dir):
            for image_name in [
                i for i in listdir(image_dir) if not i.endswith('manifest')
            ]:
                model = image_name.split(
                    '%s-' % (info['_info']['release'])
                )[-1].split(
                    '-%s.bin' % (variety)
                )[0].split(
                    '.bin'
                )[0]

                checksum = photon.m(
                    'checksumming %s' % (model),
                    cmdd=dict(
                        cmd='%s %s' % (
                            path.abspath(ccmd),
                            path.join(image_dir, image_name)
                        )
                    )
                ).get('out')

                info[model] = info.get(model, dict())
                info[model][variety] = dict(
                    image=image_name,
                    checksum=checksum
                )

            write_json(path.join(images, settings['prepare']['info']), info)

    photon.m('info generated', more=dict(images=images, info=info))
Пример #4
0
def gen_bconf(
    branch, targets, signkey,
    gluon_tag=None, site_tag=None,
    broken=False, onlyone=False, priority=None
):
    '''
    Provides all information needed by the builder in placing a ``bconf``-file.

    Since we are already collecting information here, the ``info.json``
    is created as well.

    The same arguments as in :func:`prepare` are used here.

    .. seealso:: :func:`common.prepare_args` for command line syntax
    '''
    photon, settings = pinit('gen_bconf')

    if photon.settings.load(
        'siteconf',
        path.join(
            settings['site']['local']['wi'],
            settings['site']['generator_settings']
        )
    ):
        photon.s2m

        gluon, site = ginit(photon)
        gluon_tag = gluon_tag if gluon_tag else gluon.short_commit[0]
        site_tag = site_tag if site_tag else site.short_commit[0]

        broken = '1' if broken else ''
        version = settings['siteconf']['site']['gluon_release_num']
        priority = (
            priority if priority
            else settings['siteconf']['site']['gluon_priority']
        )
        description = '-%s%s' % (
            branch, '-%s' % (get_timestamp(time=False)) if
            not all(settings['common']['branches']['avail'][branch])
            else ''
        )

        # these fields appear in the info.json
        fields = dict(
            broken_flag=broken,
            call_branch=branch,
            communities=onlyone if onlyone else ' '.join(
                settings['common']['communities'].keys()
            ),
            gluon_tag=gluon_tag,
            site_tag=site_tag,
            priority=priority,
            release='%s%s' % (version, description),
            targets=' '.join(targets),
            version=version
        )
        write_json(
            path.join(
                settings['prepare']['stage_dir'],
                settings['prepare']['info']
            ),
            dict(_info=fields)
        )

        # these fields only appear in the bconf
        fields.update(dict(
            build_branch=settings['common']['branches']['build'],
            build_dir=settings['gluon']['local']['dir'],
            info_file=settings['prepare']['info'],
            library_dir=path.join(
                settings['publish']['library_dir'],
                '%s%s' % (version, description)
            ),
            mkcmd=settings['common']['mkcmd'],
            pycmd=settings['common']['pycmd'],
            signkey=signkey,
            stage_dir=settings['prepare']['stage_dir']
        ))

        bconf = photon.template_handler(
            settings['prepare']['bconf']['tpl'],
            fields=fields
        )
        bconf.write(
            settings['prepare']['bconf']['out'],
            append=False
        )