Skip to content

Commit

Permalink
Added log file auto deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Blumberg committed Sep 21, 2019
1 parent 7576b7f commit 12cac82
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions runsharp/full_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,17 @@
import platform

HOME_DIR = os.path.join(os.path.expanduser("~"), ".sharppy")
LOG_FILE = os.path.join(HOME_DIR, 'sharppy.log')
if not os.path.isdir(HOME_DIR):
os.mkdir(HOME_DIR)

if os.path.exists(LOG_FILE):
log_file_size = os.path.getsize(LOG_FILE)
MAX_FILE_SIZE = 1024 * 1024
if log_file_size > MAX_FILE_SIZE:
# Delete the log file as it's grown too large
os.remove(LOG_FILE)

HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
Expand All @@ -47,7 +55,7 @@
# Start the logging
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(pathname)s %(funcName)s Line #: %(lineno)d %(levelname)-8s %(message)s',
filename=HOME_DIR + '/sharppy.log',
filename=LOG_FILE,
filemode='w')
console = logging.StreamHandler()
# set a format which is simpler for console use
Expand All @@ -71,11 +79,13 @@
if frozenutils.isFrozen():
if not os.path.exists(HOME_DIR):
os.makedirs(HOME_DIR)

BINARY_VERSION = True
outfile = open(os.path.join(HOME_DIR, 'sharppy-out.txt'), 'w')

console.setLevel(logging.DEBUG)
sys.stdout = outfile
sys.stderr = outfile
else
BINARY_VERSION = False

__version__ = get_versions()['version']
ver = get_versions()
Expand All @@ -87,10 +97,13 @@
logging.info('qtpy version: ' + str(qtpy.__version__))
logging.info("Python version: " + str(platform.python_version()))
logging.info("Qt version: " + str(qtpy.QtCore.__version__))

logging.info("OS version: " + str(platform.platform()))
# from sharppy._version import __version__#, __version_name__

__version_name__ = ''
if BINARY_VERSION:
logging.info("This is a binary version of SHARPpy.")

__version_name__ = 'Andover'
try:
from netCDF4 import Dataset
has_nc = True
Expand Down Expand Up @@ -871,7 +884,7 @@ def __initUI(self):
self.raise_()
import time
time.sleep(3)
QPixmap.grabWidget(self).save('./screenshot.png', 'png')
self.grab().save('./screenshot.png', 'png')

def createMenuBar(self):
"""
Expand Down

0 comments on commit 12cac82

Please sign in to comment.