Beispiel #1
0
def sharesetup(user):
    form = ShareForm()
    if request.form.get('bar', None) == 'Share/Unshare':
    	if form.validate_on_submit():
    	    shareuser = form.shareuser.data
	    if shareuser != user.nickname:
    	    	sharepath = settings.WORKING_DIR + shareuser
	    	shareuserdb = User.query.filter_by(nickname=shareuser).first()
    	    	sharedname = user.nickname + "Repo"
    
    	    	currentRepo = shareuserdb.repos.filter_by(repourl="/" + sharedname + "/").first()
    	    	if currentRepo is None:
	    	    existing = False
    	    	    for sub in os.listdir(sharepath):
	                if sub == sharedname:
	    	    	    existing = True
    	    	    if not existing:
	    	        repo = Repo(settings.REMOTE_DIR + user.nickname)
	    	        os.system("sudo mkdir " + sharepath + "/" + sharedname)
		        working_repo = repo.clone(sharepath + "/" + sharedname , False, False, "origin")
            	        p = subprocess.Popen(["sudo", "git", "remote", "add", "origin", "file:///" + settings.REMOTE_DIR + user.nickname + "/"], cwd=sharepath + "/" + sharedname)
	    	        p.wait()
	    	    newrepo = Rpstry(repourl="/" + sharedname + "/", owner=shareuserdb)
            	    db.session.add(newrepo)
            	    db.session.commit()

	    	    password = ''
	    	    searchfile = open(settings.REMOTE_DIR + shareuser + "/.htpasswd", "r")
	    	    for line in searchfile:
		        exactuser = re.compile("^" + shareuser + ":(.)*$")
                        if exactuser.match(line):
   	            	    password = line
	            searchfile.close()
                    open(settings.REMOTE_DIR + user.nickname + "/.htpasswd", 'a').writelines(password)
                    flash("Shared with: " + shareuser, 'info')
	        else:
	    	    searchfile = open(settings.REMOTE_DIR + user.nickname + "/.htpasswd", "r")
	    	    lines = searchfile.readlines()
	    	    searchfile.close()
	    	    f = open(settings.REMOTE_DIR + user.nickname + "/.htpasswd","w")
	    	    for line in lines:
		        exactuser = re.compile("^" + shareuser + ":(.)*$")
		        if not exactuser.match(line):
		    	    f.write(line)
	            f.close()
	            db.session.delete(currentRepo)
	            db.session.commit()
		    flash("Unshared with: " + shareuser, 'info')
        else:
	    flash("User does not exist", 'error')
    return form
Beispiel #2
0
 def test_clone_no_head(self):
     temp_dir = self.mkdtemp()
     self.addCleanup(shutil.rmtree, temp_dir)
     repo_dir = os.path.join(os.path.dirname(__file__), 'data', 'repos')
     dest_dir = os.path.join(temp_dir, 'a.git')
     shutil.copytree(os.path.join(repo_dir, 'a.git'),
                     dest_dir, symlinks=True)
     r = Repo(dest_dir)
     del r.refs[b"refs/heads/master"]
     del r.refs[b"HEAD"]
     t = r.clone(os.path.join(temp_dir, 'b.git'), mkdir=True)
     self.assertEqual({
         b'refs/tags/mytag': b'28237f4dc30d0d462658d6b937b08a0f0b6ef55a',
         b'refs/tags/mytag-packed':
             b'b0931cadc54336e78a1d980420e3268903b57a50',
         }, t.refs.as_dict())
Beispiel #3
0
 def test_clone_no_head(self):
     temp_dir = self.mkdtemp()
     self.addCleanup(shutil.rmtree, temp_dir)
     repo_dir = os.path.join(os.path.dirname(__file__), 'data', 'repos')
     dest_dir = os.path.join(temp_dir, 'a.git')
     shutil.copytree(os.path.join(repo_dir, 'a.git'),
                     dest_dir, symlinks=True)
     r = Repo(dest_dir)
     del r.refs[b"refs/heads/master"]
     del r.refs[b"HEAD"]
     t = r.clone(os.path.join(temp_dir, 'b.git'), mkdir=True)
     self.assertEqual({
         b'refs/tags/mytag': b'28237f4dc30d0d462658d6b937b08a0f0b6ef55a',
         b'refs/tags/mytag-packed':
             b'b0931cadc54336e78a1d980420e3268903b57a50',
         }, t.refs.as_dict())
Beispiel #4
0
 def test_clone_no_head(self):
     temp_dir = tempfile.mkdtemp()
     self.addCleanup(shutil.rmtree, temp_dir)
     repo_dir = os.path.join(os.path.dirname(__file__), "data", "repos")
     dest_dir = os.path.join(temp_dir, "a.git")
     shutil.copytree(os.path.join(repo_dir, "a.git"), dest_dir, symlinks=True)
     r = Repo(dest_dir)
     del r.refs["refs/heads/master"]
     del r.refs["HEAD"]
     t = r.clone(os.path.join(temp_dir, "b.git"), mkdir=True)
     self.assertEqual(
         {
             "refs/tags/mytag": "28237f4dc30d0d462658d6b937b08a0f0b6ef55a",
             "refs/tags/mytag-packed": "b0931cadc54336e78a1d980420e3268903b57a50",
         },
         t.refs.as_dict(),
     )