Exemplo n.º 1
0
def hisParseParams(data_str):
    """Парсинг параметров, хрянящихся в строке data_str в json-формате, полученных процедурой hisGet.
    Принимает:
    data_str - строка в json-формате '{"olds": {"FIELD1": val1, "FIELD2": val2, ...}, "news": {"FIELD1": val1, "FIELD2": val2, ...}}',
        где "olds" - старые значения полей (применимо для a in ('d','u')), "news" - новые значения полей (применимо для a in ('i','u'))

    Возвращает:
    Словарик python, полученный преобразованием строки data_str из json-формата
    """
    return pu.format(
        obj=json.loads(data_str, encoding='cp1251')
    )  #format for decoding each component from unicode, returned by json.loads
Exemplo n.º 2
0
    def upload(self):
        #print "upload: ", self.getIfaceVar("id_system")
        """upload action

        We use our variation of FieldStorage to parse the MIME
        encoded HTML form data containing the file."""

        #print "x"*5252
        #print "UPLOAD STARTS"
        #print "x"*5252

        #ignore no authorized scripts
        LOGIN = self.getUserVar('login')
        if not LOGIN:
            return 'Нельзя заливать скрипты с утерянной авторизацией!'
        #print "LOGIN="******"0"
        whatsnew = []

        formFields = FieldStorage(fp=cherrypy.request.rfile,
                                  headers=lcHDRS,
                                  environ={'REQUEST_METHOD': 'POST'},
                                  keep_blank_values=True)

        whatsnew = pu.format(
            json.loads((formFields['whatsnewdic'].value
                        ).decode("windows-1251").encode("utf-8")))
        try:
            t = self.trans()
        except Exception, exc:
            return str(exc)
Exemplo n.º 3
0
    def get_systems(self, root):
        u"Получить рекурсивный список всех дочерних систем-метрик (без методов-метрик) и их потомков"
        import py_utils as pu
        systems = []
        for ref_name in dir(root):
            obj = getattr(root, ref_name)
            id_system = getattr(obj, 'id_system', None)

            #для систем Profile, Account
            if id_system is None:
                continue

            if isinstance(obj, BaseMainMetric):
                #found mapped BaseMainMetric

                #find count of methots
                cnt_meth = 0
                for meth_name in dir(obj):
                    meth = getattr(obj, meth_name)
                    if callable(meth) and 'metric' in dir(meth):
                        cnt_meth += 1

                if cnt_meth > 0:
                    systems.append({
                        'NAME':
                        si.systems_params[id_system]['system_name'],
                        'REF_NAME':
                        si.systems_params[id_system]['system_ref'],
                        'FULL_REF_NAME':
                        '/ENGINE/METRICS' +
                        si.systems_params[id_system]['system_full_ref'],
                        'DOCSTRING':
                        pu.format(obj.__doc__),
                        'CNT_METRICS':
                        cnt_meth
                    })

                systems.extend(self.get_systems(obj))
        return systems
Exemplo n.º 4
0
    def get_system(self, obj):
        u"Получить сведения о классе метрик"
        import py_utils as pu

        system = {
            'NAME': 'unknown',
            'REF_NAME': 'unknown',
            'FULL_REF_NAME': 'unknown',
            'DOCSTRING': 'unknown',
            'CNT_METRICS': 'unknown'
        }
        id_system = getattr(obj, 'id_system', None)

        if id_system is not None and isinstance(obj, BaseMainMetric):

            #find count of methots
            cnt_meth = 0
            for meth_name in dir(obj):
                meth = getattr(obj, meth_name)
                if callable(meth) and 'metric' in dir(meth):
                    cnt_meth += 1

            system = {
                'NAME':
                si.systems_params[id_system]['system_name'],
                'REF_NAME':
                si.systems_params[id_system]['system_ref'],
                'FULL_REF_NAME':
                '/ENGINE/METRICS' +
                si.systems_params[id_system]['system_full_ref'],
                'DOCSTRING':
                pu.format(obj.__doc__),
                'CNT_METRICS':
                cnt_meth
            }

        return system
