浏览代码

Started work on the brewer

shin- 12 年之前
当前提交
3724fb6ed3
共有 5 个文件被更改,包括 87 次插入0 次删除
  1. 1 0
      .gitignore
  2. 21 0
      brew/brew.py
  3. 42 0
      brew/git.py
  4. 1 0
      requirements.txt
  5. 22 0
      setup.py

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+*.pyc

+ 21 - 0
brew/brew.py

@@ -0,0 +1,21 @@
+import os
+
+import git
+
+DEFAULT_REPOSITORY = 'git://github.com/dotcloud/docker'
+DEFAULT_BRANCH = 'library'
+
+
+def fetch_buildlist(repository=None, branch=None):
+    if repository is None:
+        repository = DEFAULT_REPOSITORY
+    if branch is None:
+        branch = DEFAULT_BRANCH
+    #FIXME: set destination folder and only pull latest changes instead of
+    # cloning the whole repo everytime
+    dst_folder = git.clone_branch(repository, branch)
+    for buildfile in os.listdir(os.path.join(dst_folder, 'library')):
+        f = open(os.path.join(dst_folder, 'library', buildfile))
+        for line in f:
+            print buildfile, '--->', line
+        f.close()

+ 42 - 0
brew/git.py

@@ -0,0 +1,42 @@
+import tempfile
+import logging
+
+from dulwich import index
+from dulwich.client import get_transport_and_path
+from dulwich.repo import Repo
+
+logger = logging.getLogger(__name__)
+
+
+def clone_branch(repo_url, branch="master", folder=None):
+    return clone(repo_url, 'refs/heads/' + branch, folder)
+
+
+def clone_tag(repo_url, tag, folder=None):
+    return clone(repo_url, 'refs/tags/' + tag, folder)
+
+
+def clone(repo_url, ref=None, folder=None):
+    if ref is None:
+        ref = 'refs/heads/master'
+    logger.debug("clone repo_url={0}, ref={1}".format(repo_url, ref))
+    if folder is None:
+        folder = tempfile.mkdtemp()
+    logger.debug("folder = {0}".format(folder))
+    rep = Repo.init(folder)
+    client, relative_path = get_transport_and_path(repo_url)
+    logger.debug("client={0}".format(client))
+
+    remote_refs = client.fetch(relative_path, rep)
+    for k, v in remote_refs.iteritems():
+        try:
+            rep.refs.add_if_new(k, v)
+        except:
+            pass
+
+    rep['HEAD'] = remote_refs[ref]
+    indexfile = rep.index_path()
+    tree = rep["HEAD"].tree
+    index.build_index_from_tree(rep.path, indexfile, rep.object_store, tree)
+    logger.debug("done")
+    return folder

+ 1 - 0
requirements.txt

@@ -0,0 +1 @@
+dulwich

+ 22 - 0
setup.py

@@ -0,0 +1,22 @@
+#/usr/bin/env python
+import os
+from setuptools import setup
+
+ROOT_DIR = os.path.dirname(__file__)
+SOURCE_DIR = os.path.join(ROOT_DIR)
+
+test_requirements = []
+setup(
+    name="docker-brew",
+    version='0.0.1',
+    description="-",
+    packages=['dockerbrew'],
+    install_requires=['requests'] + test_requirements,
+    zip_safe=False,
+    classifiers=['Development Status :: 3 - Alpha',
+                 'Environment :: Other Environment',
+                 'Intended Audience :: Developers',
+                 'Operating System :: OS Independent',
+                 'Programming Language :: Python',
+                 'Topic :: Utilities'],
+    )