From a9b94c56a14906770b418688e3b3a46c5af8eca1 Mon Sep 17 00:00:00 2001 From: Danny Staple Date: Sat, 9 Mar 2013 20:02:27 +0000 Subject: [PATCH] Make this work in windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This would error out if attempted on windows. Expand userdir works on many OS's without the HOME environment assumption.  I've set the default function as disabled in windows - it currently dies with an error when doing an add due to not having the os.symlink capability. The not in is used for other OS's that don't support this (if appropriate). Ideally, I'd like to get support for Windows using another method - but for now this gets me unstuck --- scripts/shopify_api.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/scripts/shopify_api.py b/scripts/shopify_api.py index bfabe29d..3ba1a231 100755 --- a/scripts/shopify_api.py +++ b/scripts/shopify_api.py @@ -86,7 +86,7 @@ def help(cls, task=None): class Tasks(object): __metaclass__ = TasksMeta - _shop_config_dir = os.path.join(os.environ["HOME"], ".shopify", "shops") + _shop_config_dir = os.path.join(os.path.expanduser('~'), ".shopify", "shops") _default_symlink = os.path.join(_shop_config_dir, "default") @classmethod @@ -117,7 +117,7 @@ def add(cls, connection): if not os.path.isdir(cls._shop_config_dir): os.makedirs(cls._shop_config_dir) file(filename, 'w').write(yaml.dump(config, default_flow_style=False, explicit_start="---")) - if len(cls._available_connections()) == 1: + if cls._supports_default() and len(cls._available_connections()) == 1: cls.default(connection) @classmethod @@ -126,7 +126,7 @@ def remove(cls, connection): """remove the config file for CONNECTION""" filename = cls._get_config_filename(connection) if os.path.exists(filename): - if cls._is_default(connection): + if cls._supports_default() and cls._is_default(connection): os.remove(cls._default_symlink) os.remove(filename) else: @@ -163,6 +163,9 @@ def show(cls, connection=None): @usage("default [CONNECTION]") def default(cls, connection=None): """show the default connection, or make CONNECTION the default""" + if not cls._supports_default(): + print("Sorry - this OS doesn't yet support default") + return if connection is not None: target = cls._get_config_filename(connection) if os.path.exists(target): @@ -231,6 +234,10 @@ def _session_from_config(cls, config): session.api_key = config.get("api_key") session.token = config.get("password") return session + + @classmethod + def _supports_default(cls): + return os.name not in ['nt'] @classmethod def _is_default(cls, connection):