Skip to content

Commit

Permalink
swc-installation-test-2.py: Add support for package-specific URLs
Browse files Browse the repository at this point in the history
To give users more targeted advice for fixing their installation
problems, we should link them to somewhere more specific than the root
SWC setup page.  The two knobs in the specific URL are system/OS
(Gentoo, Debian, OS X, MS Windows, ...) and package (the dependency
name: emacs, git, virtual-browser, ...).  We don't have consistent
URLs upstream yet [1], but maybe this commit will help motivate them
;).

[1]: https://github.com/swcarpentry/website/issues/2
  • Loading branch information
W. Trevor King committed Feb 26, 2013
1 parent f4340fb commit 001b57b
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion setup/swc-installation-test-2.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ def import_module(name):
import shlex as _shlex
import subprocess as _subprocess
import sys as _sys
try: # Python 3.x
import urllib.parse as _urllib_parse
except ImportError: # Python 2.x
import urllib as _urllib_parse # for quote()


if not hasattr(_shlex, 'quote'): # Python versions older than 3.3
Expand Down Expand Up @@ -107,6 +111,12 @@ def __str__(self):


class DependencyError (Exception):
_system_map = { # map long system names to shorter forms
'Gentoo Base System': 'Gentoo',
}
_supported = [ # (system, package) pairs with specific instructions
]

def _get_message(self):
return self._message
def _set_message(self, message):
Expand All @@ -121,8 +131,22 @@ def __init__(self, checker, message, causes=None):
causes = []
self.causes = causes

def get_url(self):
url = 'http://software-carpentry.org/setup/'
system = _platform.system()
if system == 'Linux':
system = _platform.linux_distribution()[0] or system
system = self._system_map.get(system, system)
package = self.checker.name
if (system, package) in self._supported:
url = '{0}{1}.html#{2}'.format(
url,
_urllib_parse.quote(system.lower()),
_urllib_parse.quote(package))
return url

def __str__(self):
url = 'http://software-carpentry.org/setup/' # TODO: per-package URL
url = self.get_url()
lines = [
'check for {0} failed:'.format(self.checker.full_name()),
' ' + self.message,
Expand Down

0 comments on commit 001b57b

Please sign in to comment.