Commits

David Warburton committed 73780b7

Status messages added.

Comments (0)

Files changed (1)

 import dateutil, yaml, shopify
 import json, os, threading, re
 
-
 with open('Stores.json') as f:
     stores = json.load(f)
 
 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):
-		commands = ["Shopify: Browse Themes - %s" % x for x in store_keys]
-		def on_shop_select(picked):
-			global current_store
-			if picked == -1:
-				return
-			current_store =  store_keys[picked] 
+        commands = ["Shopify: Browse Themes - %s" % x for x in store_keys]
+        def on_shop_select(picked):
+            if picked == -1:
+                return
+            global current_store
+            current_store =  store_keys[picked] 
 
-			api_lock.acquire()
-			connect(stores[current_store])
-			stores[current_store]['themes'] = shopify.Theme.find()
-			api_lock.release()
-			
-			self.window.run_command('shopify_show_themes')
-		self.window.show_quick_panel(commands, on_shop_select)
-    	
+            api_lock.acquire()
+            sublime.status_message('Downloading list of themes')
+            connect(stores[current_store])
+            stores[current_store]['themes'] = shopify.Theme.find()
+            sublime.status_message('')
+            api_lock.release()
+
+            self.window.run_command('shopify_show_themes')
+        self.window.show_quick_panel(commands, on_shop_select)
+        
 
 class ShopifyShowThemesCommand(sublime_plugin.WindowCommand):
-	def run(self):
-		if (current_store == None):
-			self.window.run_command('shopify_show_stores')
-			return
+    def run(self):
+        if (current_store == None):
+            self.window.run_command('shopify_show_stores')
+            return
 
-		commands = ["Shopify: %s: %s (%s)" % (current_store, theme.name, theme.role) for theme in stores[current_store]['themes']]
-		def on_theme_select(picked):
-			if picked == -1:
-				return
-			global current_theme
-			current_theme = stores[current_store]['themes'][picked]
-			
-			api_lock.acquire()
-			all_assets = shopify.Asset.find(theme_id = current_theme.id)
-			keys = map(lambda a: a.key, all_assets)
-			current_theme.assets = [a for a in all_assets if "%s.liquid" % a.key not in keys and not re.search("(\.png|\.gif|\.jpg)$", a.key)]
-			api_lock.release()
+        commands = ["Shopify: %s: %s (%s)" % (current_store, theme.name, theme.role) for theme in stores[current_store]['themes']]
+        def on_theme_select(picked):
+            if picked == -1:
+                return
+            global current_theme
+            current_theme = stores[current_store]['themes'][picked]
 
-			self.window.run_command('shopify_show_assets')
-		self.window.show_quick_panel(commands, on_theme_select)
+            api_lock.acquire()
+            sublime.status_message('Downloading list of assets')
+            all_assets = shopify.Asset.find(theme_id = current_theme.id)
+            keys = map(lambda a: a.key, all_assets)
+            current_theme.assets = [a for a in all_assets if "%s.liquid" % a.key not in keys and not re.search("(\.png|\.gif|\.jpg)$", a.key)]
+            sublime.status_message('')
+            api_lock.release()
+
+            self.window.run_command('shopify_show_assets')
+        self.window.show_quick_panel(commands, on_theme_select)
 
 class ShopifyShowAssetsCommand(sublime_plugin.WindowCommand):
-	def run(self):
-		if (current_store == None):
-			self.window.run_command('shopify_show_stores')
-			return
-		
-		commands = ["%s: %s" % (current_theme.name, a.key) for a in current_theme.assets]
-		def on_asset_select(picked):
-			if picked == -1:
-				return
-			key		     = current_theme.assets[picked].key
-			key1, key2      = key.split('/')
-			asset_file_name = os.path.join(current_store, str(current_theme.id), key1, key2)
-			root		    = os.path.join(sublime.packages_path(),'Shopify', 'cache')
-			asset_full_name = os.path.join(root,asset_file_name)
+    def run(self):
+        if (current_store == None):
+            self.window.run_command('shopify_show_stores')
+            return
 
