[chronojump/chronojump-importer] Adds Python2 compatibility.
- From: Carles Pina i Estany <carlespina src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump/chronojump-importer] Adds Python2 compatibility.
- Date: Fri, 9 Sep 2016 16:36:48 +0000 (UTC)
commit ef573d22ccc061faf0ea831be659b993a19c0103
Author: Carles Pina i Estany <carles pina cat>
Date: Fri Sep 9 17:36:30 2016 +0100
Adds Python2 compatibility.
src/chronojump-importer/chronojump_importer.py | 21 +++++++++++++--------
1 files changed, 13 insertions(+), 8 deletions(-)
---
diff --git a/src/chronojump-importer/chronojump_importer.py b/src/chronojump-importer/chronojump_importer.py
index 7a018c3..0b6b945 100755
--- a/src/chronojump-importer/chronojump_importer.py
+++ b/src/chronojump-importer/chronojump_importer.py
@@ -323,16 +323,21 @@ class Database:
data_row.set('new_' + column_name, data_row.get(column_name))
def open_database(self, filename, read_only):
- """Opens the database specified by filename. If read_only is True
- the database cannot be changed.
+ """Opens the database specified by filename. On Python3 If read_only is True
+ the database is opened in read only mode
"""
- if read_only:
- mode = "ro"
- else:
- mode = "rw"
+ if sys.version_info >= (3, 0):
+ if read_only:
+ mode = "ro"
+ else:
+ mode = "rw"
- uri = "file:{}?mode={}".format(filename,mode)
- self._conn = sqlite3.connect(uri, uri=True)
+ uri = "file:{}?mode={}".format(filename,mode)
+ self._conn = sqlite3.connect(uri, uri=True)
+ else:
+ # On Python2 there is no uri support. This opens
+ # the database always on rw
+ self._conn = sqlite3.connect(filename)
self._conn.execute("pragma foreign_keys=ON")
self._cursor = self._conn.cursor()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]