def test_persist_project(self): p = Project(path='/tmp/test_place',url='svn://alvesjnr@localhost/tmp/svnrepo') p.add_new_copy('/tmp/blah') p.create_current_copy() p.add_new_copy('/tmp/blah2') p.avoid_files(['/tmp/test_place/nha.c']) p.create_current_copy() diff = compare_tree('/tmp/test_place','/tmp/blah') self.assertFalse(diff['left_only'] or diff['right_only']) diff = compare_tree('/tmp/test_place','/tmp/blah2') self.assertTrue(diff['left_only'] == ['/nha.c'] and diff['right_only'] == []) os.system('date > /tmp/workspace/svnrepo/nha.c') os.system('date +%N >> /tmp/workspace/svnrepo/nha.c') os.system('svn commit /tmp/workspace/svnrepo/nha.c -m "changing things in repo"') self.assertFalse(filecmp.cmp('/tmp/workspace/svnrepo/nha.c','/tmp/blah/nha.c')) dumped_project = p.dumps() del(p) p = Project(dumped_project=dumped_project) p.update_project() p.update_copies() self.assertTrue(filecmp.cmp('/tmp/workspace/svnrepo/nha.c','/tmp/blah/nha.c')) diff = compare_tree('/tmp/test_place','/tmp/blah2') self.assertTrue(diff['left_only'] == ['/nha.c'] and diff['right_only'] == [])
def clone_copy(dist_file,copy_name,clone_name,license=None): with open(dist_file) as f: project_dict = pickle.loads(f.read()) project = Project(dumped_project=project_dict['project']) project = project.clone_copy(copy_name,clone_name) project_dict['project'] = project.dumps() with open(dist_file,'w') as f: f.write(pickle.dumps(project_dict))
class AppProject(object): """ AppProject is an object that represents an Project object inside the GUI This separations exists to keep Project and GUI totally unconnected """ def __init__(self,project=None,dumped_app_project=None): if project: self.project = project self.saved = False self.path = '' self.name = '-' self.locked_copy = False # A locked copy is a copy that have not been physically copied yet elif dumped_app_project: obj = pickle.loads(dumped_app_project) self.path = obj['path'] self.project = Project(dumped_project=obj['project']) self.saved = True self.name = '-' self.locked_copy = False else: raise BaseException("You must provide either a Project or a dumped AppProject object") self.update_avoided_files() def dumps(self): obj = {'project':self.project.dumps(), 'path':self.path } return pickle.dumps(obj) def update_avoided_files(self): self.avoided_files = {} self.license = {} self.renamed_files = {} for copy in self.project.copies_manager.copies: self.avoided_files[copy.copy_name] = copy.avoided_files[:] self.renamed_files[copy.copy_name] = copy.change_profile.copy() self.license[copy.copy_name] = copy.license