-
Notifications
You must be signed in to change notification settings - Fork 350
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: | ||
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'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
def _is_default(cls, connection): | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.