Exemple #1
0
def with_ubuntu_keyring():
    keyrings = [
        "/usr/share/keyrings/ubuntu-master-keyring.gpg",
        "/usr/share/keyrings/ubuntu-archive-keyring.gpg",
        ]

    def gpg(argv, **kwargs):
        return call(["gpg", "--homedir", temp_dir] + argv, **kwargs)

    with mkdtemp() as temp_dir:
        for keyring_path in keyrings:
            gpg(["--import", keyring_path])
        yield gpg
Exemple #2
0
def sync_batch(git_couchdb_url, design_couchdb_url, branch, app_subdir):
    if branch is None:
        branches = [
            b["_id"] for b in get(
                posixpath.join(git_couchdb_url, "git-branches"))["branches"]]
    else:
        # TODO: Should really look for branches with this name using
        # an index
        branches = ["git-branch-" + branch]
    with mkdtemp() as temp_dir:
        for branch in branches:
            basename = urllib.quote(branch, safe="")
            local_dir = os.path.join(temp_dir, basename)
            commit = get(posixpath.join(git_couchdb_url, 
                                        branch))["commit"]["_id"]
            tree = get(posixpath.join(git_couchdb_url, 
                                      commit))["tree"]["_id"]
            if app_subdir != ".":
                # TODO: Support multi-level sub_dir
                assert "/" not in app_subdir, app_subdir
                for child in get(posixpath.join(git_couchdb_url, 
                                                tree))["children"]:
                    if child["basename"] == app_subdir:
                        assert child["child"]["type"] == "git-tree", child
                        tree = child["child"]["_id"]
                        break
                else:
                    raise Exception("Missing child %r" % (app_subdir,))
            doc_url = posixpath.join(design_couchdb_url, 
                                     "_design", url_quote(basename))
            existing = get(doc_url)
            if existing.get("couchapp_git_tree_id") == tree:
                continue
            print "Updating %r..." % (branch,)
            tree_to_fs(git_couchdb_url, local_dir, tree)
            write_file(os.path.join(local_dir, "couchapp_git_tree_id"),
                       tree)
            if os.path.exists(os.path.join(local_dir, "_id")):
                os.unlink(os.path.join(local_dir, "_id"))
            couchapp(doc_url, local_dir)
            print "...done %r" % (branch,)            
    def _run_test(self):
        # Wipe out all git-related documents and the design document
        result = get(posixpath.join(self.couchdb_url, 
                                    "_design/test/_view/git-documents"))
        for item in result["rows"]:
            delete(posixpath.join(self.couchdb_url, url_quote(item["id"])))
        # Upload the gitbrowser to the couchdb design document
        gitbrowser_source_path = os.path.join(self.source_path, "gitbrowser")
        couchapp(posixpath.join(self.couchdb_url, "_design/gitbrowser"), 
                 gitbrowser_source_path)
        # Populate a test GIT repository
        with mkdtemp() as temp_dir:
            cwd_script = ["bash", "-c", 'cd "$1" && shift && exec "[email protected]"', "-", 
                          temp_dir]
            subprocess.check_call(cwd_script + ["git", "init"])
        ## write file README
            git = cwd_script + ["env", 
                                "HOME=%s" % (temp_dir,),
                                "git"]
            subprocess.check_call(git + ["config", "user.name", "Tester"])
            subprocess.check_call(git + ["config", "user.email", 
                                         "*****@*****.**"])
            path = os.path.join(temp_dir, "README")
            with open(path, "wb") as fh:
                fh.write("Initial version of text file\r\n")
            subprocess.check_call(git + ["add", path])
            subprocess.check_call(git + ["commit", "-m", 
                                         "Initial commit"])
        ## write file README
            with open(path, "wb") as fh:
                fh.write("""\
# Purpose

This is a minimal git repository for testing

# Example Markdown

Readme files like this are Markdown formatted:

 * Bullet points
 * Headings
 * Code blocks
 * _etc_

They can have hyperlinks:

 * to other hosts like [google](http://www.google.com/)
 * absolute paths, like the [hexdump file](/show/master/head/binary-file)
 * relative paths, like the [child folder](subfolder)

""")
            subprocess.check_call(git + ["add", path])
        ## write file binary 
            path = os.path.join(temp_dir, "binary-file")
            with open(path, "wb") as fh:
                fh.write("".join(chr(i) for i in range(2**8)))
            subprocess.check_call(git + ["add", path])
        ## write python file 
            path = os.path.join(temp_dir, "example.py")
            with open(path, "wb") as fh:
                fh.write("""\
## Example\r\n\
#This is an example python file\r\n\
#\r\n\
#  - Example bullet list\r\n\
#  - _etc_\r\n\
#\r\n\
#Because of the blank line, this documentation block should not\r\n\
#have any code on the right and the following code block should not\r\n\
#have any documentation to its left.\r\n\
\r\n\
from __future__ import division\r\n\
import os, sys, unittest\r\n\
\r\n\
class SomeTest(unittest.TestCase):\r\n\
\r\n\
  def testSomething(self):\r\n\
    '''Just an example test'''\r\n\
    self.fail("Just an example")\r\n\
\r\n\
## Main entry point\r\n\
#Some normal *Markdown* paragraph text, the example \r\n\
#heading should line up with the if statement.\r\n\
if __name__ == "__main__":\r\n\
  # This comment, starting after column 0, is a normal comment shown\r\n\
  # inline with the code instead of one that is shown in the left panel.\r\n\
  unittest.main()\r\n\
""")
            subprocess.check_call(git + ["add", path])
        ## write file .gitbrowser-project.json
            path = os.path.join(temp_dir, ".gitbrowser-project.json")
            with open(path, "wb") as fh:
                fh.write('{"title": "Example Project"}')
            subprocess.check_call(git + ["add", path])
        ## write file subfolder/README 
            path = os.path.join(temp_dir, "subfolder", "README")
            os.makedirs(os.path.dirname(path))
            with open(path, "wb") as fh:
                fh.write("A file in a subfolder with a [parent link](..)")
            subprocess.check_call(git + ["add", path])
            subprocess.check_call(git + ["commit", "-m", "Update"])
        # Copy the git repository to the couchdb
            sync_script = os.path.join(self.source_path, "gitcouchdbsync.py")
            subprocess.check_call(cwd_script + ["python", sync_script,
                                                self.couchdb_url])
        # Run selenium testing against the public URL
        print "Uploaded. Running tests..."
        self._go_to_the_selenium_stage()