Skip to content

Commit

Permalink
changes for package control. Needs cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dvcrn committed Sep 18, 2015
1 parent 800058b commit 90f951f
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 21 deletions.
Empty file added __init__.py
Empty file.
Empty file added layers/__init__.py
Empty file.
Empty file added layers/core/__init__.py
Empty file.
1 change: 1 addition & 0 deletions layers/core/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class Layer():
name = "Core"

required_packages = [
"sublimious",
"Vintage-Origami",
"Vintageous",
"Origami",
Expand Down
Empty file added layers/git/__init__.py
Empty file.
Empty file added layers/javascript/__init__.py
Empty file.
Empty file added layers/markdown/__init__.py
Empty file.
Empty file added layers/osx/__init__.py
Empty file.
Empty file added layers/python/__init__.py
Empty file.
41 changes: 31 additions & 10 deletions lib/collector.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,59 @@
import itertools
import os
import shutil

from .io import load_python_file
from . import helpers
from .helpers import mergedicts

import zipfile


class Collector():
layers = []
collected_config = {}
user_config = {}
is_zip = False
zip_file = None

def __init__(self, sublimious_dir, user_dir=None):
if "sublime-package" in sublimious_dir:
self.is_zip = True
self.zip_file = zipfile.ZipFile(sublimious_dir)

def __init__(self, sublimious_dir):
config_path = os.path.expanduser("~/.sublimious")
if not os.path.exists(config_path):
template_path = "%s/%s" % (sublimious_dir, "templates/.sublimious")
shutil.copyfile(template_path, config_path)
if self.is_zip:
self.zip_file.extract("templates/.sublimious", config_path)
else:
template_path = "%s/%s" % (sublimious_dir, "templates/.sublimious")
shutil.copyfile(template_path, config_path)

print("[Sublimious] no config found. Copied template.")

config_file = load_python_file(config_path)

# Collect all layers and layer configurations
for layer in config_file.layers:
layer_init_file = "%s/%s/layer.py" % (sublimious_dir, "layers/%s" % layer)
layer_settings_file = "%s/%s/settings.py" % (sublimious_dir, "layers/%s" % layer)

layer_init = load_python_file(layer_init_file)
if self.is_zip:
layer_init = __import__("layers.%s.layer" % layer, globals(), locals(), ['Layer'])
else:
layer_init_file = "%s/%s/layer.py" % (sublimious_dir, "layers/%s" % layer)
layer_init = load_python_file(layer_init_file)

self.layers.append(layer_init.Layer())

settings = eval(open(layer_settings_file, 'r').read())
self.collected_config = helpers.mergedicts(self.collected_config, settings)
if self.is_zip:
settings = eval(self.zip_file.read("layers/%s/settings.py" % layer))
else:
layer_settings_file = "%s/%s/settings.py" % (sublimious_dir, "layers/%s" % layer)
settings = eval(open(layer_settings_file, 'r').read())

self.collected_config = mergedicts(self.collected_config, settings)

# Load user configuration on top
if (len(config_file.user_config) > 0):
self.collected_config = helpers.mergedicts(self.collected_config, config_file.user_config)
self.collected_config = mergedicts(self.collected_config, config_file.user_config)

self.user_config = config_file

Expand Down
12 changes: 7 additions & 5 deletions spacelistener.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import sys
import os
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
path = os.path.dirname(os.path.realpath(__file__))
sys.path.append(path)

import sublime_plugin
import sublime
import threading

from .lib.collector import Collector
from .lib import helpers
from .lib import collector

keys = {
"SPACE": "<space>",
Expand Down Expand Up @@ -166,7 +168,7 @@ def on_query_context(self, view, key, *args, **kwargs):


def plugin_loaded():
collector = Collector(os.path.dirname(os.path.realpath(__file__)))
coll = collector.Collector(os.path.dirname(os.path.realpath(__file__)))
SpaceListener.shortcut_panel = sublime.active_window().create_output_panel("sublimious_shortcut_panel")
SpaceListener.collector = collector
SpaceListener.settings = helpers.mergedicts(SpaceListener.settings, collector.get_collected_config())
SpaceListener.collector = coll
SpaceListener.settings = helpers.mergedicts(SpaceListener.settings, coll.get_collected_config())
21 changes: 15 additions & 6 deletions sublimious.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import sys
import os
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
path = os.path.dirname(os.path.realpath(__file__))
is_zip = False

if "sublime-package" in path:
is_zip = True

sys.path.append(path)

import sublime
import json

from .lib.io import write_sublimious_file
from .lib.collector import Collector
from .lib.io import write_sublimious_file


def plugin_loaded():
Expand All @@ -32,9 +39,11 @@ def plugin_loaded():
status_panel.run_command("status", {"text": "Welcome to Sublimious."})

# Nuke everything
settings_current = [os.path.join(current_path, f) for f in os.listdir(current_path) if f.endswith(".sublime-settings")]
settings_user = [os.path.join(user_dir, f) for f in os.listdir(user_dir) if f.endswith(".sublime-settings")]
filelist = settings_current + settings_user
filelist = settings_user
if not is_zip:
settings_current = [os.path.join(current_path, f) for f in os.listdir(current_path) if f.endswith(".sublime-settings")]
filelist = settings_current + settings_user
for f in filelist:
os.remove(f)

Expand All @@ -51,12 +60,12 @@ def plugin_loaded():

# Get all keybinding definitions and save to keymapfile
status_panel.run_command("status", {"text": "Building keymap..."})
write_sublimious_file("%s/Default.sublime-keymap" % current_path, json.dumps(collector.collect_key("sublime_keymap")))
write_sublimious_file("%s/Default.sublime-keymap" % user_dir, json.dumps(collector.collect_key("sublime_keymap")))

# Generate a bunch of syntax files depending on layer config
syntax_definitions = collector.collect_syntax_specific_settings()
for syntax, value in syntax_definitions.items():
write_sublimious_file("%s/%s.sublime-settings" % (current_path, syntax), json.dumps(value))
write_sublimious_file("%s/%s.sublime-settings" % (user_dir, syntax), json.dumps(value))
status_panel.run_command("status", {"text": "Collected %s syntax definition..." % syntax})

# Generate package specific settings
Expand Down

0 comments on commit 90f951f

Please sign in to comment.