Commits

Anonymous committed bc6c7b5

Split original template bitbucket into bitbucket_hg and bitbucket_git

Comments (0)

Files changed (5)

     entry_points = {
         'virtualenvwrapper.project.template': [
             'bitbucket = virtualenvwrapper.bitbucket:template',
+            'bitbucket_hg = virtualenvwrapper.bitbucket_hg:template',
+            'bitbucket_git = virtualenvwrapper.bitbucket_git:template'
             ],
         },
 

virtualenvwrapper/__init__.py

 """virtualenvwrapper.emacs_desktop
 """
 
+"""virtualenvwrapper.project plugin for bitbucket repositories
+"""
+
 __import__('pkg_resources').declare_namespace(__name__)
+
+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

virtualenvwrapper/bitbucket.py

 #
 # Copyright (c) 2010 Doug Hellmann.  All rights reserved.
 #
-"""virtualenvwrapper.project plugin for bitbucket repositories
-"""
-
-import logging
-import os
-import subprocess
-
-import pkg_resources
-
-log = logging.getLogger(__name__)
-
-def get_url(project, vc_type='hg'):
-    """Return the URL for the given project.
-    """
-    user = os.environ.get('VIRTUALENVWRAPPER_BITBUCKET_USER', os.environ.get('USER'))
-    if not user:
-        log.error('Set USER or VIRTUALENVWRAPPER_BITBUCKET_USER')
-        return None
-    url = 'ssh://{vc_type}@bitbucket.org/{user}/{project}'.format(vc_type = vc_type, \
-		user=user, project=project)
-    return url
+# retained default template of bitbucket for compatibility
+from virtualenvwrapper import _template
 
 def template(args):
-    """Clones a BitBucket.org repository into the project directory.
-    """
-    project = args[0]
-    vc_type = os.environ.get('VIRTUALENVWRAPPER_BITBUCKET_VCTYPE','hg')
-    url = get_url(project,vc_type)
-    if url:
-        log.info('Cloning %s', url)
-        subprocess.call([vc_type, 'clone', url, project], shell=False)
-    return
+    return _template(args, 'hg')

virtualenvwrapper/bitbucket_git.py

+#!/usr/bin/env python
+# encoding: utf-8
+#
+# Copyright (c) 2010 Doug Hellmann.  All rights reserved.
+#
+from virtualenvwrapper import _template
+
+def template(args):
+    return _template(args, 'git')

virtualenvwrapper/bitbucket_hg.py

+#!/usr/bin/env python
+# encoding: utf-8
+#
+# Copyright (c) 2010 Doug Hellmann.  All rights reserved.
+#
+"""virtualenvwrapper.project plugin for bitbucket repositories
+"""
+import pkg_resources
+
+from virtualenvwrapper import log, _template
+
+VERSION_CONTROL_TYPE='hg'
+
+def template(args):
+    log.info('Pulling from BitBucket using ' % VERSION_CONTROL_TYPE)
+    return _template(args, VERSION_CONTROL_TYPE)