Skip to content

Commit

Permalink
Merge pull request mtxr#206 from evandroforks/stop_creating_settings
Browse files Browse the repository at this point in the history
Don't create an empty settings file if one does not exist
  • Loading branch information
tkopets authored Mar 4, 2019
2 parents 9ba95d3 + 83de670 commit c4d8be2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
14 changes: 2 additions & 12 deletions SQLTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ def startPlugin():
settings = Settings(SETTINGS_FILENAME, default=SETTINGS_FILENAME_DEFAULT)
except Exception as e:
msg = '{0}: Failed to parse {1} file'.format(__package__, SQLTOOLS_SETTINGS_FILE)
logging.error(msg + "\nError: " + str(e))
logging.exception(msg)
Window().status_message(msg)

try:
connections = Settings(CONNECTIONS_FILENAME, default=CONNECTIONS_FILENAME_DEFAULT)
except Exception as e:
msg = '{0}: Failed to parse {1} file'.format(__package__, SQLTOOLS_CONNECTIONS_FILE)
logging.error(msg + "\nError: " + str(e))
logging.exception(msg)
Window().status_message(msg)

queries = Storage(QUERIES_FILENAME, default=QUERIES_FILENAME_DEFAULT)
Expand Down Expand Up @@ -763,16 +763,6 @@ def reload():


def plugin_loaded():
# this ensures we have empty settings file in 'User' directory during first start
# otherwise sublime will copy entire contents of 'SQLTools.sublime-settings'
# which is not desirable and prevents future changes to queries and other
# sensible defaults defined in settings file, as those would be overridden by content
# from older versions of SQLTools in 'User\SQLTools.sublime-settings'
sublimeUserFolder = getSublimeUserFolder()
userSettingFile = os.path.join(sublimeUserFolder, SQLTOOLS_SETTINGS_FILE)
if not os.path.isfile(userSettingFile):
# create empty settings file in 'User' folder
sublime.save_settings(SQLTOOLS_SETTINGS_FILE)

try:
from package_control import events
Expand Down
11 changes: 8 additions & 3 deletions SQLToolsAPI/Storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ def __init__(self, filename, default=None):
self.items = {}

# copy entire file, to keep comments
if not os.path.isfile(filename) and default and os.path.isfile(default):
shutil.copyfile(default, filename)
# if not os.path.isfile(filename) and default and os.path.isfile(default):
# shutil.copyfile(default, filename)

self.all()

def all(self):
self.items = U.parseJson(self.getFilename())
userFile = self.getFilename()

if os.path.exists(userFile):
self.items = U.parseJson(self.getFilename())
else:
self.items = {}

return U.merge(self.items, self.defaults())

Expand Down

0 comments on commit c4d8be2

Please sign in to comment.