Skip to content

Commit

Permalink
Fix sandbox file opening, logging to log fixed folder
Browse files Browse the repository at this point in the history
  • Loading branch information
manuvarkey committed Apr 3, 2019
1 parent 5c739d2 commit 924f39e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
2 changes: 0 additions & 2 deletions com.kavilgroup.gestimator.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
"--socket=x11",
"--socket=wayland",
"--socket=fallback-x11",
"--share=network",
"--filesystem=host",
"--filesystem=xdg-run/dconf",
"--filesystem=~/.config/dconf:ro",
"--talk-name=ca.desrt.dconf",
Expand Down
11 changes: 7 additions & 4 deletions estimator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1160,15 +1160,16 @@ def do_open(self, files, hint):

def call_open(window, filename):
if window.finished_setting_up:
log.info('MainApp - do_open - call_open - Start')
window.on_open_project_clicked(None, filename)
log.info('MainApp - do_open - opened file ' + filename)
log.info('MainApp - do_open - call_open - opened file ' + filename)
return False
else:
return True

log.info('MainApp - do_open - Start')
self.activate()
if len(files) > 1:
if len(files) > 0:
filename = files[0].get_path()
GLib.timeout_add(500, call_open, self.window, filename)
log.info('MainApp - do_open - End')
Expand All @@ -1178,8 +1179,9 @@ def do_command_line(self, command_line):

def call_open(window, filename):
if window.finished_setting_up:
log.info('MainApp - do_command_line - call_open - Start')
window.on_open_project_clicked(None, filename)
log.info('MainApp - do_command_line - opened file ' + filename)
log.info('MainApp - do_command_line - call_open - opened file ' + filename)
return False
else:
return True
Expand All @@ -1188,7 +1190,8 @@ def call_open(window, filename):
options = command_line.get_arguments()
self.activate()
if len(options) > 1:
GLib.timeout_add(500, call_open, self.window, options[1])
filename = misc.uri_to_file(options[1])
GLib.timeout_add(500, call_open, self.window, filename)
log.info('MainApp - do_command_line - End')
return 0

Expand Down
20 changes: 15 additions & 5 deletions gestimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#
#

import sys, tempfile, logging
import sys, os, io, logging, appdirs

import gi
gi.require_version('Gtk', '3.0')
Expand All @@ -31,16 +31,15 @@
# Get logger object
log = logging.getLogger()

from estimator import MainApp
from estimator import MainApp, misc

if __name__ == '__main__':
# Setup logging

# Setup Logging to temporary file
log_file = tempfile.NamedTemporaryFile(mode='w', prefix='estimator_',
suffix='.log', delete=False)
log_file_temp = io.StringIO()
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
stream=log_file,level=logging.INFO)
stream=log_file_temp,level=logging.INFO)
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
stream=sys.stdout,level=logging.INFO)
# Logging to stdout
Expand All @@ -64,3 +63,14 @@ def handle_exception(exc_type, exc_value, exc_traceback):
log.info('Entering Gtk main loop')
app.run(sys.argv)
log.info('End Program Execution')

# Copy temporary logfile to log folder
dirs = appdirs.AppDirs(misc.PROGRAM_NAME, misc.PROGRAM_AUTHOR, version=misc.PROGRAM_VER)
log_dir = misc.posix_path(dirs.user_data_dir, 'logs')
log_file = misc.posix_path(log_dir, misc.PROGRAM_NAME + '.log')
if not os.path.exists(log_dir):
os.makedirs(log_dir)
with open(log_file, 'w') as fobj:
fobj.write(log_file_temp.getvalue())


0 comments on commit 924f39e

Please sign in to comment.