Ejemplo n.º 1
0
def get_report_info(testlog, workspace):
    '''Get report info'''
    logger.debug("Get report info of testlog %s %s", testlog, workspace)
    try:
        package = utils.load(CONST.WORKSPACE).get(workspace, {}).get('package')
        data = get_function_info(testlog, package)
        func = data.get('func', '')
        task = data.get('task_title', '')

        deliver = utils.load(CONST.WORKSPACE).get(workspace).get('deliver')
        deliver = Path(deliver)

        deliver = deliver.joinpath(task)

        dirTarget = utils.load(CONST.SETTING, 'jpDict.dirresult')
        dirSpec = utils.load(CONST.SETTING, 'jpDict.dirspec')

        data.update({
            'dirTarget':
            str(deliver.joinpath(dirTarget, func)),
            'dirSpec':
            str(deliver.joinpath(dirSpec)),
            'dirTargetGcs':
            str(deliver.joinpath(dirTarget, task, func)),
            'func_no':
            data.get('func_no')
        })

    except Exception as e:
        logger.exception(e)
        data = {}
    finally:
        return data
Ejemplo n.º 2
0
def get_messages():
    '''Get messages from server'''
    try:
        msg = '''<a id="new-build" href={URL}>
                    <div class="mail-contnet">
                        <h5>{title}</h5> <h6>{content}</h6> <h6>{content1}</h6>
                    </div>
                </a>
        '''
        html = ''

        is_online = utils.online_status()
        if is_online == 200:
            auth = utils.get_auth_info()

            # Get version
            version = utils.load(CONST.VERSION, 'version')

            filename = 'messages.json'
            url = utils.get_http_link(filename)
            filepath = CONST.DATA.joinpath(filename)
            utils.download(url, filepath, auth)

            info = utils.load(filepath)
            latest = info.get('version')
            link_down = info.get('link')
            descrip = info.get('descrip')

            if latest != None and version != latest:
                html += msg.format(URL=link_down,
                                   title='New Build Available',
                                   content='Version {0}'.format(latest),
                                   content1=descrip)

            # Get messages
            for title, body in info.items():
                if title == 'version' or title == 'link' or title == 'descrip':
                    continue

                try:
                    content, tilldate = tuple(body)
                    if utils.is_expired(tilldate) is False:
                        html += msg.format(URL="",
                                           title=title,
                                           content=content,
                                           content1="")
                except Exception as e:
                    logger.exception(e)

            # Delete file
            utils.delete(filepath)

        data = {'html': html} if html.strip() != '' else {}

    except Exception as e:
        logger.exception(e)
        data = {}

    finally:
        return data
Ejemplo n.º 3
0
Archivo: db.py Proyecto: HP1012/lila
    def __init__(self, name, level=1):
        self.name = name
        self.json = CONST.DATA.joinpath('{0}.json'.format(name))
        self.info = utils.load(CONST.PACKAGE).get(name, {})
        self.data_pkg = utils.load(self.json)

        # Update data
        if self.name != None and self.info != {}:
            self.update_data(level)
Ejemplo n.º 4
0
Archivo: db.py Proyecto: HP1012/lila
    def update_data_xlsx(self, key):
        '''Update summary or report data'''
        logger.debug("Update data %s of package %s", key, self.name)
        try:
            key_date = '{0}_date'.format(key)
            params = [
                self.info.get(key, {}).get(k)
                for k in ['xlsx', 'sheet', 'begin', 'end']
            ]

            xlsx = CONST.DATA.joinpath('{0}.{1}.xlsx'.format(self.name, key))

            if str(params[0]).strip() != '' and str(params[1]).strip() != '':

                date = self.data_pkg.get(key_date)

                if params[0] is not None:
                    xlsx, date = utils.update_file(params[0], xlsx, date)

                if xlsx is not None and Path(xlsx).is_file():
                    params[0] = xlsx
                    params += [utils.load(CONST.SETTING, 'headerXlsx')]
                    data = parse.get_xlsx_raw(*tuple(params))
                    if data != {} and data != []:
                        self.data_pkg.update({key: data, key_date: date})
                        utils.write(self.data_pkg, self.json)
                    utils.delete(xlsx)
        except Exception as e:
            logger.exception(e)
