20 from ..preferences.settings
import SETTINGS_DIRECTORY
21 from ..spec.iteminfo
import LibraryKeywordInfo
22 from ..lib.robot.utils
import system_decode
24 CREATION_SCRIPT =
"""\
25 CREATE TABLE libraries (id INTEGER PRIMARY KEY,
30 CREATE TABLE keywords (name TEXT,
35 FOREIGN KEY(library) REFERENCES libraries(id));
43 print(
'Creating librarykeywords database to "%s"' % DATABASE_FILE)
45 connection = sqlite3.connect(DATABASE_FILE)
46 connection.executescript(CREATION_SCRIPT)
52 connection = sqlite3.connect(DATABASE_FILE)
54 connection.execute(
'select id, name, doc_format, arguments,'
55 ' last_updated from libraries')
56 connection.execute(
'select name, doc, arguments, library_name,'
57 ' library from keywords')
63 if not os.path.exists(SETTINGS_DIRECTORY):
64 os.makedirs(SETTINGS_DIRECTORY)
65 if not os.path.exists(DATABASE_FILE):
70 except sqlite3.DatabaseError
as err:
71 print(
'removing database "%s"' % DATABASE_FILE)
72 print(
'error during database validation "%s"' % err)
74 os.remove(DATABASE_FILE)
75 except Exception
as err:
76 print(
'failed to remove database "%s"' % DATABASE_FILE)
84 self.
_connection_connection = sqlite3.connect(database, timeout=30.0)
87 self.
_cursor_cursor().executescript(CREATION_SCRIPT)
98 library_doc_format =
"ROBOT"
100 library_doc_format = keywords[0].doc_format
106 old_versions = cur.execute(
'select id from libraries where name = ? '
109 str(library_arguments))).fetchall()
110 cur.executemany(
'delete from keywords where library = ?', old_versions)
111 cur.executemany(
'delete from libraries where id = ?', old_versions)
112 lib = self.
_insert_library_insert_library(library_name, library_doc_format,
113 library_arguments, cur)
114 keyword_values = [[kw.name, kw.doc,
u' | '.join(kw.arguments),
116 lib[0]]
for kw
in keywords
if kw
is not None]
121 self.
_cursor_cursor().execute(
'update libraries set last_updated = ?'
122 ' where name = ? and arguments = ?',
123 (milliseconds
or time.time(), name,
128 lib = self.
_fetch_lib_fetch_lib(library_name, library_arguments, self.
_cursor_cursor())
132 arguments.split(
u' | ')
if arguments
else [])
133 for name, doc, arguments, library_name
in
134 self.
_connection_connection.execute(
'select name, doc, arguments,'
135 ' library_name from keywords where'
136 ' library = ?', [lib[0]])]
139 return self.
_fetch_lib_fetch_lib(library_name, library_arguments,
140 self.
_cursor_cursor())
is not None
143 lib = self.
_fetch_lib_fetch_lib(library_name, library_arguments, self.
_cursor_cursor())
149 cursor.execute(
'insert into libraries values (null, ?, ?, ?, ?)',
150 (name, doc_format, str(arguments), time.time()))
151 return self.
_fetch_lib_fetch_lib(name, arguments, cursor)
154 t = cursor.execute(
'select max(last_updated) from libraries where name'
155 ' = ? and arguments = ?',
156 (name, str(arguments))).fetchone()[0]
157 return cursor.execute(
'select * from libraries where name = ?'
158 ' and arguments = ? and last_updated = ?',
159 (name, str(arguments), t)).fetchone()
162 cursor.executemany(
'insert into keywords values (?, ?, ?, ?, ?)', data)
def library_exists(self, library_name, library_arguments)
def __init__(self, database)
def fetch_library_keywords(self, library_name, library_arguments)
def create_database(self)
def insert_library_keywords(self, library_name, library_arguments, keywords)
def _insert_library_keywords(self, data, cursor)
def get_library_last_updated(self, library_name, library_arguments)
def _insert_library(self, name, doc_format, arguments, cursor)
def _fetch_lib(self, name, arguments, cursor)
def update_library_timestamp(self, name, arguments, milliseconds=None)
def system_decode(string)
Decodes bytes from system (e.g.
def initialize_database()