def updateConfigFile(config, filename, rmnames): wrapper = TextWrapper() wrapper.width = 80 wrapper.break_long_words = False wrapper.break_on_hyphens = False wrap = lambda names: '\n'.join(wrapper.wrap(' '.join(names))) didChange = False for propertyName, values in config.items('glyphs'): glyphNames = values.split() propChanged = False glyphNames2 = [name for name in glyphNames if name not in rmnames] if len(glyphNames2) < len(glyphNames): print('[fontbuild.cfg] updating glyphs property', propertyName) config.set('glyphs', propertyName, wrap(glyphNames2)+'\n') didChange = True if didChange: s = StringIO() config.write(s) s = s.getvalue() s = re.sub(r'\n(\w+)\s+=\s*', '\n\\1: ', s, flags=re.M) s = re.sub(r'((?:^|\n)\[[^\]]*\])', '\\1\n', s, flags=re.M) s = re.sub(r'\n\t\n', '\n\n', s, flags=re.M) s = s.strip() + '\n' print('Writing', filename) if not dryRun: with open(filename, 'w') as f: f.write(s)
def renameConfigFile(config, filename, newNames, dryRun=False, print=print): wrapper = TextWrapper() wrapper.width = 80 wrapper.break_long_words = False wrapper.break_on_hyphens = False wrap = lambda names: '\n'.join(wrapper.wrap(' '.join(names))) didRename = False for propertyName, values in config.items('glyphs'): glyphNames = values.split() # print(propertyName, glyphNames) propChanged = False for name in glyphNames: if name in newNames: sectionChanged = True if sectionChanged: config.set('glyphs', propertyName, wrap(glyphNames) + '\n') didRename = True # config.set(section, option, value) if didRename: s = StringIO() config.write(s) s = s.getvalue() s = re.sub(r'\n(\w+)\s+=\s*', '\n\\1: ', s, flags=re.M) s = re.sub(r'((?:^|\n)\[[^\]]*\])', '\\1\n', s, flags=re.M) s = re.sub(r'\n\t\n', '\n\n', s, flags=re.M) s = s.strip() + '\n' print('Writing', filename) if not dryRun: with open(filename, 'w') as f: f.write(s)
def linewrap(width = None): """Returns a function that wraps long lines to a max of 251 characters. Note that this function returns a list of lines, which is suitable as the argument for the spss.Submit function. """ wrapper = TextWrapper() wrapper.width = width or 251 wrapper.replace_whitespace = True wrapper.break_long_words = False wrapper.break_on_hyphens = False return wrapper.wrap
def dry_run(self): from textwrap import TextWrapper wrapper = TextWrapper() wrapper.subsequent_indent = ' ' wrapper.break_long_words = False wrapper.break_on_hyphens = False wrapper.width = 78 commands = [ '# Create %s' % self._object.full_name(), self.create_cmd(), self._hook.__str__(self._object) ] for command in commands: command.strip() if len(command) > 0: print ' \\\n'.join(wrapper.wrap(command)) print ''
def getMsg(self): primary_authors = [] for auth in self._abstract.getPrimaryAuthorList(): primary_authors.append("""%s (%s) <%s>""" % (auth.getFullName(), auth.getAffiliation(), auth.getEmail())) co_authors = [] for auth in self._abstract.getCoAuthorList(): email = "" if auth.getEmail() != "": email = " <%s>" % auth.getEmail() co_authors.append("""%s (%s)%s""" % (auth.getFullName(), auth.getAffiliation(), email)) speakers = [] for spk in self._abstract.getSpeakerList(): speakers.append(spk.getFullName()) tracks = [] for track in self._abstract.getTrackListSorted(): tracks.append("""%s""" % track.getTitle()) tw = TextWrapper() msg = [i18nformat("""_("Dear") %s,""") % self._abstract.getSubmitter().getStraightFullName()] msg.append("") msg.append(tw.fill(_("The submission of your abstract has been successfully processed."))) msg.append("") tw.break_long_words = False msg.append( tw.fill(i18nformat("""_("Abstract submitted"):\n<%s>.""") % urlHandlers.UHUserAbstracts.getURL(self._conf)) ) msg.append("") msg.append( tw.fill( i18nformat("""_("Status of your abstract"):\n<%s>.""") % urlHandlers.UHAbstractDisplay.getURL(self._abstract) ) ) msg.append("") tw.subsequent_indent = "" msg.append(tw.fill(i18nformat("""_("See below a detailed summary of your submitted abstract"):"""))) msg.append("") tw.subsequent_indent = " " * 3 msg.append(tw.fill(i18nformat("""_("Conference"): %s""") % self._conf.getTitle())) msg.append("") msg.append(tw.fill(i18nformat("""_("Submitted by"): %s""") % self._abstract.getSubmitter().getFullName())) msg.append("") msg.append( tw.fill( i18nformat("""_("Submitted on"): %s""") % self._abstract.getSubmissionDate().strftime("%d %B %Y %H:%M") ) ) msg.append("") msg.append(tw.fill(i18nformat("""_("Title"): %s""") % self._abstract.getTitle())) msg.append("") for f in self._conf.getAbstractMgr().getAbstractFieldsMgr().getFields(): msg.append(tw.fill(f.getCaption())) msg.append(self._abstract.getField(f.getId())) msg.append("") msg.append(tw.fill(i18nformat("""_("Primary Authors"):"""))) msg += primary_authors msg.append("") msg.append(tw.fill(i18nformat("""_("Co-authors"):"""))) msg += co_authors msg.append("") msg.append(tw.fill(i18nformat("""_("Abstract presenters"):"""))) msg += speakers msg.append("") msg.append(tw.fill(i18nformat("""_("Track classification"):"""))) msg += tracks msg.append("") ctype = i18nformat("""--_("not specified")--""") if self._abstract.getContribType() is not None: ctype = self._abstract.getContribType().getName() msg.append(tw.fill(i18nformat("""_("Presentation type"): %s""") % ctype)) msg.append("") msg.append(tw.fill(i18nformat("""_("Comments"): %s""") % self._abstract.getComments())) msg.append("") return "\n".join(msg)
def getMsg( self ): primary_authors = [] for auth in self._abstract.getPrimaryAuthorList(): primary_authors.append("""%s (%s) <%s>"""%(auth.getFullName(), auth.getAffiliation(), auth.getEmail()) ) co_authors = [] for auth in self._abstract.getCoAuthorList(): email = "" if auth.getEmail() != "": email = " <%s>"%auth.getEmail() co_authors.append( """%s (%s)%s"""%(auth.getFullName(), auth.getAffiliation(), email) ) speakers = [] for spk in self._abstract.getSpeakerList(): speakers.append( spk.getFullName() ) tracks = [] for track in self._abstract.getTrackListSorted(): tracks.append( """%s"""%track.getTitle() ) tw = TextWrapper() msg = [ i18nformat("""_("Dear") %s,""")%self._abstract.getSubmitter().getStraightFullName() ] msg.append( "" ) msg.append( tw.fill(_("The submission of your abstract has been successfully processed.")) ) msg.append( "" ) tw.break_long_words = False msg.append( tw.fill( i18nformat("""_("Abstract submitted"):\n<%s>.""")%urlHandlers.UHUserAbstracts.getURL( self._conf ) ) ) msg.append( "" ) msg.append( tw.fill( i18nformat("""_("Status of your abstract"):\n<%s>.""")%urlHandlers.UHAbstractDisplay.getURL( self._abstract ) ) ) msg.append( "" ) tw.subsequent_indent = "" msg.append( tw.fill( i18nformat("""_("See below a detailed summary of your submitted abstract"):""") ) ) msg.append( "" ) tw.subsequent_indent = " "*3 msg.append( tw.fill( i18nformat("""_("Conference"): %s""")%self._conf.getTitle() ) ) msg.append( "" ) msg.append( tw.fill( i18nformat("""_("Submitted by"): %s""")%self._abstract.getSubmitter().getFullName() ) ) msg.append( "" ) msg.append( tw.fill( i18nformat("""_("Submitted on"): %s""")%self._abstract.getSubmissionDate().strftime( "%d %B %Y %H:%M" ) ) ) msg.append( "" ) msg.append( tw.fill( i18nformat("""_("Title"): %s""")%self._abstract.getTitle() ) ) msg.append( "" ) for f in self._conf.getAbstractMgr().getAbstractFieldsMgr().getFields(): msg.append( tw.fill(f.getCaption()) ) msg.append( self._abstract.getField(f.getId()) ) msg.append( "" ) msg.append( tw.fill( i18nformat("""_("Primary Authors"):""") ) ) msg += primary_authors msg.append( "" ) msg.append( tw.fill( i18nformat("""_("Co-authors"):""") ) ) msg += co_authors msg.append( "" ) msg.append( tw.fill( i18nformat("""_("Abstract presenters"):""") ) ) msg += speakers msg.append( "" ) msg.append( tw.fill( i18nformat("""_("Track classification"):""") ) ) msg += tracks msg.append( "" ) ctype= i18nformat("""--_("not specified")--""") if self._abstract.getContribType() is not None: ctype=self._abstract.getContribType().getName() msg.append( tw.fill( i18nformat("""_("Presentation type"): %s""")%ctype) ) msg.append( "" ) msg.append( tw.fill( i18nformat("""_("Comments"): %s""")%self._abstract.getComments() ) ) msg.append( "" ) return "\n".join( msg )