def mark_as_started(self, f, assignee, role): role = match_arg(role, ['revisor1']) for c in self.__data: if role == 'revisor1': cond = (c.trn_filename == f) if cond: c.rev1_assignee = assignee c.rev1_assigned = True else: raise ValueError("Unexpected role input:", role)
def sandbox_f(user, role): role = match_arg(role, ["translator", "revisor1", "revisor2"]) if role == "translator": postfix = "trn" elif role == "revisor1": postfix = "rev1" elif role == "revisor2": postfix = "rev2" else: ValueError("There is something wrong here") return os.path.join(sandbox_dir, "{0}_{1}.srt".format(user, postfix))
def keep_swots(self, users, role): role = match_arg(role, ['translator', 'revisor1', 'revisor2']) swots = [] for u in users: not_completed = self.avanz.unfinished_homeworks(u, role) if len(not_completed) > 0: print(u, 'has unfinished files:', not_completed, 'Ignoring the request') else: swots.append(u) return swots
def filenames(self, phase): phase = match_arg(phase, ['trn', 'rev2']) res = [] for c in self.__data: if phase == 'trn': res += [c.trn_filename] elif phase == 'rev2': res += [c.rev2_filename] if (c.rev2_filename not in res) \ else [] else: raise ValueError("Unexpected role phase:", phase) return res
def keep_sandboxed(self, users, role): role = match_arg(role, ['translator', 'revisor1', 'revisor2']) avail = [] miss = [] for u in users: s = self.add_basedir(sandbox_f(u, role=role)) if os.path.isfile(s): avail.append(u) else: miss.append(u) if len(miss) > 0: msg = "Some users have no sandbox file for " print(msg, role, "role: ", miss, '. Ignoring the request.') return avail
def assign(self, old_f, assignee, new_f, role): role = match_arg(role, ['translator', 'revisor2']) for c in self.__data: if role == 'translator': cond = (c.trn_filename == old_f) if cond: c.trn_assignee = assignee c.trn_assigned = True c.trn_filename = new_f elif role =='revisor2': cond = (c.rev2_filename == old_f) if cond: c.rev2_assignee = assignee c.rev2_assigned = True c.rev2_filename = new_f else: raise ValueError("Unexpected role input:", role)
def to_be_completed_files(self, role): role = match_arg(role, ['translator', 'revisor1', 'revisor2']) res = [] for c in self.__data: if role == 'translator': cond = c.trn_assigned and (not c.trn_completed) res += [c.trn_filename] if cond else [] elif role == 'revisor1': cond = (c.rev1_assigned) and (not c.rev1_completed) res += [c.trn_filename] if cond else [] elif role =='revisor2': # return unique values here cond = (c.rev2_assigned) and (not c.rev2_completed) and \ (not c.rev2_filename in res) res += [c.rev2_filename] if cond else [] else: raise ValueError("Unexpected role input:", role) return res
def try_assign(users, role): role = match_arg(role, ['translator', 'revisor2']) ascii_header(role) # check for user pemissions users = self.users.keep_allowed(users, role) # check for available sandboxes users = self.keep_sandboxed(users, role) # check for done homeworks users = self.keep_swots(users, role) # are there remaining users for the request? if len(users) == 0: raise ValueError("No user available for this request.") # if there are assignable files, do the thing assignable_files = self.avanz.assignable_files(role) if len(assignable_files): max_assignments = min(len(users), len(assignable_files)) assigned_users = [] assigned_paths = [] for i in range(max_assignments): assignee = users[i] assigned_users.append(assignee) old_f = assignable_files[i] old_p = os.path.join(self.prj_dir, old_f) new_f = "{0}_{1}.srt".format( os.path.splitext(old_f)[0], assignee) new_p = os.path.join(self.prj_dir, new_f) assigned_paths.append(new_p) worker(old_f, assignee, new_f, old_p, new_p, role) # remove ./ from the path for pretty printing assigned_paths = [p[2:] for p in assigned_paths] # do list paths for translators if role == 'translator': listing(assigned_paths) #todohere elif role == 'revisor2': rev2_urls = [ "{0}/{1}".format(raw_gh_path, p) for p in assigned_paths ] listing(rev2_urls) else: ValueError("Something wrong here") else: print("No assignable files, all done, yee!")
def unfinished_homeworks(self, user, role): role = match_arg(role, ['translator', 'revisor1', 'revisor2']) res = [] for c in self.__data: if role == 'translator': cond = (user == c.trn_assignee) and (c.trn_assigned) and \ (not c.trn_completed) res += [c.trn_filename] if cond else [] elif role == 'revisor1': cond = (user == c.rev1_assignee) and (c.rev1_assigned) and \ (not c.rev1_completed) res += [c.rev1_filename] if cond else [] elif role =='revisor2': cond = (user == c.rev2_assignee) and (c.rev2_assigned) and \ (not c.rev2_completed) res += [c.rev2_filename] if cond else [] else: raise ValueError("Unexpected role input:", role) return res
def keep_allowed(self, users, role): ## input github logins and check that are allowed as role ## siano stati abilitati in data/users.csv (a seconda del permesso ## specificato) restituisce gli utenti abilitati, segnala se ve ne ## sono di non abilitati e interrompe se nessuno è abilitato role = match_arg(role, ['translator', 'revisor1', 'revisor2']) if role == 'translator': allowed = self.translators() elif role == 'revisor1': allowed = self.revisors1() elif role == 'revisor2': allowed = self.revisors2() else: ValueError("there is something wrong here.") rval = [] for u in users: if u in allowed: rval.append(u) else: print("Ignoring request for", u, ". Not allowed") return rval
def mark_as_completed(self, f, phase): phase = match_arg(phase, ['trn', 'rev1', 'rev2']) rev2_ready = dict() rev2_complete = dict() for c in self.__data: if phase == 'trn': if c.trn_filename == f: c.trn_completed = True elif phase == 'rev1': if c.trn_filename == f: c.rev1_completed = True # checking if all rev1 are completed if (c.rev2_filename not in rev2_ready.keys()): rev2_ready[c.rev2_filename] = True rev2_ready[c.rev2_filename] = \ rev2_ready[c.rev2_filename] and c.rev1_completed elif phase == 'rev2': if c.rev2_filename == f: c.rev2_completed = True # checking if all rev2 are completed if (c.rev2_filename not in rev2_complete.keys()): rev2_complete[c.rev2_filename] = True rev2_complete[c.rev2_filename] = \ rev2_complete[c.rev2_filename] and c.rev2_completed else: raise ValueError("Unexpected phase input:", phase) # update creable rev2 if phase == 'rev1': for c in self.__data: # c.rev2_ready = rev2_complete[c.rev2_filename] c.rev2_ready = rev2_ready[c.rev2_filename] # checks: tutte le rev2 complete, creazione if phase == 'rev2': if (all(rev2_complete.values())): ascii_header('Tutte le revisioni sono complete') ascii_header('creare il file finale con make final-srt')