예제 #1
0
    def push(self, repo, filename, options):
        from gitbundler.poster.encode import multipart_encode
        from gitbundler.poster.streaminghttp import register_openers

        import urllib2

        register_openers()

        repo = os.path.abspath(repo)
        if not os.path.exists(repo):
            print "error: repo folder %s doesn't existed" %repo
            return
            
        print "Bundle> \n  File  :: %s, git: %s, %s" % (filename, repo, options)
    
        git = GitCmd(filename, repo)
        git.get_branch()
        print git.pull()
        print git.bundle_create(filename, options)
       
        if os.path.exists(os.path.join(repo, filename)):
            print "  Info  :: %s" % git.ls_remote(filename)
            print "  Server:: %s" % self.url
            file = open(os.path.join(repo, filename), "rb")
            params = {'fileName': file}
            datagen, headers = multipart_encode(params)
            headers['gitbundler-user'] = self.user
            headers['gitbundler-password'] = self.password
            request = urllib2.Request(self.url, datagen, headers)
            result = urllib2.urlopen(request)
            print "  Upload:: %s" % result.read()
            file.close()
            os.unlink(os.path.relpath(os.path.join(repo, filename)))
        else:
            print "error: generate git bundle fails."
예제 #2
0
 def pull(self, repo, filename, force_branch):
     import os
     import urllib2
     
     git = GitCmd(filename, repo)
     git.get_branch()
     git.set_force_branch(force_branch)
     
     fileurl = '%s%s' % (self.url, filename)
     
     print 'cmd >> Downloading %s' % fileurl
     
     headers = {}
     headers['gitbundler-user'] = self.user
     headers['gitbundler-password'] = self.password
     
     request = urllib2.Request(fileurl, None, headers)
     server = urllib2.urlopen(request)
     bundle = open(os.path.join(repo, filename), 'wb')
     bundle.write(server.read())
     bundle.close()
     server.close()
     
     if os.path.exists(os.path.join(repo, filename)):
         print "  Info  :: %s" % git.ls_remote(filename)
         print "  Server:: %s" % self.url
         print git.pull_bundle(filename)
         #os.unlink(os.path.relpath(os.path.join(repo, filename)))
     else:
         print "error: git bundle download fails."
예제 #3
0
class TestGitLabClone(TestHttpsClone):
    testDir = "./__testGitLabClone"

    def setUp(self):
        """
        put this file in local test dir:
                [myconfig.py]
                user, pwd = "gitlab user", "git lab password",
                url = 'gitlab url'
                commit_id = "commitid for test"
                commit_exists = '/path/somefilename'
        then pass this test
        :return:
        """
        self.cf = __import__("myconfig")
        self.gc = GitCmd(work_dir=self.testDir, user=self.cf.user, pwd=self.cf.pwd,
                         url=self.cf.url)
        self.gc.clone()

    def testCheckout(self):
        self.gc.checkout(self.cf.commit_id)
        self.exists(self.cf.commit_exists)
        self.gc.checkout()

    def testPull(self):
        self.gc.pull()
예제 #4
0
class TestSSHClone(TestHttpsClone):
    testDir = "./__testSSHClone"

    def setUp(self):
        self.gc = GitCmd(work_dir=self.testDir, url='[email protected]:philoprove/gitcmd.git')
        self.gc.clone()
        assert os.path.exists(self.testDir)
        self.exists('/README.rst')

    def testPull(self):
        self.gc.pull()

    def tearDown(self):
        os.popen("rm -rf " + self.testDir)
예제 #5
0
class TestGitLabClone(TestHttpsClone):
    testDir = "./__testGitLabClone"

    def setUp(self):
        """
        put this file in local test dir:
                [myconfig.py]
                user, pwd = "gitlab user", "git lab password",
                url = 'gitlab url'
                commit_id = "commitid for test"
                commit_exists = '/path/somefilename'
        then pass this test
        :return:
        """
        self.cf = __import__("myconfig")
        self.gc = GitCmd(work_dir=self.testDir,
                         user=self.cf.user,
                         pwd=self.cf.pwd,
                         url=self.cf.url)
        self.gc.clone()

    def testCheckout(self):
        self.gc.checkout(self.cf.commit_id)
        self.exists(self.cf.commit_exists)
        self.gc.checkout()

    def testPull(self):
        self.gc.pull()
