changeset 38:d17978d9697b

make more robust
author Jeff Hammel <k0scist@gmail.com>
date Tue, 12 May 2015 18:32:07 -0700
parents 1877e2cb1118
children 9e21b4fbd8b3
files silvermirror/hg.py
diffstat 1 files changed, 8 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/silvermirror/hg.py
+++ b/silvermirror/hg.py
@@ -13,30 +13,35 @@ from hglib.error import ServerError
 
 _import_error = None
 try:
     import lxml.html
 except ImportError as _import_error:
     pass
 
 
+def clone(source, path):
+    print ('Cloning {} -> {}'.format(source, path))
+    return hglib.clone(source, path)
+
 def update(source, path):
     """
     get changes from host on path
     """
 
+    if not os.path.exists(path):
+        return clone(source, path)
 
     try:
         repo = hglib.open(path)
-        print ('Updating {}:'.format(path))
+        print ('Updating {}'.format(path))
         repo.pull(source, update=True, insecure=True)
     except ServerError:
-        print ('Cloning {} -> {}'.format(source, path))
         repo = hglib.clone(source, path)
-
+    return repo
 
 def repositories(url):
     """
     returns the list of repositories under a URL of an hg server
     """
     element = lxml.html.parse(url)
     tds = element.xpath('//tr[position() > 1]/td[1]')
     repos = [i.text_content() for i in tds]