Example #1
0
File: file.py Project: s-tar/kate
def save_to_db(name, module=None, entity=None, database=None):
    db = database
    if not db: db = Database()
    name = name.strip("/")
    name_parts = name.split('.')

    new_file = File()
    new_file.name = name_parts[0]
    new_file.module = module
    new_file.entity = entity
    new_file.extension = name_parts[-1] if len(name_parts) > 1 else None
    new_file.type = '.'.join(name_parts[1:-1]) if len(name_parts) > 2 else None

    prev_file = db(File).get_by_fullpath(new_file.fullpath)

    if prev_file:
        new_file = prev_file

    old_path = os.path.join(root, new_file.fullpath)
    m = hashlib.md5()
    m.update(str(uuid.uuid4()))
    new_file.uniq_id = m.hexdigest()
    new_path = os.path.join(root, new_file.fullpath)

    if old_path != new_path and os.path.exists(old_path): os.remove(old_path)

    db.add(new_file)
    print new_file.id
    if not database:
        db.commit()
        db.close()

    return new_path
Example #2
0
def get_default_language():
    global default_language
    db = Database()
    if not default_language:
        lang = db(Language).get_default()
        default_language = lang
    db.close()
    return default_language
Example #3
0
def translate(code, default='', language=None):
    from entities.s_dictionary import Dictionary
    global dictionary
    mode = request.query.get('mode')
    if mode == 'no_translation': return code
    if code not in dictionary:
        db = Database()
        d = db(Dictionary).get_by_code(code)
        if d is None:
            d = Dictionary()
            d.code = code
            d.text = default
            db.add(d)
            db.commit()
        db.expunge(d)
        db.close()
        dictionary[code] = d
    return dictionary[code].t('text', language=language)
Example #4
0
def after_delete_listener(mapper, connection, target):
    db = Database()
    for t in get_translations(target, db): db.delete(t)
    db.commit()
    db.close()