Skip to content

Commit 5529155

Browse files
author
stephanie
committed
merge logging
2 parents 2bb8c9e + 4997af4 commit 5529155

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+338
-171
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ setup/Output/setup.exe
6363

6464
#folders
6565
Temp
66+
6667
*.app
6768
*.spec
6869

.travis.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,19 @@ addons:
4141
- wx2.8-headers
4242
- wx2.8-i18n
4343

44+
4445
# mariadb: '10.1'
4546
before_script:
4647
- ./ci-helpers/travis/mysql_setup.sh
4748
- ./ci-helpers/travis/postgres_setup.sh
4849
- ./ci-helpers/travis/freetds.sh
4950

51+
5052
before_install:
5153
# python -m pip makes the install go into the virtualenv
5254
- python -m pip install pandas
5355
- export PYMSSQL_BUILD_WITH_BUNDLED_FREETDS=1;python -m pip install pymssql
56+
5457
# - python -m pip install mysql-python
5558
install: # now just our code
5659
- pip install geoalchemy2
@@ -60,8 +63,17 @@ install: # now just our code
6063
# don't forget to open up the azure mssql server to these addreses
6164
# https://docs.travis-ci.com/user/ip-addresses/
6265

66+
# mariadb: '10.1'
67+
before_script:
68+
- chmod +x ./tests/scripts/mysql_setup.sh
69+
# - chmod +x ./tests/scripts/postgres_setup.sh
70+
- chmod +x ./tests/scripts/freetds.sh
71+
- ./tests/scripts/mysql_setup.sh
72+
# - ./tests/scripts/postgres_setup.sh
73+
- ./tests/scripts/freetds.sh
74+
6375
# command to run tests
6476
script:
65-
77+
# - pythonw -m pytest
6678
- py.test
6779

ODMTools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import psycopg2
2424

2525
tool = LoggerTool()
26-
logger = tool.setupLogger(__name__, __name__ + '.log', 'w', logging.DEBUG)
26+
logger = tool.setupLogger('main', 'odmtools.log', 'a', logging.INFO)
2727
wx.Log.SetLogLevel(0)
2828

2929

@@ -67,7 +67,7 @@ def runODM():
6767
app.MainLoop()
6868

6969
if __name__ == '__main__':
70-
logger.debug("Welcome to ODMTools Python. Please wait as system loads")
70+
logger.info("Welcome to ODMTools Python. Please wait as system loads")
7171
# https://docs.python.org/2/library/multiprocessing.html#miscellaneous
7272

7373
# Add support for when a program which uses multiprocessing has been frozen to produce a Windows executable.

ci-helpers/travis/mysql_setup.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ mysql -e "create database IF NOT EXISTS odm2test;" --user=root
2121
#####
2222
# install
2323
#####
24-
ls -al ./tests/scripts/sampledb/odm_mysql.sql ./tests/scripts/sampledb/odm_postgresql.sql
24+
ls -al ./tests/scripts/sampledb/odm_mysql.sql ./tests/scripts/sampledb/odm_postgres.sql
2525
mysql --user=ODM --password=odm odm < ./tests/scripts/sampledb/odm_mysql.sql
2626
mysql --user=root -e "show databases;"
2727
mysql --user=root -e "GRANT ALL PRIVILEGES ON odm.* TO 'ODM'@'localhost';FLUSH PRIVILEGES;"
2828
# these should produce results, if they don't the lower_case_table_names failed
2929
# should make them grep or sed for some keywords
3030
mysql --user=ODM --password=odm odm -e "use odm; Select * from Variables;"
31-
mysql --user=ODM --password=odm odm -e "Select * from Variables;"
32-
mysql --user=ODM --password=odm -e "Select * from Variables;"
31+
mysql --user=ODM --password=odm odm -e "use odm; Select * from Variables;"
32+
mysql --user=ODM --password=odm -e "use odm; Select * from Variables;"

ci-helpers/travis/postgres_setup.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
psql -U postgres -c "create extension postgis"
33
psql -c 'DROP DATABASE IF EXISTS odmtest;' -U postgres;
44
psql -c 'create database odmtest;' -U postgres;
5-
#psql -U postgres -d odmtest -a -f ./tests/scripts/sampledb/odm_postgresql.sql
5+
#psql -U postgres -d odmtest -a -f ./tests/scripts/sampledb/odm_postgres.sql
66
psql -c 'DROP DATABASE IF EXISTS odm;' -U postgres;
77
psql -c 'create database odm;' -U postgres;
88
## install
99
# add -a to psql to see full log, -q is quiet
10-
psql -U postgres -q -f ./tests/scripts/sampledb/odm_postgresql.sql
10+
psql -U postgres -q -f ./tests/scripts/sampledb/odm_postgres.sql

odmtools/common/logger.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,33 @@
1515
class LoggerTool():
1616
def __init__(self):
1717
self.formatString = '%(asctime)s - %(levelname)s - %(name)s.%(funcName)s() (%(lineno)d): %(message)s'
18-
self.formatString1 = '%(asctime)s (%(levelname)s) %(module)s:%(funcName)s.%(name)s(%(lineno)d) - %(message)s'
18+
self.formatString1 = '%(asctime)s (%(levelname)s) %(module)s:%(funcName)s(%(lineno)d) - %(message)s'
19+
self.formatString2 ='%(asctime)s - %(levelname)s - %(module)s - %(message)s'
1920

2021
def setupLogger(self, loggerName, logFile, m='w', level=logging.INFO):
2122
l = logging.getLogger(loggerName)
2223
# formatter = logging.Formatter('%(asctime)s : %(message)s')
23-
formatter = logging.Formatter(self.formatString)
24+
formatter = logging.Formatter(self.formatString1)
2425

