Skip to content

Commit

Permalink
Issue: #1
Browse files Browse the repository at this point in the history
Added default folders option values, if not have existing file or file not contains folders options value
Development status changes to Stable
  • Loading branch information
nazrulworld committed May 16, 2017
1 parent 1ee5bae commit 0bfc83f
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 27 deletions.
4 changes: 0 additions & 4 deletions README.rst
Expand Up @@ -10,10 +10,6 @@
:target: https://coveralls.io/r/nazrulworld/plone.recipe.sublimetext
:alt: Test Coverage

.. image:: https://img.shields.io/pypi/dm/plone.recipe.sublimetext.svg
:target: https://pypi.python.org/pypi/plone.recipe.sublimetext/
:alt: Downloads

.. image:: https://img.shields.io/pypi/pyversions/plone.recipe.sublimetext.svg
:target: https://pypi.python.org/pypi/plone.recipe.sublimetext/
:alt: Python Versions
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Expand Up @@ -8,5 +8,5 @@ line_length = 200
not_skip = __init__.py

[zest.releaser]
create-wheel = no
create-wheel = yes
register = yes
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -34,7 +34,7 @@ def read(*rnames):
# Get more from https://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[
'Environment :: Web Environment',
'Development Status :: 3 - Alpha',
'Development Status :: 5 - Production/Stable',
'Framework :: Plone',
'Framework :: Plone :: 4.3',
'Framework :: Plone :: 5.0',
Expand Down
31 changes: 29 additions & 2 deletions src/plone/recipe/sublimetext/recipes.py
Expand Up @@ -20,6 +20,12 @@
}
json_load_params = {}

default_st3_folders_settings = [
{
'path': '.'
}
]

if PY2:
json_dump_params['encoding'] = 'utf-8'
json_load_params['encoding'] = 'utf-8'
Expand Down Expand Up @@ -194,9 +200,13 @@ def _write_project_file(self, project_file, settings, overwrite=False):
# get comment cleaned (/* */) json string
json_string = json_comment.sub('', f.read().strip())
existing_st3_settings = json.loads(json_string, **json_load_params)
existing_st3_settings.update(settings)

settings = existing_st3_settings.copy()
if existing_st3_settings:
self._merge_settings(settings, existing_st3_settings)
settings = existing_st3_settings.copy()

if 'folders' not in settings:
settings['folders'] = default_st3_folders_settings

with open(project_file, 'w') as f:
json.dump(settings, f, **json_dump_params)
Expand All @@ -205,6 +215,23 @@ def _write_project_file(self, project_file, settings, overwrite=False):
# catching any json error
raise UserError(str(exc))

def _merge_settings(self, new_settings, existing_settings):
""" """

for key, value in new_settings.items():

try:
item = existing_settings[key]
if isinstance(value, dict) and (type(item) == type(value)):
self._merge_settings(value, item)
existing_settings[key] = item
else:
existing_settings[key] = value

except KeyError:
# New Item
existing_settings[key] = value


def uninstall(name, options):
""" """
Expand Down
27 changes: 8 additions & 19 deletions src/plone/recipe/sublimetext/template.json
@@ -1,33 +1,22 @@
{
"ST3_DEFAULTS": {
"show_line_endings": true,
"sublimelinter": false,
"tab_size": 4,
"translate_tabs_to_spaces": true,
"trim_automatic_white_space": true,
"trim_trailing_white_space_on_save": true
"sublimelinter": false
},
"ST3_FOLDER_OPTIONS": [
{
"path": "."
}
],
"SUBLIMELINTER_DEFAULTS": {
"@python": 3,
"linters": {}
},
"SUBLIMELINTER_FLAKE8_DEFAULTS": {
"@disable": false,
"args": [],
"builtins": "",
"excludes": [],
"ignore": "",
"jobs": "1",
"max-complexity": 15,
"max-line-length": 120,
"select": "",
"show-code": false
"@disable": false
},
"SUBLIMELINTER_PYLINTER_DEFAULTS": {
"@disable": false,
"args": [],
"paths": [],
"show-codes": false
"paths": []
},
"JEDI_DEFAULTS": {
"python_interpreter": "$project_path/bin/python",
Expand Down

0 comments on commit 0bfc83f

Please sign in to comment.