Skip to content

Commit

Permalink
New plugin data folder and logfile path
Browse files Browse the repository at this point in the history
Migrate to the new locations for plugin data and log files.
  • Loading branch information
markwal committed Jun 24, 2015
1 parent c4aa2e7 commit 5025694
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
23 changes: 17 additions & 6 deletions octoprint_GPX/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,21 @@ class GPXPlugin(
):
def on_after_startup(self):
from .iniparser import IniParser
profile_folder = os.path.join(self._settings.global_get_basefolder("base"), "gpxProfiles")
if not os.path.isdir(profile_folder):
os.makedirs(profile_folder)
profile_path = os.path.join(profile_folder, "gpx.ini")
old_data_folder = os.path.join(self._settings.global_get_basefolder("base"), "gpxProfiles")
data_folder = self._settings.get_plugin_data_folder()
if os.path.isdir(old_data_folder):
# migrate old folder to new one
if os.path.isdir(data_folder) and len(os.listdir(data_folder)) > 0:
self._logger.warn("Both old ({old}) and new ({new}) data folders exist. Not migrating to avoid data loss.".format(
old=old_data_folder, new=data_folder))
else:
import shutil
if os.path.isdir(data_folder):
os.rmdir(data_folder)
shutil.move(old_data_folder, data_folder)
elif not os.path.isdir(data_folder):
os.makedirs(data_folder)
profile_path = os.path.join(data_folder, "gpx.ini")
self.iniparser = IniParser(profile_path, self._logger)
self.printer = None

Expand Down Expand Up @@ -110,8 +121,8 @@ def get_assets(self):
)

def fetch_machine_ini(self, machineid):
profile_folder = os.path.join(self._settings.global_get_basefolder("base"), "gpxProfiles")
profile_path = os.path.join(profile_folder, machineid + ".ini")
data_folder = self._settings.get_plugin_data_folder()
profile_path = os.path.join(data_folder, machineid + ".ini")
from .iniparser import IniParser
machine_ini = IniParser(profile_path, self._logger)
if os.path.isdir(profile_folder) and os.path.exists(profile_path) and os.path.isfile(profile_path):
Expand Down
8 changes: 3 additions & 5 deletions octoprint_GPX/gpxprinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ def __init__(self, logger = None, settings = None, printer = None, port = None,
self._logger.info("GPXPrinter created, port: %s, baudrate: %s" % (self.port, self.baudrate))
self.outgoing = Queue.Queue()
self.baudrateError = False;
profile_folder = os.path.join(self._settings.global_get_basefolder("base"), "gpxProfiles")
if not os.path.isdir(profile_folder):
os.makedirs(profile_folder)
self.profile_path = os.path.join(profile_folder, "gpx.ini")
log_path = os.path.join(self._settings.global_get_basefolder("logs"), "gpx.log")
data_folder = self._settings.get_plugin_data_folder()
self.profile_path = os.path.join(data_folder, "gpx.ini")
log_path = self._settings.get_plugin_logfile_path()
try:
self._append(gpx.connect(port, baudrate, self.profile_path, log_path,
self._logger.getEffectiveLevel() == logging.DEBUG))
Expand Down

0 comments on commit 5025694

Please sign in to comment.