Ejemplo n.º 5
0
Archivo: db.py Proyecto: HP1012/lila
def get_list_package():
    '''Get list package'''
    def is_package(filepath):
        data = utils.load(filepath)
        return 'summary' in data.keys() and 'simulink' in data.keys()

    try:
        data = list(utils.load(CONST.PACKAGE).keys())

        lst, _ = utils.scan_files(CONST.DATA, '.json')
        for filepath in lst:
            try:
                if is_package(filepath):
                    filename = Path(filepath).name
                    name = filename.replace('.json', '')
                    if name not in data:
                        data.append(name)
            except Exception as e:
                logger.exception(e)

    except Exception as e:
        logger.exception(e)
        data = data if isinstance(data, list) else []
    finally:
        return data
Ejemplo n.º 6
0
def generate_html():
    '''Generate html files'''
    data = utils.get_lang_data('ui')
    data.update(utils.load(CONST.VERSION))
    lst_page = [('workspace.html', 'index.html'),
                ('package.html', 'package.html'),
                ('summary.html', 'summary.html')]

    for page in lst_page:
        render(data, *page)
Ejemplo n.º 7
0
def get_package_info(name=None):
    '''Get package info'''
    logger.debug("Request package info")
    try:
        data = utils.load(CONST.PACKAGE)
        info = data if name is None else data.get(name, {})
    except Exception as e:
        logger.exception(e)
        info = {}
    finally:
        return info
Ejemplo n.º 8
0
Archivo: db.py Proyecto: HP1012/lila
def update_package(info, action, path=CONST.PACKAGE):
    '''Update package'''
    data = utils.load(path)
    name = info.get('name')

    if action == 'delete':
        if name in data.keys():
            logger.debug("Delete package %s", name)
            del data[name]

    else:
        action = "Add new" if name in data.keys() else "Update"
        logger.debug("%s package %s", action, info)

        data.update({name: info})

    # Write changes to file
    utils.write(data, path)
Ejemplo n.º 9
0
def get_workspace_info(workspace):
    '''Get workspace info'''
    logger.debug("Get workspace info %s", workspace)
    pkg_options = '''
        {% for pkg in list_pkg %}
        <option data-tokens="{{pkg}}">{{pkg}}</option>
        {% endfor %}
        '''
    try:
        data = utils.load(CONST.WORKSPACE).get(workspace)
        list_pkg = db.get_list_package()
        data.update({
            'pkgOptions':
            render({'list_pkg': list_pkg}, pkg_options, mode="string")
        })
    except Exception as e:
        logger.exception(e)
        data = data if isinstance(data, dict) else {}
    finally:
        return data
Ejemplo n.º 10
0
Archivo: db.py Proyecto: HP1012/lila
def get_workspace_data():
    '''Get workspace data'''
    logger.debug("Get workspace data")
    data_wsp = utils.load(CONST.WORKSPACE)
    if data_wsp == {}:
        return {}

    list_wsp = [[
        name, dct.get('path'),
        dct.get('package'),
        dct.get('stamp', 0)
    ] for name, dct in data_wsp.items()]
    list_wsp.sort(key=lambda x: x[0])

    # Latest workspace
    last_wsp_name = sorted(list_wsp, key=lambda x: x[3])[-1][0]
    last_wsp = data_wsp.get(last_wsp_name, {})

    # Scan testlog in directory
    dir_log = last_wsp.get('path')
    list_log, latest_log = utils.scan_files(dir_log)
    list_log = [[Path(f).name, f] for f in list_log]
    list_log.sort(key=lambda x: x[0])

    # Latest function
    last_log = Path(str(last_wsp.get('function', latest_log)))
    if str(last_log).startswith(
            str(dir_log)) is False or last_log.is_file() is False:
        last_log = latest_log

    return {
        'list_wsp': list_wsp,
        'last_wsp_name': last_wsp_name,
        'list_log': list_log,
        'last_log': last_log if last_log is None else last_log.name,
        'latest_log': latest_log if latest_log is None else latest_log.name,
        'last_pkg_name': last_wsp.get('package')
    }
Ejemplo n.º 11
0
Archivo: db.py Proyecto: HP1012/lila
def update_workspace(info, action, filepath=CONST.WORKSPACE):
    '''Update workspace'''
    data = utils.load(filepath)
    name = info.get('name')

    if action == 'delete':
        if name in data.keys():
            logger.debug("Delete workspace %s", name)
            del data[name]

    else:
        dct = data.get(name, {})

        action = "Add new" if dct == {} else "Update"
        logger.debug("%s workspace %s", action, info)

        info.update({'stamp': time.time()})

        dct.update(info)
        data.update({name: dct})

    # Write changes to file
    utils.write(data, filepath)
Ejemplo n.º 12
0
Archivo: db.py Proyecto: HP1012/lila
 def is_package(filepath):
     data = utils.load(filepath)
     return 'summary' in data.keys() and 'simulink' in data.keys()