예제 #6
0
class TestSSHClone(TestHttpsClone):
    testDir = "./__testSSHClone"

    def setUp(self):
        self.gc = GitCmd(work_dir=self.testDir,
                         url='[email protected]:philoprove/gitcmd.git')
        self.gc.clone()
        assert os.path.exists(self.testDir)
        self.exists('/README.rst')

    def testPull(self):
        self.gc.pull()

    def tearDown(self):
        os.popen("rm -rf " + self.testDir)
예제 #7
0
class TestHttpsClone(unittest.TestCase):
    testDir = "./__testHttpsClone"

    def setUp(self):
        self.gc = GitCmd(work_dir=self.testDir, url='https://github.com/philoprove/gitcmd')
        self.gc.clone()
        assert os.path.exists(self.testDir)
        assert os.path.exists(self.testDir + '/README.rst')

    def testPull(self):
        self.gc.pull()

    def tearDown(self):
        os.popen("rm -rf " + self.testDir)

    def exists(self, filename):
        assert os.path.exists(self.testDir + filename)
예제 #8
0
 def setUp(self):
     """
     put this file in local test dir:
             [myconfig.py]
             user, pwd = "gitlab user", "git lab password",
             url = 'gitlab url'
             commit_id = "commitid for test"
             commit_exists = '/path/somefilename'
     then pass this test
     :return:
     """
     self.cf = __import__("myconfig")
     self.gc = GitCmd(work_dir=self.testDir,
                      user=self.cf.user,
                      pwd=self.cf.pwd,
                      url=self.cf.url)
     self.gc.clone()
예제 #9
0
 def lpush(self, remote, branch=None):
     git = GitCmd(self.filename, self.repo)
     git.get_branch()
     if branch:
         remote_branch = branch
     else:
         remote_branch = git.branch
     
     git.checkout(remote_branch)
     git.execute('pull %s %s' % (remote, remote_branch))
예제 #10
0
class TestHttpsClone(unittest.TestCase):
    testDir = "./__testHttpsClone"

    def setUp(self):
        self.gc = GitCmd(work_dir=self.testDir,
                         url='https://github.com/philoprove/gitcmd')
        self.gc.clone()
        assert os.path.exists(self.testDir)
        assert os.path.exists(self.testDir + '/README.rst')

    def testPull(self):
        self.gc.pull()

    def tearDown(self):
        os.popen("rm -rf " + self.testDir)

    def exists(self, filename):
        assert os.path.exists(self.testDir + filename)
예제 #11
0
 def setUp(self):
     """
     put this file in local test dir:
             [myconfig.py]
             user, pwd = "gitlab user", "git lab password",
             url = 'gitlab url'
             commit_id = "commitid for test"
             commit_exists = '/path/somefilename'
     then pass this test
     :return:
     """
     self.cf = __import__("myconfig")
     self.gc = GitCmd(work_dir=self.testDir, user=self.cf.user, pwd=self.cf.pwd,
                      url=self.cf.url)
     self.gc.clone()
예제 #12
0
 def setUp(self):
     self.gc = GitCmd(work_dir=self.testDir, url='[email protected]:philoprove/gitcmd.git')
     self.gc.clone()
     assert os.path.exists(self.testDir)
     self.exists('/README.rst')
예제 #13
0
 def setUp(self):
     self.gc = GitCmd(work_dir=self.testDir, url='https://github.com/philoprove/gitcmd')
     self.gc.clone()
     assert os.path.exists(self.testDir)
     assert os.path.exists(self.testDir + '/README.rst')
예제 #14
0
 def setUp(self):
     self.gc = GitCmd(work_dir=self.testDir,
                      url='[email protected]:philoprove/gitcmd.git')
     self.gc.clone()
     assert os.path.exists(self.testDir)
     self.exists('/README.rst')
예제 #15
0
 def setUp(self):
     self.gc = GitCmd(work_dir=self.testDir,
                      url='https://github.com/philoprove/gitcmd')
     self.gc.clone()
     assert os.path.exists(self.testDir)
     assert os.path.exists(self.testDir + '/README.rst')
예제 #16
0
 def archive(self, repo, filename, commit, output):
     git = GitCmd(filename, repo)
     print git.archive(commit, output)