Commits

David Warburton  committed 679ba41

Move the store definitions to the user dir.
Generate the file if it does not exist.
Reload the file when it is saved.

  • Participants
  • Parent commits 73780b7

Comments (0)

Files changed (3)

 import dateutil, yaml, shopify
 import json, os, threading, re
 
-with open('Stores.json') as f:
-    stores = json.load(f)
+def load():
+    global stores, store_keys, current_store, current_theme, api_lock
+    store_template = """{
+    "Human Readable Shop Name":{
+        "API_KEY": "API-KEY-HERE",
+        "API_PASSWORD": "API-PASSWORD-HERE",
+        "SHOP_NAME": "SHOP-NAME-AS-IT-APPEARS-IN-URLS"
+    }
+}
+"""
+    store_file = os.path.join(sublime.packages_path(), 'User', 'ShopifyStores.json')
 
-store_keys = [x for x in stores]
-current_store = None
-current_theme = None
-api_lock = threading.Lock()
+    stores = None
+
+    if (not os.path.exists(store_file)):
+        with open(store_file, 'w') as f:
+            f.write(store_template)
+
+    with open(store_file) as f:
+        stores = json.load(f)
+    
+    if (len(stores.keys()) == 1 and "Human Readable Shop Name" in stores.keys()):
+        stores = None
+        return
+
+    store_keys = [x for x in stores]
+    current_store = None
+    current_theme = None
+    api_lock = threading.Lock()
 
 def connect(shop):
     shopify.ShopifyResource.site = "https://%s:%s@%s.myshopify.com/admin" % (shop['API_KEY'], shop['API_PASSWORD'], shop['SHOP_NAME'])
 
 class ShopifyShowStoresCommand(sublime_plugin.WindowCommand):
     def run(self):
+        if (not stores):
+            self.window.run_command('open_file', {"file": "${packages}/User/ShopifyStores.json"})
+            return
+
         commands = ["Shopify: Browse Themes - %s" % x for x in store_keys]
         def on_shop_select(picked):
             if picked == -1:
 
 class ShopifyShowThemesCommand(sublime_plugin.WindowCommand):
     def run(self):
+        if (not stores):
+            self.window.run_command('open_file', {"file": "${packages}/User/ShopifyStores.json"})
+            return
+
         if (current_store == None):
             self.window.run_command('shopify_show_stores')
             return
 
 class ShopifyShowAssetsCommand(sublime_plugin.WindowCommand):
     def run(self):
+        if (not stores):
+            self.window.run_command('open_file', {"file": "${packages}/User/ShopifyStores.json"})
+            return
+
         if (current_store == None):
             self.window.run_command('shopify_show_stores')
             return
             key = "%s/%s" %(asset_type, asset_name)
             pusher = ShopifyPusher(store, theme_id, key, view.file_name())
             pusher.start()
+        elif (os.path.basename(view.file_name()) == 'ShopifyStores.json'):
+            load()
 
 class ShopifyPusher(threading.Thread):
     def __init__(self, store, theme_id, key, filename):
         api_lock.release()
         self.result = True
 
+load()

File Shopify.sublime-commands

         "caption": "Shopify: Edit store information",
 		"command": "open_file", "args":
         {
-            "file": "${packages}/Shopify/Stores.json"
+            "file": "${packages}/User/ShopifyStores.json"
         }
     },
     {

File Stores.json

-{
-    "Human Readable Shop Name":{
-    	"API_KEY": "API-KEY-HERE",
-		"API_PASSWORD": "API-PASSWORD-HERE",
-		"SHOP_NAME": "SHOP-NAME-AS-IT-APPEARS-IN-URLS"
-    }
-}