25-
#logPath = os.path.abspath(os.path.dirname("../../"))
26-
#logPath = util.resource_path("ODMTools")
27-
logPath = user_log_dir("ODMTools", "UCHIC")
2826

29-
#logPath = os.path.join(user_log_dir("ODMTools", "UCHIC"), "log")
30-
#print logPath
27+
streamHandler = logging.StreamHandler()
28+
streamHandler.setFormatter(formatter)
29+
30+
l.setLevel(level)
31+
#l.setLevel(20) #Set logger to 20 to hide debug statements
32+
l.addHandler(streamHandler)
33+
3134

35+
36+
logPath = user_log_dir("ODMTools", "UCHIC")
3237
if not os.path.exists(logPath):
3338
os.makedirs(logPath, 0755)
3439
fileHandler = logging.FileHandler(os.path.join(logPath, logFile), mode=m)
3540
fileHandler.setFormatter(formatter)
36-
streamHandler = logging.StreamHandler()
37-
streamHandler.setFormatter(formatter)
3841

39-
l.setLevel(level)
40-
#l.setLevel(20) #Set logger to 20 to hide debug statements
42+
# l.setLevel(logging.ERROR)
4143
l.addHandler(fileHandler)
42-
l.addHandler(streamHandler)
44+
4345

4446
# solves issues where logging would duplicate its logging message to the root logger
4547
# https://stackoverflow.com/questions/21127360/python-2-7-log-displayed-twice-when-logging-module-is-used-in-two-python-scri

odmtools/common/taskServer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
from odmtools.common.logger import LoggerTool
1010

1111

12-
tool = LoggerTool()
13-
logger = tool.setupLogger(__name__, __name__ + '.log', 'w', logging.DEBUG)
12+
# tool = LoggerTool()
13+
# logger = tool.setupLogger(__name__, __name__ + '.log', 'w', logging.DEBUG)
14+
logger =logging.getLogger('main')
1415

1516
class TaskServerMP:
1617
"""

odmtools/controller/frmAddPoints.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from agw import genericmessagedialog as GMD
88
except ImportError:
99
import wx.lib.agw.genericmessagedialog as GMD
10+
import logging
11+
logger =logging.getLogger('main')
1012

1113
# Implementing AddPoints
1214
class AddPoints(clsAddPoints.AddPoints):
@@ -79,6 +81,7 @@ def onDeleteBtn(self, event):
7981
value = msg.ShowModal()
8082
if value == wx.ID_YES:
8183
self.customRemove(self.selectedObject)
84+
8285
#self.sb.SetStatusText("Removing %s" % self.sb.SetStatusText("Removing %s" % self.selectedObject.dataValue))
8386

8487
self.selectedObject = None

odmtools/controller/frmBulkInsert.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
from pandas.parser import CParserError
99
import csv
1010
import StringIO
11-
11+
import logging
12+
logger =logging.getLogger('main')
1213
__author__ = 'Jacob'
1314

1415

@@ -63,12 +64,14 @@ def readDataFromCSV(self, filepath):
6364
8: str.strip,
6465
9: str.strip})
6566
except CParserError as e:
66-
67-
msg = wx.MessageDialog(None, "There was an issue trying to parse your file. "
68-
"Please compare your csv with the template version as the file"
69-
" you provided "
70-
"doesn't work: %s" % e, 'Issue with csv', wx.OK | wx.ICON_WARNING |
67+
message = "There was an issue trying to parse your file. "\
68+
"Please compare your csv with the template version as the file"\
69+
" you provided "\
70+
"doesn't work: %s" % e
71+
msg = wx.MessageDialog(None,message , 'Issue with csv', wx.OK | wx.ICON_WARNING |
7172
wx.OK_DEFAULT)
73+
74+
logger.info(message)
7275
value = msg.ShowModal()
7376
return False
7477

@@ -97,11 +100,13 @@ def loadIntoDataFrame(self, data):
97100

98101
except TypeError as e:
99102
dlg.Destroy()
100-
msg = wx.MessageDialog(None, "There was an issue trying to parse your file. "
101-
"Please check to see if there could be more columns or"
102-
" values than"
103-
" the program expects",
103+
message = "There was an issue trying to parse your file. "\
104+
"Please check to see if there could be more columns or"\
105+
" values than"\
106+
" the program expects"
107+
msg = wx.MessageDialog(None, message,
104108
'Issue with csv', wx.OK | wx.ICON_WARNING | wx.OK_DEFAULT)
109+
logger.info(message)
105110
value = msg.ShowModal()
106111
return False
107112

odmtools/controller/frmDBConfig.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
sys.path.append(directory)
1515
'''
1616

17-
tool = LoggerTool()
18-
logger = tool.setupLogger(__name__, __name__ + '.log', 'w', logging.DEBUG)
17+
# tool = LoggerTool()
18+
# logger = tool.setupLogger(__name__, __name__ + '.log', 'w', logging.DEBUG)
19+
logger =logging.getLogger('main')
1920

2021
class frmDBConfig(wx.Dialog):
2122
def __init__(self, parent, service_manager, is_main=False):
@@ -54,7 +55,7 @@ def OnValueChanged(self, event):
5455
curr_dict = self.getFieldValues()
5556
if self.conn_dict == curr_dict:
5657
self.btnSave.Enable(True)
57-
except:
58+
except Exception as e:
5859
pass
5960

6061

0 commit comments

Comments
 (0)