Commits

shirkey committed c05c966

adding common.py

Comments (0)

Files changed (1)

virtualenvwrapper/common.py

+
+import logging
+import os
+import subprocess
+
+log = logging.getLogger(__name__)
+
+REPOSITORY_URL = 'ssh://{vc_type}@bitbucket.org/{user}/{project}'
+
+def get_url(project, vc_type='hg'):
+    """Return the URL for the given project.
+    """
+    # potential env vars for userid, in order of increased precedence
+    env_var_strings = ['USER','VIRTUALENVWRAPPER_BITBUCKET_USER'] 
+    env_vars = [(os.environ.get(env),env) for env in env_var_strings 
+                            if os.environ.get(env)]
+    if len(env_vars)<1:
+        log.error('Set one of the following: %s' % env_var_strings)
+        return None
+
+    user, source = env_vars[-1]
+    log.info('Pulling from Bitbucket as %s(=env var %s) using %s' % (user,source, vc_type))
+    url = REPOSITORY_URL.format(vc_type = vc_type, user=user, project=project)
+    return url
+
+def _template(args, vc_type):
+    """Clones a BitBucket.org repository into the project directory.
+    """
+    project = args[0]
+    url = get_url(project, vc_type)
+    if url:
+        log.info('Cloning %s', url)
+        subprocess.call([vc_type, 'clone', url, project], shell=False)
+    return