def repo_with_col(repo): repo = hangar.Repository(Path.cwd()) co = repo.checkout(write=True) arr = np.arange(20).reshape(4, 5) co.add_ndarray_column('ndcol', prototype=arr) co.commit('init column') co.close() yield None repo._env._close_environments()
def test_stock_init_on_existing_hangar_repo(self, cwd): repo = hangar.Repository(cwd, exists=False) repo.init("a", "[email protected]") repo._env._close_environments() assert not cwd.joinpath("head.stock").exists() init_repo() assert cwd.joinpath("head.stock").exists() with open(cwd.joinpath(".gitignore")) as f: assert "\n.hangar\n" in f.read()
def repo_with_aset(repo): repo = hangar.Repository(Path.cwd()) co = repo.checkout(write=True) arr = np.arange(20).reshape(4, 5) co.arraysets.init_arrayset('aset', prototype=arr) co.commit('init aset') co.close() yield None repo._env._close_environments()
def test_stock_init_on_existing_hangar_repo(self, cwd): repo = hangar.Repository(cwd, exists=False) repo.init('a', '[email protected]') repo._env._close_environments() assert not cwd.joinpath('head.stock').exists() init_repo() assert cwd.joinpath('head.stock').exists() with open(cwd.joinpath('.gitignore')) as f: assert '\n.hangar\n' in f.read()
def get_repo(identity): path = Path('/home/lost/') / str(identity) path.mkdir(exist_ok=True) repo = hangar.Repository(path) if not repo.initialized: repo.init(user_name=str(identity) + '_placeholder', user_email='*****@*****.**') co = repo.checkout(write=True) co.add_str_column('paths') co.add_ndarray_column('annotations', contains_subsamples=True, dtype=np.float64, variable_shape=True, shape=(200, 2)) co.commit('Added columns') co.close() else: if repo.writer_lock_held: repo.force_release_writer_lock() return repo
def post(self): dbm = access.DBMan(LOST_CONFIG) identity = get_jwt_identity() user = dbm.get_user_by_id(identity) if not user.has_role(roles.DESIGNER): dbm.close_session() return "You are not authorized.", 401 # get data from parser data = create_user_parser.parse_args() # find user in database user = None if 'email' in data: user = dbm.find_user_by_email(data['email']) if not user and 'user_name' in data: user = dbm.find_user_by_user_name(data['user_name']) if user: return {'message': 'User already exists.'}, 401 else: # ################# Hangar ############# path = Path('/home/lost/') / str(identity) path.mkdir(exist_ok=True) repo = hangar.Repository(path) if not repo.initialized: uname = '{}_{}'.format(identity, data['user_name']) email = data['email'] if data[ 'email'] else '*****@*****.**' repo.init(user_name=uname, user_email=email) co = repo.checkout(write=True) co.add_str_column('paths') co.add_ndarray_column('annotations', contains_subsamples=True, dtype=np.float64, variable_shape=True, shape=(200, 2)) co.commit('Added columns') co.close() # ###################################### user = DBUser( user_name=data['user_name'], email=data['email'], email_confirmed_at=datetime.datetime.utcnow(), password=data['password'], ) anno_role = dbm.get_role_by_name(roles.ANNOTATOR) user.roles.append(anno_role) user.groups.append(Group(name=user.user_name, is_user_default=True)) if data['roles']: for role_name in data['roles']: if role_name == 'Designer': designer_role = dbm.get_role_by_name(roles.DESIGNER) user.roles.append(designer_role) if data['groups']: for group_name in data['groups']: group = dbm.get_group_by_name(group_name) if group: user.groups.append(group) dbm.save_obj(user) try: email.send_new_user(user, data['password']) except: pass dbm.close_session() return {'message': 'success'}, 200
co.close() return aset_name def fill_data(repo, aset_name, count, branch_name='master'): commit_every = random.randint(30, 50) co = repo.checkout(write=True, branch=branch_name) aset = co.arraysets[aset_name] shape = aset.shape for i in tqdm(range(count)): aset[i] = np.random.random(shape) if i % commit_every == 0: co.commit(f"commit #{i}") if co.diff.status() == "DIRTY": co.commit('filled data') co.close() nrepos = os.environ.get('NDUMMY') if nrepos: for i in range(int(nrepos)): print(f"Making repo #{i}") path = BOARD_DIR.joinpath(f'mydummyrepo_{i}') path.mkdir() repo = hangar.Repository(path) repo.init(user_name=f'name_{i}', user_email=f'email_{i}@abc.com', remove_old=True) aset_name = make_arrayset(i, repo) datacount = random.randint(100, 300) fill_data(repo, aset_name, datacount)