def testVersioning(self): shelf = gitshelve.open('test') text = "Hello, this is a test\n" shelf['foo/bar/baz1.c'] = text shelf.sync() buf = StringIO() shelf.dump_objects(buf) self.assertEqual( """tree 073629aeb0ef56a50a6cfcaf56da9b8393604b56 tree ce9d91f2da4ab3aa920cd5763be48b9aef76f999: foo tree 2e626f2ae629ea77618e84e79e1bfae1c473452e: bar blob ea93d5cc5f34e13d2a55a5866b75e2c58993d253: baz1.c """, buf.getvalue()) text = "Hello, this is a change\n" shelf['foo/bar/baz1.c'] = text shelf['foo/bar/baz2.c'] = text shelf.sync() buf = StringIO() shelf.dump_objects(buf) self.assertEqual( """tree c7c6fd4368460c645d0953349d5577d32f46115a tree 3936ea8daffe9eef0451b43205d6530374f8ffa3: foo tree 8f7bfca3bc33c93fb1a878bc79c2bb93d8f41730: bar blob fb54a7573d864d4b57ffcc8af37e7565e2ba4608: baz1.c blob fb54a7573d864d4b57ffcc8af37e7565e2ba4608: baz2.c """, buf.getvalue()) del shelf shelf = gitshelve.open('test') buf = StringIO() shelf.dump_objects(buf) self.assertEqual( """tree 3936ea8daffe9eef0451b43205d6530374f8ffa3: foo tree 8f7bfca3bc33c93fb1a878bc79c2bb93d8f41730: bar blob fb54a7573d864d4b57ffcc8af37e7565e2ba4608: baz1.c blob fb54a7573d864d4b57ffcc8af37e7565e2ba4608: baz2.c """, buf.getvalue()) self.assertEqual(text, shelf['foo/bar/baz1.c']) self.assertEqual(text, shelf['foo/bar/baz2.c']) log = gitshelve.git('log', 'test', keep_newline=True) self.assert_( re.match( """commit [0-9a-f]{40} Author: .+ Date: .+ commit [0-9a-f]{40} Author: .+ Date: .+ """, log))
def testVersioning(self): shelf = gitshelve.open('test') text = "Hello, this is a test\n" shelf['foo/bar/baz1.c'] = text shelf.sync() buf = StringIO() shelf.dump_objects(buf) self.assertEqual("""tree 073629aeb0ef56a50a6cfcaf56da9b8393604b56 tree ce9d91f2da4ab3aa920cd5763be48b9aef76f999: foo tree 2e626f2ae629ea77618e84e79e1bfae1c473452e: bar blob ea93d5cc5f34e13d2a55a5866b75e2c58993d253: baz1.c """, buf.getvalue()) text = "Hello, this is a change\n" shelf['foo/bar/baz1.c'] = text shelf['foo/bar/baz2.c'] = text shelf.sync() buf = StringIO() shelf.dump_objects(buf) self.assertEqual("""tree c7c6fd4368460c645d0953349d5577d32f46115a tree 3936ea8daffe9eef0451b43205d6530374f8ffa3: foo tree 8f7bfca3bc33c93fb1a878bc79c2bb93d8f41730: bar blob fb54a7573d864d4b57ffcc8af37e7565e2ba4608: baz1.c blob fb54a7573d864d4b57ffcc8af37e7565e2ba4608: baz2.c """, buf.getvalue()) del shelf shelf = gitshelve.open('test') buf = StringIO() shelf.dump_objects(buf) self.assertEqual("""tree 3936ea8daffe9eef0451b43205d6530374f8ffa3: foo tree 8f7bfca3bc33c93fb1a878bc79c2bb93d8f41730: bar blob fb54a7573d864d4b57ffcc8af37e7565e2ba4608: baz1.c blob fb54a7573d864d4b57ffcc8af37e7565e2ba4608: baz2.c """, buf.getvalue()) self.assertEqual(text, shelf['foo/bar/baz1.c']) self.assertEqual(text, shelf['foo/bar/baz2.c']) log = gitshelve.git('log', 'test', keep_newline = True) self.assert_(re.match("""commit [0-9a-f]{40} Author: .+ Date: .+ commit [0-9a-f]{40} Author: .+ Date: .+ """, log))
def testInsertion(self): shelf = gitshelve.open('test') text = "Hello, this is a test\n" shelf['foo/bar/baz.c'] = text buf = StringIO() shelf.dump_objects(buf) self.assertEqual(buf.getvalue(), """tree: foo tree: bar blob: baz.c """) hash1 = shelf.commit('first\n') hash2 = shelf.commit('second\n') self.assertEqual(hash1, hash2) buf = StringIO() shelf.dump_objects(buf) self.assertEqual( """tree ca37be3e31987d8ece35001301c0b8f1fccbb888 tree 95b790693f3b5934c63d10b8b007e4758f6134a9: foo tree c03cdd65fa74c272bed2e9a48e3ed19402576e19: bar blob ea93d5cc5f34e13d2a55a5866b75e2c58993d253: baz.c """, buf.getvalue()) hash3 = shelf.current_head() self.assertEqual(hash1, hash3) commit = gitshelve.git('cat-file', 'commit', 'test', keep_newline=True) self.assert_(re.search('first\n$', commit)) data = gitshelve.git('cat-file', 'blob', 'test:foo/bar/baz.c', keep_newline=True) self.assertEqual(text, data) del shelf shelf = gitshelve.open('test') self.assertEqual( """tree ca37be3e31987d8ece35001301c0b8f1fccbb888 tree 95b790693f3b5934c63d10b8b007e4758f6134a9: foo tree c03cdd65fa74c272bed2e9a48e3ed19402576e19: bar blob ea93d5cc5f34e13d2a55a5866b75e2c58993d253: baz.c """, buf.getvalue()) self.assertEqual(text, shelf['foo/bar/baz.c']) del shelf
def testInsertion(self): shelf = gitshelve.open('test') text = "Hello, this is a test\n" shelf['foo/bar/baz.c'] = text buf = StringIO() shelf.dump_objects(buf) self.assertEqual(buf.getvalue(), """tree: foo tree: bar blob: baz.c """) hash1 = shelf.commit('first\n') hash2 = shelf.commit('second\n') self.assertEqual(hash1, hash2) buf = StringIO() shelf.dump_objects(buf) self.assertEqual("""tree ca37be3e31987d8ece35001301c0b8f1fccbb888 tree 95b790693f3b5934c63d10b8b007e4758f6134a9: foo tree c03cdd65fa74c272bed2e9a48e3ed19402576e19: bar blob ea93d5cc5f34e13d2a55a5866b75e2c58993d253: baz.c """, buf.getvalue()) hash3 = shelf.current_head() self.assertEqual(hash1, hash3) commit = gitshelve.git('cat-file', 'commit', 'test', keep_newline = True) self.assert_(re.search('first\n$', commit)) data = gitshelve.git('cat-file', 'blob', 'test:foo/bar/baz.c', keep_newline = True) self.assertEqual(text, data) del shelf shelf = gitshelve.open('test') self.assertEqual("""tree ca37be3e31987d8ece35001301c0b8f1fccbb888 tree 95b790693f3b5934c63d10b8b007e4758f6134a9: foo tree c03cdd65fa74c272bed2e9a48e3ed19402576e19: bar blob ea93d5cc5f34e13d2a55a5866b75e2c58993d253: baz.c """, buf.getvalue()) self.assertEqual(text, shelf['foo/bar/baz.c']) del shelf
def testDetachedRepo(self): shelf = gitshelve.open(repository = '/tmp/repo-test') text = "Hello, world!\n" shelf['foo.txt'] = text try: shelf.sync() gitshelve.git('clone', '/tmp/repo-test', '/tmp/repo-test-clone') try: self.assert_(os.path.isfile('/tmp/repo-test-clone/foo.txt')) data = open('/tmp/repo-test-clone/foo.txt') try: self.assertEqual(text, data.read()) finally: data.close() finally: if os.path.isdir('/tmp/repo-test-clone'): shutil.rmtree('/tmp/repo-test-clone') finally: del shelf if os.path.isdir('/tmp/repo-test'): shutil.rmtree('/tmp/repo-test')
def testDetachedRepo(self): repotest = os.path.join(self.tmpdir, 'repo-test') repotestclone = os.path.join(self.tmpdir, 'repo-test-clone') shelf = gitshelve.open(repository = repotest) text = "Hello, world!\n" shelf['foo.txt'] = text try: shelf.sync() gitshelve.git('clone', repotest, repotestclone) clonedfoo = os.path.join(repotestclone, 'foo.txt') try: self.assert_(os.path.isfile(clonedfoo)) data = open(clonedfoo) try: self.assertEqual(text, data.read()) finally: data.close() finally: if os.path.isdir(repotestclone): shutil.rmtree(repotestclone) finally: del shelf if os.path.isdir(repotest): shutil.rmtree(repotest)
def testDetachedRepo(self): repotest = os.path.join(self.tmpdir, 'repo-test') repotestclone = os.path.join(self.tmpdir, 'repo-test-clone') shelf = gitshelve.open(repository=repotest) text = "Hello, world!\n" shelf['foo.txt'] = text try: shelf.sync() gitshelve.git('clone', repotest, repotestclone) clonedfoo = os.path.join(repotestclone, 'foo.txt') try: self.assert_(os.path.isfile(clonedfoo)) data = open(clonedfoo) try: self.assertEqual(text, data.read()) finally: data.close() finally: if os.path.isdir(repotestclone): shutil.rmtree(repotestclone) finally: del shelf if os.path.isdir(repotest): shutil.rmtree(repotest)
def __SaveToShelf(self,ticketId,data,message): if 'uuid' in data: del data['uuid'] if 'num' in data: del data['num'] shelfData = gitshelve.open(branch=self.branch) shelfData['active/%s'%ticketId] = str(data) shelfData.commit(message) shelfData.close()
def __LoadNumMap(self): if self.numMap is None: shelfData = gitshelve.open(branch=self.branch) try: self.numMap = shelfData[GITTKT_NUM_MAP_FILE] except KeyError: #reading from the shelf failed, so we have to start new self.numMap = "" shelfData.close()
def testAdd(self): ticketDataOld = { 'field1' : 'data1', 'field2' : 'data2', } ticketId = self.gitTktFolder.Add(ticketDataOld.copy()) self.assertIn('Added Ticket ',self.stream.getvalue()) self.ClearStream() #assert that the ticket was added to the shelf shelf = gitshelve.open(branch = self.branch) data = eval(shelf['active/%s'%ticketId]) newData = {} for key,value in data.items(): if key not in GitTktFolder.GITTKT_RESERVED_FIELD_NAMES: newData[key] = value self.assertEqual(ticketDataOld,newData) #verify the number map is setup correctly data = shelf['active/%s'%GitTktFolder.GITTKT_NUM_MAP_FILE] ticketNumFile = "1\t%s\n"%ticketId self.assertEqual(str(data),ticketNumFile) #verify we strip out uuid and num from the ticket data ticketDataNew = { 'field1' : 'data1', 'field2' : 'data2', 'uuid' : 'data3', 'num' : '1', } ticketId = self.gitTktFolder.Add(ticketDataNew) self.assertIn('Added Ticket ',self.stream.getvalue()) self.ClearStream() #assert that the ticket was added to the shelf shelf = gitshelve.open(branch = self.branch) data = eval(shelf['active/%s'%ticketId]) newData = {} for key,value in data.items(): if key not in GitTktFolder.GITTKT_RESERVED_FIELD_NAMES: newData[key] = value self.assertEqual(ticketDataOld,newData) data = shelf['active/%s'%GitTktFolder.GITTKT_NUM_MAP_FILE] ticketNumFile += "2\t%s\n"%ticketId self.assertEqual(str(data),ticketNumFile)
def __init__(self, repodir, pubkey_getter, repobranch='numbex'): self.repobranch = repobranch self.repodir = repodir if self.repodir and self.repobranch: self.shelf = gitshelve.open(self.repobranch, repository=self.repodir) else: self.shelf = None self.get_pubkeys = pubkey_getter self.daemon = None self.log = logging.getLogger("git")
def __GetTicketData(self,ticketId): local,uuid = self.__GetTicketIds(ticketId) if uuid is None: raise GitTktError("Ticket not found: %s"%ticketId) shelfData = gitshelve.open(branch=self.branch) returnData = ticketData = eval(shelfData["active/%s"%uuid]) returnData['num'] = local returnData['uuid'] = uuid shelfData.close() return returnData
def testBasicInsertion(self): shelf = gitshelve.open('test') text = "Hello, this is a test\n" shelf['foo/bar/baz.c'] = text self.assertEqual(text, shelf['foo/bar/baz.c']) def foo1(shelf): return shelf['foo/bar'] self.assertRaises(exceptions.KeyError, foo1, shelf) del shelf
def testBlobStore(self): """Test use a gitshelve as a generic blob store.""" try: blobpath = os.path.join(self.tmpdir, 'blobs') shelf = gitshelve.open(repository=blobpath, keep_history=False) text = "This is just some sample text.\n" hash = shelf.put(text) buf = StringIO() shelf.dump_objects(buf) self.assertEqual( """tree: ac blob acd291ce81136338a729a30569da2034d918e057: d291ce81136338a729a30569da2034d918e057 """, buf.getvalue()) self.assertEqual(text, shelf.get(hash)) shelf.sync() buf = StringIO() shelf.dump_objects(buf) self.assertEqual( """tree 127093ef9a92ebb1f49caa5ecee9ff7139db3a6c tree 6c6167149ccc5bf60892b65b84322c1943f5f7da: ac blob acd291ce81136338a729a30569da2034d918e057: d291ce81136338a729a30569da2034d918e057 """, buf.getvalue()) del shelf shelf = gitshelve.open(repository=blobpath, keep_history=False) buf = StringIO() shelf.dump_objects(buf) self.assertEqual( """tree 6c6167149ccc5bf60892b65b84322c1943f5f7da: ac blob acd291ce81136338a729a30569da2034d918e057: d291ce81136338a729a30569da2034d918e057 """, buf.getvalue()) self.assertEqual(text, shelf.get(hash)) del shelf finally: if os.path.isdir(blobpath): shutil.rmtree(blobpath)
def testBlobStore(self): blobpath = None """Test use a gitshelve as a generic blob store.""" try: blobpath = os.path.join(self.gitDir, 'blobs') shelf = gitshelve.open(repository = blobpath, keep_history = False) text = "This is just some sample text.\n" hash = shelf.put(text) buf = StringIO() shelf.dump_objects(buf) self.assertEqual("""tree: ac blob acd291ce81136338a729a30569da2034d918e057: d291ce81136338a729a30569da2034d918e057 """, buf.getvalue()) self.assertEqual(text, shelf.get(hash)) shelf.sync() buf = StringIO() shelf.dump_objects(buf) self.assertEqual("""tree 127093ef9a92ebb1f49caa5ecee9ff7139db3a6c tree 6c6167149ccc5bf60892b65b84322c1943f5f7da: ac blob acd291ce81136338a729a30569da2034d918e057: d291ce81136338a729a30569da2034d918e057 """, buf.getvalue()) del shelf shelf = gitshelve.open(repository = blobpath, keep_history = False) buf = StringIO() shelf.dump_objects(buf) self.assertEqual("""tree 6c6167149ccc5bf60892b65b84322c1943f5f7da: ac blob acd291ce81136338a729a30569da2034d918e057: d291ce81136338a729a30569da2034d918e057 """, buf.getvalue()) self.assertEqual(text, shelf.get(hash)) del shelf finally: if blobpath and os.path.isdir(blobpath): shutil.rmtree(blobpath)
def testFolders(self): #test with no folders self.gittkt.Folders() self.assertRegexpMatches(self.stream.getvalue(),"No folders found.") #test with some shelves shelf = gitshelve.open(self.branch) shelf['active/numbers.txt'] = 'text' shelf['archived/numbers.txt'] = 'text' shelf.commit() self.stream.truncate(0) self.gittkt.Folders() self.assertRegexpMatches(self.stream.getvalue(),"active\narchived\n")
def __AddToNumMap(self,ticketId): self.__LoadNumMap() #attempt to read it from te shelf if self.__GetTicketIds(ticketId) == (None,None) and len(self.numMap) > 0: lastEntry = self.numMap.split("\n")[-2] self.nextNum = int(lastEntry[:lastEntry.find("\t")]) self.nextNum += 1 self.numMap += "%d\t%s\n"%(self.nextNum,ticketId) commitMsg = "Updating map with %d %s"%(self.nextNum, ticketId) shelfData = gitshelve.open(branch=self.branch) shelfData['%s/%s'%(self.name,GITTKT_NUM_MAP_FILE)] = self.numMap shelfData.commit(commitMsg) shelfData.close()
def testIterator(self): shelf = gitshelve.open('test') text = "Hello, this is a test\n" shelf['foo/bar/baz1.c'] = text shelf['alpha/beta/baz2.c'] = text shelf['apple/orange/baz3.c'] = text buf = StringIO() keys = shelf.keys() keys.sort() for path in keys: buf.write("path: (%s)\n" % path) self.assertEqual("""path: (alpha/beta/baz2.c) path: (apple/orange/baz3.c) path: (foo/bar/baz1.c) """, buf.getvalue())
def testIterator(self): shelf = gitshelve.open('test') text = "Hello, this is a test\n" shelf['foo/bar/baz1.c'] = text shelf['alpha/beta/baz2.c'] = text shelf['apple/orange/baz3.c'] = text buf = StringIO() keys = shelf.keys() keys.sort() for path in keys: buf.write("path: (%s)\n" % path) self.assertEqual( """path: (alpha/beta/baz2.c) path: (apple/orange/baz3.c) path: (foo/bar/baz1.c) """, buf.getvalue())
def testBasicDeletion(self): shelf = gitshelve.open('test') text = "Hello, this is a test\n" shelf['foo/bar/baz.c'] = text del shelf['foo/bar/baz.c'] def foo2(shelf): return shelf['foo/bar/baz.c'] self.assertRaises(exceptions.KeyError, foo2, shelf) shelf['foo/bar/baz.c'] = text del shelf['foo/bar'] def foo4(shelf): return shelf['foo/bar/baz.c'] self.assertRaises(exceptions.KeyError, foo4, shelf) del shelf
def _calculate_threshold(self): first = self.issues[0].get_property('id').value second = self.issues[1].get_property('id').value for i in range(len(first)): if first[i] != second[i]: break return i def __str__(self): msg = '' for issue in self.issues: msg += "[%s]%s: %s\n" %\ (issue.get_property('id').value[:self._threshold], issue.get_property('id').value[self._threshold:], issue.get_property('title') ) return msg.strip() import gitshelve import database # initialize gitshelve git_repo = gitshelve.open(branch='gitissius') # initialize issue manager issue_manager = database.IssueManager()
import json import gitshelve with open('UserDatabase.json', "r") as f: userData = json.loads(f.read()) #json_data=open('UserDatabase.json') #userData=json.load(json_data) #userData=json.dumps(userData, ensure_ascii=False) print(userData) userData=userData userData['Users'].append({"username":"******", "userpassword":"******", "googleid":"123", "googlepass":"******", "grouplist":[]}) with open('UserDatabase.json', 'w') as outfile: outfile.write(json.dumps(userData, sort_keys=True, indent=2)) #data = gitshelve.open(repository = '/team07project3/CalendarTest/jsontest') #data['/team07project3/CalendarTest/jsontest/UserDatabase.json']="something" #data.sync() gitoutfile=gitshelve.open('test') gitoutfile['C:/Users/twc2429/Downloads/team07project3/CalendarTest/jsontest/UserDatabase.json']="Hi" print("TESTING", gitoutfile) gitoutfile.sync() gitoutfile.close() #gitoutfile.commit("commit testing")
# create an empty repo gitshelve.git('symbolic-ref', 'HEAD', 'refs/heads/gitissius') cwd = common.find_repo_root() os.unlink(os.path.join(cwd, '.git', 'index')) gitshelve.git('clean', '-fdx') gitshelve.git('commit', '--allow-empty', '-m', 'Initialization') gitshelve.git('checkout', branch) try: gitshelve.git('stash', 'pop') except gitshelve.GitError, error: pass # open the repo now, since init was done common.git_repo = gitshelve.open(branch='gitissius') def close(): common.git_repo.close() def main(): initialize() try: command = sys.argv[1] except IndexError: # no command given print usage(commands.available_commands)
def testOpen(self): s = gitshelve.open()