From 368d4a5bfe141fe12476a78bc68209d8f7fbf194 Mon Sep 17 00:00:00 2001 From: Christian Tryti Date: Mon, 25 Jul 2011 11:12:50 +0200 Subject: [PATCH] devilryclient.plugins.updatemeta: Done up to deliveries --- devilryclient/plugins/updatemeta.py | 97 ++++++++++++++++++----------- 1 file changed, 59 insertions(+), 38 deletions(-) diff --git a/devilryclient/plugins/updatemeta.py b/devilryclient/plugins/updatemeta.py index 72319d82e3..8e9ab020ec 100755 --- a/devilryclient/plugins/updatemeta.py +++ b/devilryclient/plugins/updatemeta.py @@ -47,49 +47,70 @@ def run(self): 6: self.delivery_meta } + # sort the keys by increasing depth for key in sorted(self.metadata.keys(), key=lambda path: len(path.split(sep))): if key == '.meta': continue print key - #methods[self.depth(key)](key) + methods[self.depth(key)](key) def subject_meta(self, path): - # not much to do, really - pass - + # alias to something shorter + meta = self.metadata[path]['.meta'] + try: + meta['num_subjects'] += 1 + except KeyError: + meta['num_subjects'] = 0 + meta['num_deliveries'] = 0 + meta['num_late_deliveries'] = 0 + meta['num_periods'] = 0 + meta['num_corrected'] = 0 + meta['num_groups'] = 0 + meta['num_assignments'] = 0 + def period_meta(self, path): - print "sdf", path - periods = self.metadata[path] - periods['.meta']['num_assignmentgroups'] = 0 # for this subject - for period in periods.keys(): - if period[0] != '.': - path_dict['period'] = period - self.assignment_meta(path_dict) - - def assignment_meta(self, path_dict): - subject = path_dict['subject'] - period = path_dict['period'] - assignments = self.metadata[subject][period] - assignments['.meta']['num_assignmentgroups'] = 0 #for period - for assignment in assignments.keys(): - if assignment[0] != '.': - path_dict['assignment'] = assignment - self.group_meta(path_dict) - - def group_meta(self, path_dict): - subject = path_dict['subject'] - period = path_dict['period'] - assignment = path_dict['assignment'] - groups = self.metadata[subject][period][assignment] - groups['.meta']['num_assignmentgroups'] = 0 #for assignment - for group in groups.keys(): - if group[0] != '.': - path_dict['group'] = group - self.metadata['.meta']['num_assignmentgroups'] += 1 - self.metadata[subject]['.meta']['num_assignmentgroups'] += 1 - self.metadata[subject][period]['.meta']['num_assignmentgroups'] += 1 - self.metadata[subject][period][assignment]['.meta']['num_assignmentgroups'] += 1 - self.deadline_meta(path_dict) + # alias to something shorter + meta = self.metadata[path]['.meta'] + meta['num_groups'] = 0 + meta['num_deliveries'] = 0 + meta['num_late_deliveries'] = 0 + meta['num_assignments'] = 0 + + def assignment_meta(self, path): + meta = self.metadata[path]['.meta'] + meta['num_groups'] = 0 + meta['num_deliveries'] = 0 + meta['num_late_deliveries'] = 0 + + # update upwards + while dirname(path) != '': + path = dirname(path) + self.metadata[path]['.meta']['num_assignments'] += 1 + + def group_meta(self, path): + # alias to something shorter + meta = self.metadata[path]['.meta'] + meta['num_deliveries'] = 0 + meta['num_late_deliveries'] = 0 + + # update upwards + while dirname(path) != '': + path = dirname(path) + self.metadata[path]['.meta']['num_groups'] += 1 + + # subject = path_dict['subject'] + # period = path_dict['period'] + # assignment = path_dict['assignment'] + # groups = self.metadata[subject][period][assignment] + # groups['.meta']['num_assignmentgroups'] = 0 #for assignment + # for group in groups.keys(): + # if group[0] != '.': + # path_dict['group'] = group + # self.metadata['.meta']['num_assignmentgroups'] += 1 + # self.metadata[subject]['.meta']['num_assignmentgroups'] += 1 + # self.metadata[subject][period]['.meta']['num_assignmentgroups'] += 1 + # self.metadata[subject][period][assignment]['.meta']['num_assignmentgroups'] += 1 + # self.deadline_meta(path_dict) def deadline_meta(self, path): self.metadata[path]['deadline'] = deadline_unformat(basename(path)[2:]) @@ -105,11 +126,11 @@ def delivery_meta(self, path): # if delivery[0] != '.': # path_dict['delivery'] = delivery # self.file_meta(path_dict) - print path # alias to something short meta = self.metadata[path]['.meta'] meta['done'] = "TODO: noooo, we shouldnt overwrite this variable if it existed before sync" - meta['is_late'] = is_late(self.metadata[dirname(path)]['deadline']) + # meta['deliver_time'] = + #is_late(self.metadata[dirname(path)]['deadline']) def file_meta(self, path_dict): subject = path_dict['subject']