def handle_upload_file(file, filename, meeting, subdir): ''' This function takes a file object, a filename and a meeting object and subdir as string. It saves the file to the appropriate directory, get_upload_root() + subdir. If the file is a zip file, it creates a new directory in 'slides', which is the basename of the zip file and unzips the file in the new directory. ''' base, extension = os.path.splitext(filename) if extension == '.zip': path = os.path.join(get_upload_root(meeting), subdir, base) if not os.path.exists(path): os.mkdir(path) else: path = os.path.join(get_upload_root(meeting), subdir) # agendas and minutes can only have one file instance so delete file if it already exists if subdir in ('agenda', 'minutes'): old_files = glob.glob(os.path.join(path, base) + '.*') for f in old_files: os.remove(f) destination = open(os.path.join(path, filename), 'wb+') for chunk in file.chunks(): destination.write(chunk) destination.close() # unzip zipfile if extension == '.zip': os.chdir(path) os.system('unzip %s' % filename)
def handle_upload_file(file,filename,meeting,subdir): ''' This function takes a file object, a filename and a meeting object and subdir as string. It saves the file to the appropriate directory, get_upload_root() + subdir. If the file is a zip file, it creates a new directory in 'slides', which is the basename of the zip file and unzips the file in the new directory. ''' base, extension = os.path.splitext(filename) if extension == '.zip': path = os.path.join(get_upload_root(meeting),subdir,base) if not os.path.exists(path): os.mkdir(path) else: path = os.path.join(get_upload_root(meeting),subdir) # agendas and minutes can only have one file instance so delete file if it already exists if subdir in ('agenda','minutes'): old_files = glob.glob(os.path.join(path,base) + '.*') for f in old_files: os.remove(f) destination = open(os.path.join(path,filename), 'wb+') for chunk in file.chunks(): destination.write(chunk) destination.close() # unzip zipfile if extension == '.zip': os.chdir(path) os.system('unzip %s' % filename)
def get_doc_filename(doc): ''' This function takes a Document of type slides,minute or agenda and returns the full path to the file on disk. During migration of the system the filename was saved in external_url, new files will also use this convention. ''' session = doc.session_set.all()[0] meeting = session.meeting if doc.external_url: return os.path.join(get_upload_root(meeting),doc.type.slug,doc.external_url) else: path = os.path.join(get_upload_root(meeting),doc.type.slug,doc.name) files = glob.glob(path + '.*') # TODO we might want to choose from among multiple files using some logic return files[0]
def delete_interim_meeting(request, meeting_num): ''' This view deletes the specified Interim Meeting and any material that has been uploaded for it. The pattern in urls.py ensures we don't call this with a regular meeting number. ''' meeting = get_object_or_404(Meeting, number=meeting_num) sessions = Session.objects.filter(meeting=meeting) group = sessions[0].group # delete directories path = get_upload_root(meeting) # do a quick sanity check on this path before we go and delete it parts = path.split('/') assert parts[-1] == group.acronym if os.path.exists(path): shutil.rmtree(path) meeting.delete() sessions.delete() url = reverse('proceedings_interim', kwargs={'acronym':group.acronym}) return HttpResponseRedirect(url)
def get_doc_filename(doc): ''' This function takes a Document of type slides,minute or agenda and returns the full path to the file on disk. During migration of the system the filename was saved in external_url, new files will also use this convention. ''' session = doc.session_set.all()[0] meeting = session.meeting if doc.external_url: return os.path.join(get_upload_root(meeting), doc.type.slug, doc.external_url) else: path = os.path.join(get_upload_root(meeting), doc.type.slug, doc.name) files = glob.glob(path + '.*') # TODO we might want to choose from among multiple files using some logic return files[0]
def delete_interim_meeting(request, meeting_num): ''' This view deletes the specified Interim Meeting and any material that has been uploaded for it. The pattern in urls.py ensures we don't call this with a regular meeting number. ''' meeting = get_object_or_404(Meeting, number=meeting_num) sessions = Session.objects.filter(meeting=meeting) group = sessions[0].group # delete directories path = get_upload_root(meeting) # do a quick sanity check on this path before we go and delete it parts = path.split('/') assert parts[-1] == group.acronym if os.path.exists(path): shutil.rmtree(path) meeting.delete() sessions.delete() url = reverse('proceedings_interim', kwargs={'acronym': group.acronym}) return HttpResponseRedirect(url)
def make_directories(meeting): ''' This function takes a meeting object and creates the appropriate materials directories ''' path = get_upload_root(meeting) os.umask(0) for leaf in ('slides','agenda','minutes','id','rfc'): target = os.path.join(path,leaf) if not os.path.exists(target): os.makedirs(target)
def make_directories(meeting): ''' This function takes a meeting object and creates the appropriate materials directories ''' path = get_upload_root(meeting) os.umask(0) for leaf in ('slides', 'agenda', 'minutes', 'id', 'rfc'): target = os.path.join(path, leaf) if not os.path.exists(target): os.makedirs(target)
def make_directories(meeting): ''' This function takes a meeting object and creates the appropriate materials directories ''' path = get_upload_root(meeting) os.umask(0) if not os.path.exists(path): os.makedirs(path) for d in ('slides', 'agenda', 'minutes', 'id', 'rfc', 'bluesheets'): if not os.path.exists(os.path.join(path, d)): os.mkdir(os.path.join(path, d))
def make_directories(meeting): ''' This function takes a meeting object and creates the appropriate materials directories ''' path = get_upload_root(meeting) os.umask(0) if not os.path.exists(path): os.makedirs(path) for d in ('slides','agenda','minutes','id','rfc','bluesheets'): if not os.path.exists(os.path.join(path,d)): os.mkdir(os.path.join(path,d))
def get_proceedings_path(self, group=None): path = os.path.join(get_upload_root(self),'proceedings.html') return path
def create_proceedings(meeting, group, is_final=False): ''' This function creates the proceedings html document. It gets called anytime there is an update to the meeting or the slides for the meeting. NOTE: execution is aborted if the meeting is older than 79 because the format changed. ''' # abort, proceedings from meetings before 79 have a different format, don't overwrite if meeting.type_id == 'ietf' and int(meeting.number) < 79: return sessions = Session.objects.filter(meeting=meeting,group=group) if sessions: session = sessions[0] agenda,minutes,slides = get_material(session) else: agenda = None minutes = None slides = None chairs = group.role_set.filter(name='chair') secretaries = group.role_set.filter(name='secr') if group.parent: # Certain groups like Tools Team do no have a parent ads = group.parent.role_set.filter(name='ad') else: ads = None tas = group.role_set.filter(name='techadv') docs = Document.objects.filter(group=group,type='draft').order_by('time') meeting_root = get_upload_root(meeting) if meeting.type.slug == 'ietf': url_root = "%sproceedings/%s/" % (settings.MEDIA_URL,meeting.number) else: url_root = "%sproceedings/interim/%s/%s/" % ( settings.MEDIA_URL, meeting.date.strftime('%Y/%m/%d'), group.acronym) # Only do these tasks if we are running official proceedings generation, # otherwise skip them for expediency. This procedure is called any time meeting # materials are uploaded/deleted, and we don't want to do all this work each time. if is_final: # ---------------------------------------------------------------------- # Find active Drafts and RFCs, copy them to id and rfc directories drafts = docs.filter(states__slug='active') for draft in drafts: source = os.path.join(draft.get_file_path(),draft.filename_with_rev()) target = os.path.join(meeting_root,'id') if not os.path.exists(target): os.makedirs(target) if os.path.exists(source): shutil.copy(source,target) draft.bytes = os.path.getsize(source) else: draft.bytes = 0 draft.url = url_root + "id/%s" % draft.filename_with_rev() rfcs = docs.filter(states__slug='rfc') for rfc in rfcs: # TODO should use get_file_path() here but is incorrect for rfcs rfc_num = get_rfc_num(rfc) filename = "rfc%s.txt" % rfc_num alias = rfc.docalias_set.filter(name='rfc%s' % rfc_num) source = os.path.join(settings.RFC_PATH,filename) target = os.path.join(meeting_root,'rfc') rfc.rmsg = '' rfc.msg = '' if not os.path.exists(target): os.makedirs(target) try: shutil.copy(source,target) rfc.bytes = os.path.getsize(source) except IOError: pass rfc.url = url_root + "rfc/%s" % filename rfc.num = "RFC %s" % rfc_num # check related documents # check obsoletes related = rfc.relateddocument_set.all() for item in related.filter(relationship='obs'): rfc.msg += 'obsoletes %s ' % item.target.name #rfc.msg += ' '.join(item.__str__().split()[1:]) updates_list = [x.target.name.upper() for x in related.filter(relationship='updates')] if updates_list: rfc.msg += 'updates ' + ','.join(updates_list) # check reverse related rdocs = RelatedDocument.objects.filter(target=alias) for item in rdocs.filter(relationship='obs'): rfc.rmsg += 'obsoleted by RFC %s ' % get_rfc_num(item.source) updated_list = ['RFC %s' % get_rfc_num(x.source) for x in rdocs.filter(relationship='updates')] if updated_list: rfc.msg += 'updated by ' + ','.join(updated_list) # ---------------------------------------------------------------------- # check for blue sheets pattern = os.path.join(meeting_root,'bluesheets','bluesheets-%s-%s-*' % (meeting.number,group.acronym.lower())) files = glob.glob(pattern) bluesheets = [] for name in files: basename = os.path.basename(name) obj = {'name': basename, 'url': url_root + "bluesheets/" + basename} bluesheets.append(obj) bluesheets = sorted(bluesheets, key = lambda x: x['name']) # ---------------------------------------------------------------------- else: drafts = rfcs = bluesheets = None # the simplest way to display the charter is to place it in a <pre> block # however, because this forces a fixed-width font, different than the rest of # the document we modify the charter by adding replacing linefeeds with <br>'s if group.charter: charter = get_charter_text(group).replace('\n','<br />') ctime = group.charter.time else: charter = None ctime = None # rather than return the response as in a typical view function we save it as the snapshot # proceedings.html response = render_to_response('proceedings/proceedings.html',{ 'bluesheets': bluesheets, 'charter': charter, 'ctime': ctime, 'drafts': drafts, 'group': group, 'chairs': chairs, 'secretaries': secretaries, 'ads': ads, 'tas': tas, 'meeting': meeting, 'rfcs': rfcs, 'slides': slides, 'minutes': minutes, 'agenda': agenda} ) # save proceedings proceedings_path = get_proceedings_path(meeting,group) f = open(proceedings_path,'w') f.write(response.content) f.close() try: os.chmod(proceedings_path, 0664) except OSError: pass # rebuild the directory if meeting.type.slug == 'interim': create_interim_directory()
def create_proceedings(meeting, group, is_final=False): ''' This function creates the proceedings html document. It gets called anytime there is an update to the meeting or the slides for the meeting. NOTE: execution is aborted if the meeting is older than 79 because the format changed. ''' # abort, proceedings from meetings before 79 have a different format, don't overwrite if meeting.type_id == 'ietf' and int(meeting.number) < 79: return sessions = Session.objects.filter(meeting=meeting,group=group) if sessions: session = sessions[0] agenda,minutes,slides = get_material(session) else: agenda = None minutes = None slides = None chairs = group.role_set.filter(name='chair') secretaries = group.role_set.filter(name='secr') if group.parent: # Certain groups like Tools Team do no have a parent ads = group.parent.role_set.filter(name='ad') else: ads = None tas = group.role_set.filter(name='techadv') docs = Document.objects.filter(group=group,type='draft').order_by('time') meeting_root = get_upload_root(meeting) if meeting.type.slug == 'ietf': url_root = "%s/proceedings/%s/" % (settings.MEDIA_URL,meeting.number) else: url_root = "%s/proceedings/interim/%s/%s/" % ( settings.MEDIA_URL, meeting.date.strftime('%Y/%m/%d'), group.acronym) # Only do these tasks if we are running official proceedings generation, # otherwise skip them for expediency. This procedure is called any time meeting # materials are uploaded/deleted, and we don't want to do all this work each time. if is_final: # ---------------------------------------------------------------------- # Find active Drafts and RFCs, copy them to id and rfc directories drafts = docs.filter(states__slug='active') for draft in drafts: source = os.path.join(draft.get_file_path(),draft.filename_with_rev()) target = os.path.join(meeting_root,'id') if not os.path.exists(target): os.makedirs(target) if os.path.exists(source): shutil.copy(source,target) draft.bytes = os.path.getsize(source) else: draft.bytes = 0 draft.url = url_root + "id/%s" % draft.filename_with_rev() rfcs = docs.filter(states__slug='rfc') for rfc in rfcs: # TODO should use get_file_path() here but is incorrect for rfcs rfc_num = get_rfc_num(rfc) filename = "rfc%s.txt" % rfc_num alias = rfc.docalias_set.filter(name='rfc%s' % rfc_num) source = os.path.join(settings.RFC_PATH,filename) target = os.path.join(meeting_root,'rfc') rfc.rmsg = '' rfc.msg = '' if not os.path.exists(target): os.makedirs(target) shutil.copy(source,target) rfc.url = url_root + "rfc/%s" % filename rfc.bytes = os.path.getsize(source) rfc.num = "RFC %s" % rfc_num # check related documents # check obsoletes related = rfc.relateddocument_set.all() for item in related.filter(relationship='obs'): rfc.msg += 'obsoletes %s ' % item.target.name #rfc.msg += ' '.join(item.__str__().split()[1:]) updates_list = [x.target.name.upper() for x in related.filter(relationship='updates')] if updates_list: rfc.msg += 'updates ' + ','.join(updates_list) # check reverse related rdocs = RelatedDocument.objects.filter(target=alias) for item in rdocs.filter(relationship='obs'): rfc.rmsg += 'obsoleted by RFC %s ' % get_rfc_num(item.source) updated_list = ['RFC %s' % get_rfc_num(x.source) for x in rdocs.filter(relationship='updates')] if updated_list: rfc.msg += 'updated by ' + ','.join(updated_list) # ---------------------------------------------------------------------- # check for blue sheets pattern = os.path.join(meeting_root,'bluesheets','bluesheets-%s-%s-*' % (meeting.number,group.acronym.lower())) files = glob.glob(pattern) bluesheets = [] for name in files: basename = os.path.basename(name) obj = {'name': basename, 'url': url_root + "bluesheets/" + basename} bluesheets.append(obj) bluesheets = sorted(bluesheets, key = lambda x: x['name']) # ---------------------------------------------------------------------- else: drafts = rfcs = bluesheets = None # the simplest way to display the charter is to place it in a <pre> block # however, because this forces a fixed-width font, different than the rest of # the document we modify the charter by adding replacing linefeeds with <br>'s if group.charter: charter = get_charter_text(group).replace('\n','<br />') ctime = group.charter.time else: charter = None ctime = None # rather than return the response as in a typical view function we save it as the snapshot # proceedings.html response = render_to_response('proceedings/proceedings.html',{ 'bluesheets': bluesheets, 'charter': charter, 'ctime': ctime, 'drafts': drafts, 'group': group, 'chairs': chairs, 'secretaries': secretaries, 'ads': ads, 'tas': tas, 'meeting': meeting, 'rfcs': rfcs, 'slides': slides, 'minutes': minutes, 'agenda': agenda} ) # save proceedings proceedings_path = get_proceedings_path(meeting,group) f = open(proceedings_path,'w') f.write(response.content) f.close() try: os.chmod(proceedings_path, 0664) except OSError: pass # rebuild the directory if meeting.type.slug == 'interim': create_interim_directory()
def get_proceedings_path(meeting,group): if meeting.type_id == 'ietf': path = os.path.join(get_upload_root(meeting),group.acronym + '.html') elif meeting.type_id == 'interim': path = os.path.join(get_upload_root(meeting),'proceedings.html') return path
def get_proceedings_path(self, group=None): path = os.path.join(get_upload_root(self), 'proceedings.html') return path
def get_proceedings_path(meeting, group): if meeting.type_id == 'ietf': path = os.path.join(get_upload_root(meeting), group.acronym + '.html') elif meeting.type_id == 'interim': path = os.path.join(get_upload_root(meeting), 'proceedings.html') return path