changeset 8:cf00d46b1bfb

pretend like we have a pluggable system to start debugging it
author Jeff Hammel <jhammel@mozilla.com>
date Sun, 18 Sep 2011 18:46:31 -0700
parents 4d3d0e1324f5
children f8575a78ec06
files fetch/main.py
diffstat 1 files changed, 29 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/fetch/main.py	Sun Sep 18 18:37:02 2011 -0700
+++ b/fetch/main.py	Sun Sep 18 18:46:31 2011 -0700
@@ -8,7 +8,16 @@
 import sys
 import optparse
 
-__all__ = ['Fetcher', 'FileFetcher', 'main']
+__all__ = ['Fetcher', 'Fetch', 'main']
+
+def which(executable, path=os.environ['PATH']):
+  """python equivalent of which; should really be in the stdlib"""
+  # XXX from https://github.com/mozautomation/mozmill/blob/master/mozrunner/mozrunner/utils.py
+  dirs = path.split(os.pathsep)
+  for dir in dirs:
+    if os.path.isfile(os.path.join(dir, fileName)):
+      return os.path.join(dir, fileName)
+
 
 class Fetcher(object):
   """abstract base class for resource fetchers"""
@@ -60,6 +69,13 @@
     tf = tarfile.open(mode='r', fileobj=buffer)
     tf.extract(dest)
 
+fetchers = [FileFetcher, TarballFetcher]
+
+### VCS fetchers using executable
+
+if which('hg'):
+  pass # TODO: wrap HgFetcher
+
 class HgFetcher(Fetcher):
   """checkout a mercurial repository"""
 
@@ -70,7 +86,10 @@
 
   type = 'git'
 
-fetchers = [FileFetcher]
+
+fetcher_names = [cls.__name__ for cls in fetchers]
+__all__ += fetcher_names
+
 
 class Fetch(object):
   
@@ -170,8 +189,16 @@
   parser.add_option('-s', '--strict',
                     action='store_true', default=False,
                     help="fail on error")
+  parser.add_option('--list-fetchers', dest='list_fetchers',
+                    action='store_true', default=False,
+                    help='list available fetchers and exit')
   options, args = parser.parse_args(args)
 
+  if options.list_fetchers:
+    for name in fetcher_names:
+      print name
+    parser.exit()
+
   if not args:
     parser.print_help()
     parser.exit()