예제 #1
0
def getFullOptions(options=None):
    gnr_path = gnrConfigPath()
    enviroment_path = os.path.join(gnr_path,'environment.xml')
    env_options = Bag(expandpath(enviroment_path)).getAttr('gnrdaemon')
    if env_options.get('sockets'):
        if env_options['sockets'].lower() in ('t','true','y') :
            env_options['sockets']=os.path.join(gnr_path,'sockets')
        if not os.path.isdir(env_options['sockets']):
            os.makedirs(env_options['sockets'])
        env_options['socket']=env_options.get('socket') or os.path.join(env_options['sockets'],'gnrdaemon.sock')
    assert env_options,"Missing gnrdaemon configuration."
    for k,v in options.items():
        if v:
            env_options[k] = v
    return env_options
예제 #2
0
def getFullOptions(options=None):
    gnr_path = gnrConfigPath()
    enviroment_path = os.path.join(gnr_path, 'environment.xml')
    env_options = Bag(expandpath(enviroment_path)).getAttr('gnrdaemon')
    if env_options.get('sockets'):
        if env_options['sockets'].lower() in ('t', 'true', 'y'):
            env_options['sockets'] = os.path.join(gnr_path, 'sockets')
        if not os.path.isdir(env_options['sockets']):
            os.makedirs(env_options['sockets'])
        env_options['socket'] = env_options.get('socket') or os.path.join(
            env_options['sockets'], 'gnrdaemon.sock')
    assert env_options, "Missing gnrdaemon configuration."
    for k, v in options.items():
        if v:
            env_options[k] = v
    return env_options
예제 #3
0
    if operation in ('i', 'import'):
        import_record = tbl.insertOrUpdate if replace else tbl.insert
        try:
            for rec in data[pkg_table].values():
                import_record(rec)
            instance.db.dbcommit()
        except Exception, e:
            instance.db.rollback()
            logging.exception(e)

    if operation in ('e', 'export'):
        qry = tbl.query(where=where)
        logging.info('%d records found', qry.count())

        pkey = tbl.pkey
        records = data.get(pkg_table) or Bag()
        for n, rec in enumerate(qry.fetch()):
            r = dict([(k, unicodeToUTF8String(v)) for k, v in rec.items()
                      if not k.startswith('__')])
            records.addItem(unicodeToUTF8String(r[pkey]), Bag(r))

        data.setItem(pkg_table, records)

        yaml.dump(data.asDictDeeply(), codecs.open(filename, 'wt', 'utf-8'))


def unicodeToUTF8String(maybe_unicode):
    if isinstance(maybe_unicode, unicode):
        return maybe_unicode.encode('utf-8')
    else:
        return maybe_unicode
예제 #4
0
파일: yamlio.py 프로젝트: poppogbr/genropy
    if operation in ('i','import'):
        import_record = tbl.insertOrUpdate if replace else tbl.insert
        try:
            for rec in data[pkg_table].values():
                import_record(rec)
            instance.db.dbcommit()
        except Exception, e:
            instance.db.rollback()
            logging.exception(e)

    if operation in ('e','export'):
        qry = tbl.query(where=where)
        logging.info('%d records found', qry.count())

        pkey = tbl.pkey
        records = data.get(pkg_table) or Bag()
        for n, rec in enumerate(qry.fetch()):
            r = dict([(k,unicodeToUTF8String(v)) for k,v in rec.items() if not k.startswith('__')])
            records.addItem(unicodeToUTF8String(r[pkey]), Bag(r))

        data.setItem(pkg_table, records)

        yaml.dump(data.asDictDeeply(), codecs.open(filename, 'wt','utf-8'))

def unicodeToUTF8String(maybe_unicode):
    if isinstance(maybe_unicode, unicode):
        return maybe_unicode.encode('utf-8')
    else:
        return maybe_unicode

if __name__ == '__main__':