Manabu TERADA avatar Manabu TERADA committed d52b7be Draft

adding support for git backup, but this commit does not finish yet.

Comments (0)

Files changed (2)

c2/recipe/bitbucketbk/backuprunner.py

 from urllib2 import HTTPError
 import base64
 import xlwt
-from mercurial import hg, ui, commands
+from mercurial import hg
+from mercurial import ui as hg_ui
+from mercurial import commands as hg_commands
+# from git import Repo as git_repo
+from dulwich.repo import Repo as git_repo
 
 BITBUCKET_API = u"https://api.bitbucket.org/1.0/"
 BITBUCKET_BASE_URL = u"https://%(user)s:%(passwd)s@bitbucket.org/"
     bitbucket_obj = access_api_base(api_url)
     repos = json.load(bitbucket_obj).get('repositories', [])
     for repo in repos:
-        yield repo.get('name', None), repo.get('scm', ''), repo.get('has_issues')
+        yield repo.get('name'), repo.get('scm'), repo.get('has_issues')
 
 def has_repo(repo_name, location):
     if os.path.exists(os.path.join(location, repo_name)):
 
 def create_hg_repo(repo_url, location):
     # repo = hg.repository(ui.ui(), repo_url)
-    commands.clone(ui.ui(), repo_url, dest=location, insecure=True)
+    hg_commands.clone(hg_ui.ui(), repo_url, dest=location, insecure=True)
 
 def get_hg_data(repo_url, location):
-    repo = hg.repository(ui.ui(), location)
-    commands.pull(ui.ui(), repo, source=repo_url)
+    repo = hg.repository(hg_ui.ui(), location)
+    hg_commands.pull(hg_ui.ui(), repo, source=repo_url)
+
+def create_git_repo(repo_url_git, location):
+    # repo = git_repo.init_bare(location)
+    # repo.create(repo_url_git)
+    repo = git_repo(location)
+    repo.clone(repo_url_git)
+
+def get_git_data(repo_url_git, location):
+    # print "git has repo : ", repo_url_git
+    # repo = git_repo.init_bare(location)
+    # import pdb; pdb.set_trace()
+    # origin = repo.remote()
+    # origin.fetch()
+    repo = git_repo(location)
+    repo.fetch(repo_url_git)
 
 def _get_issue_comment(comments):
     for data in comments:
                 create_hg_repo(repo_url, folder_location)
             else:
                 get_hg_data(repo_url, folder_location)
+        elif scm == u"git":
+            repo_url_git = repo_url + u".git"
+            if not has_repo(repo_name, location):
+                create_git_repo(repo_url_git, folder_location)
+            else:
+                get_git_data(repo_url_git, folder_location)
+
 
         if has_issues:
             issues_folder_location = os.path.join(location, ISSUES_LOCATION, repo_name)
                         'zc.buildout',
                         'zc.recipe.egg',
                         'mercurial',
+                        # 'GitPython',
+                        'dulwich',
                         'xlwt',
                         # -*- Extra requirements: -*-
                         ],
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.