Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Make this work in windows #16

Closed
wants to merge 1 commit into from

3 participants

@dannystaple

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

@dannystaple dannystaple Make this work in windows
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
a9b94c5
@dylanahsmith dylanahsmith commented on the diff
scripts/shopify_api.py
@@ -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):
@dylanahsmith Collaborator

It would make more sense if _is_default just returned false.

@dylanahsmith Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@dylanahsmith dylanahsmith commented on the diff
scripts/shopify_api.py
@@ -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']
@dylanahsmith Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@dylanahsmith dylanahsmith commented on the diff
scripts/shopify_api.py
@@ -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")
@dylanahsmith Collaborator

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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@dylanahsmith
Collaborator

Sorry for the delay in reviewing this.

@kevinhughes27
Collaborator

This PR has been open for a long time, I'm going to close it now. Feel free to re-open if you'd like and we can discuss and re-evaluate making some changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 9, 2013
  1. @dannystaple

    Make this work in windows

    dannystaple authored
    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
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 3 deletions.
  1. +10 −3 scripts/shopify_api.py
View
13 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):
@dylanahsmith Collaborator

It would make more sense if _is_default just returned false.

@dylanahsmith Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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")
@dylanahsmith Collaborator

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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ 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']
@dylanahsmith Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@classmethod
def _is_default(cls, connection):
Something went wrong with that request. Please try again.