Exemplo n.º 5
0
    def saveLabel(self, html, procedures, name, file, reportid):
        if reportid == '':
            reportid = None
        # файл отчета
        path_to_file = os.path.join(os.path.abspath('..'), 'static',
                                    'KURSSKLAD', 'LABELEDIT', 'reports', file)
        #open(path_to_file, 'w').close()
        self.report_config = ConfigParser.ConfigParser()
        # добавим секции
        self.report_config.add_section(self.section_procname)
        self.report_config.add_section(self.section_procparam)
        self.report_config.add_section(self.section_procfetch)
        self.report_config.add_section(self.section_datalist)
        self.report_config.add_section('html')

        procedures = simplejson.loads(procedures)
        i = 1
        for item in procedures:
            self.report_config.set(self.section_procname, 'proc' + str(i),
                                   item['procname'])
            self.report_config.set(self.section_procparam, 'proc' + str(i),
                                   item['procparams'])
            self.report_config.set(self.section_procfetch, 'proc' + str(i),
                                   item['fetch'])
            self.report_config.set(self.section_datalist, 'proc' + str(i),
                                   item['dl'])
            i += 1
        self.report_config.set('html', 'html', pu.format(html))

        # save config
        with open(path_to_file, 'wb') as configfile:
            self.report_config.write(configfile)
        data = self.dbExecC(sql='select * from RBS_LABELEDIT_SAVE(?,?,?)',
                            params=[reportid, name, file],
                            fetch='one')
        return self.pyDumps(data)
Exemplo n.º 6
0
def get_methods(system):
    u"Получает методы-метрики по системе, имеющей класс метрик"
    import py_utils as pu
    from app import mappings

    methods = []
    obj = mappings.find_map_obj(system['FULL_REF_NAME'])
    id_system = getattr(obj, 'id_system', None)

    #для систем Profile, Account
    if id_system is not None and isinstance(obj, BaseMainMetric):
        for meth_name in dir(obj):
            meth = getattr(obj, meth_name)
            if callable(meth) and 'metric' in dir(meth):
                methods.append({
                    'NAME':
                    meth.__name__,
                    'FULL_REF_NAME':
                    system['FULL_REF_NAME'] + '/' + meth.__name__,
                    'DOCSTRING':
                    pu.format(meth.__doc__)
                })

    return methods
Exemplo n.º 7
0
    def createSite(self, t, site, objid, editmode, parent=None):
        def coalesce(val, other):
            if val == 'null' or val == 'undefined' or val is None or val == '':
                return other
            else:
                return val

        if site.has_key('z'):
            z = site['z']
        else:
            z = None
        if site.has_key('classname'):
            classname = site['classname']
        else:
            classname = ''
        if site.has_key('subtype'):
            subtype = site['subtype']
        else:
            subtype = ''
        if site.has_key('slength'):
            slength = site['slength']
        else:
            slength = None
        if editmode == 'false':
            id = t.dbExec(
                sql=
                'select * from RBS_WH_CREATE_SITE(?,?,?,?,?,?,?,?,?,?,?,?,?)',
                params=[
                    parent,
                    pu.format(site['name']),
                    pu.format(site['viewname']), site['type'], site['width'],
                    site['height'],
                    coalesce(site['x'], None),
                    coalesce(site['y'], None),
                    coalesce(z, 1),
                    coalesce(objid, None), classname, subtype, slength
                ],
                fetch='one')['SITEID']
        else:
            if site.has_key('id'):
                siteid = site['id']
            else:
                siteid = None
            id = t.dbExec(
                sql=
                'select * from RBS_WH_SITE_TMP_INS(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
                params=[
                    coalesce(siteid, None), parent,
                    coalesce(objid, None), site['type'],
                    pu.format(site['name']), site['height'], site['width'],
                    slength,
                    coalesce(site['x'], None),
                    coalesce(site['y'], None),
                    coalesce(z, 1),
                    pu.format(site['viewname']), None, classname, subtype
                ],
                fetch='one')['SITEOUT']
        if site.has_key('children'):
            for item in site['children']:
                self.createSite(t, item, objid, editmode, id)
        return id