Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
energy
bmon
Commits
34b2118d
Commit
34b2118d
authored
Jan 30, 2015
by
Alan Mitchell
Browse files
Adjusted path in readingdb scripts.
parent
7ba3fec6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
12 deletions
+18
-12
bmsapp/global_vars.py
bmsapp/global_vars.py
+1
-1
bmsapp/readingdb/scripts/backup.py
bmsapp/readingdb/scripts/backup.py
+12
-7
bmsapp/readingdb/scripts/daily_status.py
bmsapp/readingdb/scripts/daily_status.py
+3
-2
bmsapp/readingdb/scripts/import_readings.py
bmsapp/readingdb/scripts/import_readings.py
+2
-2
No files found.
bmsapp/global_vars.py
View file @
34b2118d
'''
This file holds settings for the application
This file holds settings for the application
and sets up logging.
'''
from
os.path
import
dirname
,
join
,
realpath
from
glob
import
glob
...
...
bmsapp/readingdb/scripts/backup.py
View file @
34b2118d
...
...
@@ -11,17 +11,22 @@ import shutil
import
subprocess
import
glob
SENSOR_DB
=
'bms_data.sqlite'
# change into the directory of this script
os
.
chdir
(
os
.
path
.
dirname
(
sys
.
argv
[
0
]))
# make backup filename with current date time
fname
=
'bak/'
+
time
.
strftime
(
'%Y-%m-%d-%H%M%S'
)
+
'.sqlite'
# get parent directory into path
sys
.
path
.
insert
(
0
,
'../'
)
import
bmsdata
# path to reading database
db_path
=
bmsdata
.
DEFAULT_DB
# make backup filename with current date time in 'bak' subdirectory
fname
=
os
.
path
.
join
(
os
.
path
.
dirname
(
db_path
),
'bak'
,
time
.
strftime
(
'%Y-%m-%d-%H%M%S'
)
+
'.sqlite'
)
# Before copying the database file, need to force a lock on it so that no
# write operations occur during the copying process
conn
=
sqlite3
.
connect
(
SENSOR_DB
)
conn
=
sqlite3
.
connect
(
db_path
)
cur
=
conn
.
cursor
()
# create a dummy table to write into.
...
...
@@ -35,7 +40,7 @@ except:
cur
.
execute
(
'INSERT INTO _junk VALUES (1)'
)
# now copy database
shutil
.
copy
(
SENSOR_DB
,
fname
)
shutil
.
copy
(
db_path
,
fname
)
# Rollback the Insert as we don't really need it.
conn
.
rollback
()
...
...
@@ -45,6 +50,6 @@ subprocess.call(['gzip', fname])
# delete any backup files more than 3 weeks old
cutoff_time
=
time
.
time
()
-
3
*
7
*
24
*
3600.0
for
fn
in
glob
.
glob
(
'bak/
*.gz'
):
for
fn
in
glob
.
glob
(
os
.
path
.
join
(
os
.
path
.
dirname
(
db_path
),
'bak'
,
'
*.gz'
)
)
:
if
os
.
path
.
getmtime
(
fn
)
<
cutoff_time
:
os
.
remove
(
fn
)
bmsapp/readingdb/scripts/daily_status.py
View file @
34b2118d
...
...
@@ -5,9 +5,10 @@ import os, sys, logging, time
# change into this directory
os
.
chdir
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
sys
.
argv
[
0
])
))
sys
.
path
.
insert
(
0
,
'../../'
)
# add the parent/parent directory to the Python path
sys
.
path
.
insert
(
0
,
'../'
)
# add the parent directory to the Python path
from
readingdb
import
bmsdata
import
global_vars
# needed to set up logging
import
bmsdata
# make a logger object and set time zone so log readings are stamped with Alaska time.
# Did this because Django sets time to AK time.
...
...
bmsapp/readingdb/scripts/import_readings.py
View file @
34b2118d
...
...
@@ -28,10 +28,10 @@ import sys, glob
# Add the parent directory to the Python import path
sys
.
path
.
insert
(
0
,
'../'
)
import
bmsapp.readingdb.
bmsdata
import
bmsdata
# Open reading database object
db
=
bmsapp
.
readingdb
.
bmsdata
.
BMSdata
()
db
=
bmsdata
.
BMSdata
()
for
filename
in
glob
.
glob
(
sys
.
argv
[
1
]):
success_count
,
errors
=
db
.
import_text_file
(
filename
)
...
...
Write
Preview
Markdown
is supported
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