Esempio n. 1
0
def _editor(args):
    editor_cmd = os.getenv('EDITOR')

    if editor_cmd is None:
        sys.exit("Environment var EDITOR is unset")

    if args.id:
        try:
            doc = client.get(args.id)
        except NotFoundError:
            sys.exit('Document not found')
    else:
        doc = Document()

    (_, filename) = tempfile.mkstemp()

    with codecs.open(filename, 'w', encoding='utf8') as file:
        data = "" if doc.data is None else doc.data.content
        file.write(data)

    if os.system(editor_cmd + " " + filename) == 0:
        with codecs.open(filename, 'r', encoding='utf8') as file:
            doc.data = file.read().strip()
            if doc.data or doc.id:
                client.save(doc)

    os.unlink(filename)
Esempio n. 2
0
    def get(self, id):

        try:
            args = (self.config['TABLE'], id)
            self.cursor.execute('''SELECT * FROM %s WHERE id = %s''' % args)
            row = self.cursor.fetchone()
            if row is not None:
                doc = Document(**row)
                doc.users    = row[5].split(',')
                doc.usersdel = row[6].split(',')
            else:
                doc = None
        except Exception as e:
            DatabaseException(e)
        else:
            return doc
Esempio n. 3
0
    def get_docs_for_commit(self):

        docs = []
        try:
            self.cursor.execute('''SELECT * FROM %s
                                   WHERE synched = 0 ''' % (self.config['TABLE']))
            rows = self.cursor.fetchall()
            for row in rows:
                doc = Document(**row)
                doc.users    = row[5].split(',')
                doc.usersdel = row[6].split(',')
                docs.append(doc.to_dict())
        except Exception as e:
            DatabaseException(e)
        else:
            return docs
Esempio n. 4
0
    def search(self, search_text):

        docs = []
        try:
            if (search_text is not None) and (not search_text == ''):
                self.cursor.execute('''SELECT * FROM %s
                                       WHERE keys LIKE '%s' ''' % (self.config['TABLE'],
                                                                   '%' + search_text + '%'))
                rows = self.cursor.fetchall()
                for row in rows:
                    doc = Document(**row)
                    doc.users    = row[5].split(',')
                    doc.usersdel = row[6].split(',')
                    docs.append(doc)
        except Exception as e:
            DatabaseException(e)
        else:
            return docs
Esempio n. 5
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import codecs
from lai import Client, Database, Document

client = Client(Database())
filename = '/home/xleo/src/tools12/trunk/scripts/lai/data'

with codecs.open(filename, 'r', encoding='latin1') as file:
    lines = file.readlines()
    count = 0
    for line in lines[1772:]:
        if line != '':
            doc = Document(line.strip())
            doc.set_keys(line)
            doc = client.save(doc)
            if count % 25 == 0:
                client.commit()
            count += 1