-			api_lock.acquire()
-			asset = shopify.Asset.find(key, theme_id = current_theme.id)
-			api_lock.release()
+        commands = ["%s: %s" % (current_theme.name, a.key) for a in current_theme.assets]
+        def on_asset_select(picked):
+            if picked == -1:
+                return
+            key             = current_theme.assets[picked].key
+            key1, key2      = key.split('/')
+            asset_file_name = os.path.join(current_store, str(current_theme.id), key1, key2)
+            root            = os.path.join(sublime.packages_path(),'Shopify', 'cache')
+            asset_full_name = os.path.join(root,asset_file_name)
 
-			if ( not os.path.exists(os.path.dirname(asset_full_name))):
-				os.makedirs(os.path.dirname(asset_full_name))
+            api_lock.acquire()
+            sublime.status_message('Downloading asset')
+            asset = shopify.Asset.find(key, theme_id = current_theme.id)
+            api_lock.release()
 
-			with open(asset_full_name, 'wb') as f:
-				f.write(asset.value)
-			self.window.run_command('open_file', {"file":os.path.join('cache', asset_file_name)})
+            if ( not os.path.exists(os.path.dirname(asset_full_name))):
+                os.makedirs(os.path.dirname(asset_full_name))
 
-		self.window.show_quick_panel(commands, on_asset_select)
+            with open(asset_full_name, 'wb') as f:
+                f.write(asset.value)
+            sublime.status_message('')
+            self.window.run_command('open_file', {"file":os.path.join('cache', asset_file_name)})
+
+        self.window.show_quick_panel(commands, on_asset_select)
 
 class ShopifyUploadOnSave(sublime_plugin.EventListener):
     def on_post_save(self, view):
-		root = os.path.join(sublime.packages_path(),'Shopify','cache')
-		relpath = os.path.relpath(view.file_name(),root)
-		if relpath[0:2] != '..':
-		    store, theme_id, asset_type, asset_name = relpath.split(os.sep)
-		    key = "%s/%s" %(asset_type, asset_name)
-		    pusher = ShopifyPusher(store, theme_id, key, view.file_name())
-		    pusher.start()
-		    
-		    
+        root = os.path.join(sublime.packages_path(),'Shopify','cache')
+        relpath = os.path.relpath(view.file_name(),root)
+        if relpath[0:2] != '..':
+            sublime.status_message('Uploading asset')
+            store, theme_id, asset_type, asset_name = relpath.split(os.sep)
+            key = "%s/%s" %(asset_type, asset_name)
+            pusher = ShopifyPusher(store, theme_id, key, view.file_name())
+            pusher.start()
 
 class ShopifyPusher(threading.Thread):
-	def __init__(self, store, theme_id, key, filename):
-		self.store = store
-		self.theme_id = theme_id
-		self.key = key
-		self.filename = filename
-		self.result = None
-		threading.Thread.__init__(self)
+    def __init__(self, store, theme_id, key, filename):
+        self.store = store
+        self.theme_id = theme_id
+        self.key = key
+        self.filename = filename
+        self.result = None
+        threading.Thread.__init__(self)
 
-	def run(self):
-		api_lock.acquire()
-		save_site = shopify.ShopifyResource.site
-		connect(stores[self.store])
-		asset = shopify.Asset.find(self.key, theme_id = self.theme_id)
-		with open(self.filename, 'rb') as f:
-			asset.value = f.read()
-		asset.save()
-		shopify.ShopifyResource.site = save_site
-		api_lock.release()
-		self.result = True
+    def run(self):
+        api_lock.acquire()
+        save_site = shopify.ShopifyResource.site
+        connect(stores[self.store])
+        asset = shopify.Asset.find(self.key, theme_id = self.theme_id)
+        with open(self.filename, 'rb') as f:
+            asset.value = f.read()
+        asset.save()
+        shopify.ShopifyResource.site = save_site
+        sublime.set_timeout(lambda:sublime.status_message(''),0)
+        api_lock.release()
+        self.result = True