Commits

David Warburton committed 4aeea6b

Search for the correct folder where the script lives to save cache data instead of assuming we know the right filename.

Comments (0)

Files changed (1)

     admin_url_template = "https://%s:%s@%s.myshopify.com/admin"
     use_ssl = True
 
+for root, dirnames, filenames in os.walk(sublime.packages_path()):
+    if ('Shopify.py' in filenames):
+        PACKAGE_DIR = root
+
 PACKAGE_NAME = 'Shopify'
 
 def load():
     current_theme = None
 
     store_file = os.path.join(sublime.packages_path(), 'User', 'ShopifyStores.json')
-    cache_data_file = os.path.join(sublime.packages_path(), PACKAGE_NAME, 'cache_data.json')
+    cache_data_file = os.path.join(PACKAGE_DIR, 'cache_data.json')
     cache_data = {}
     if (os.path.exists(cache_data_file)):
         with open(cache_data_file) as f:
     if (not os.path.exists(store_file)):
         with open(store_file, 'w') as f:
             f.write(store_template)
-            return
 
     with open(store_file) as f:
         store_data = json.load(f)
 
     bad_values = []
-    if (len(store_data) == 1 and False):
+    if (len(store_data) == 1):
         only_store = store_data.values()[0]
         if (only_store["API_KEY"]      == "API-KEY-HERE"):
             bad_values.append("API_KEY")
             bad_values.append("API_PASSWORD")
         if (only_store["SHOP_NAME"]    == "SHOP-NAME-AS-IT-APPEARS-IN-URLS" ):
             bad_values.append("SHOP_NAME")
-        return
+        if len(bad_values) > 0: return
     
     stores = []
     for name, data in store_data.iteritems():
         stores.append(Shop(name, data))
 
-
 class Shop:
     def __init__(self, name, shop_data):
         self.name         = shop_data['SHOP_NAME']
         json.dump(cache_data, f)
 
 def cache_root():
-    return os.path.join(sublime.packages_path(),PACKAGE_NAME,'cache')
+    return os.path.join(PACKAGE_DIR,'cache')
 
 class ShopifyUploadOnSave(sublime_plugin.EventListener):
     def on_post_save(self, view):