Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Vladislav Rykov
THSO.server
Commits
51f76a47
Commit
51f76a47
authored
Apr 17, 2020
by
Vladislav Rykov
Browse files
database configuration added
parent
6220f3d4
Changes
3
Show whitespace changes
Inline
Side-by-side
db.conf
0 → 100644
View file @
51f76a47
{
"name"
:
"gateway"
,
"user"
:
"pi"
,
"password"
:
"dev"
,
"host"
:
"localhost"
,
"port"
:
5432
}
misc.py
View file @
51f76a47
from
binascii
import
hexlify
from
binascii
import
hexlify
import
os
import
os
import
psycopg2
import
json
def
rand_str
(
length
):
def
rand_str
(
length
):
if
length
%
2
==
0
:
if
length
%
2
==
0
:
...
@@ -39,12 +41,18 @@ def prep_id_range(devlist):
...
@@ -39,12 +41,18 @@ def prep_id_range(devlist):
s
+=
str
(
r
[
-
1
])
+
']'
s
+=
str
(
r
[
-
1
])
+
']'
return
s
return
s
import
psycopg2
# decorator implementation
# decorator implementation
def
with_psql
(
f
):
def
with_psql
(
f
):
def
_with_psql
(
*
args
,
**
kwargs
):
def
_with_psql
(
*
args
,
**
kwargs
):
conn
=
psycopg2
.
connect
(
'dbname=gateway'
)
db_conf
=
read_json_file
(
'db.conf'
)
conn
=
psycopg2
.
connect
(
database
=
db_conf
[
'name'
],
user
=
db_conf
[
'user'
],
password
=
db_conf
[
'password'
],
host
=
db_conf
[
'host'
],
port
=
db_conf
[
'port'
]
)
cur
=
conn
.
cursor
()
cur
=
conn
.
cursor
()
try
:
try
:
...
@@ -61,3 +69,12 @@ def with_psql(f):
...
@@ -61,3 +69,12 @@ def with_psql(f):
return
res
return
res
return
_with_psql
return
_with_psql
def
read_json_file
(
path
):
json_dict
=
None
try
:
with
open
(
path
)
as
json_file
:
json_dict
=
json
.
load
(
json_file
)
except
Exception
,
e
:
print
(
"{} : {}"
.
format
(
path
,
e
))
return
json_dict
misc.pyc
View file @
51f76a47
No preview for this file type
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment