Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make this work in windows #16

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 10 additions & 3 deletions scripts/shopify_api.py
Expand Up @@ -86,7 +86,7 @@ def help(cls, task=None):
class Tasks(object): class Tasks(object):
__metaclass__ = TasksMeta __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") _default_symlink = os.path.join(_shop_config_dir, "default")


@classmethod @classmethod
Expand Down Expand Up @@ -117,7 +117,7 @@ def add(cls, connection):
if not os.path.isdir(cls._shop_config_dir): if not os.path.isdir(cls._shop_config_dir):
os.makedirs(cls._shop_config_dir) os.makedirs(cls._shop_config_dir)
file(filename, 'w').write(yaml.dump(config, default_flow_style=False, explicit_start="---")) 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) cls.default(connection)


@classmethod @classmethod
Expand All @@ -126,7 +126,7 @@ def remove(cls, connection):
"""remove the config file for CONNECTION""" """remove the config file for CONNECTION"""
filename = cls._get_config_filename(connection) filename = cls._get_config_filename(connection)
if os.path.exists(filename): if os.path.exists(filename):
if cls._is_default(connection): if cls._supports_default() and cls._is_default(connection):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would make more sense if _is_default just returned false.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it looks like it would already be doing that. Since _default_connection would return None if there is no default file.

os.remove(cls._default_symlink) os.remove(cls._default_symlink)
os.remove(filename) os.remove(filename)
else: else:
Expand Down Expand Up @@ -163,6 +163,9 @@ def show(cls, connection=None):
@usage("default [CONNECTION]") @usage("default [CONNECTION]")
def default(cls, connection=None): def default(cls, connection=None):
"""show the default connection, or make CONNECTION the default""" """show the default connection, or make CONNECTION the default"""
if not cls._supports_default():
print("Sorry - this OS doesn't yet support default")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to print this message if no arguments are provided, since default wouldn't exist, and it would print "There is no default connection set".

return
if connection is not None: if connection is not None:
target = cls._get_config_filename(connection) target = cls._get_config_filename(connection)
if os.path.exists(target): if os.path.exists(target):
Expand Down Expand Up @@ -231,6 +234,10 @@ def _session_from_config(cls, config):
session.api_key = config.get("api_key") session.api_key = config.get("api_key")
session.token = config.get("password") session.token = config.get("password")
return session return session

@classmethod
def _supports_default(cls):
return os.name not in ['nt']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't newer versions of windows support symbolic links, and couldn't there be other platforms that don't support symlinks. I think we should do feature detection rather than os detection. Is the function not defined on windows? If not, then we can detect the presence of the method. Does the method exist but raise an error? If so, then try to read or write the symlink and rescue the error.



@classmethod @classmethod
def _is_default(cls, connection): def _is_default(cls, connection):
Expand Down