def flatten(fpath, modnames): txt = '' with open(fpath, 'r') as f: while True: line = f.readline() if not line: break l = line.rstrip() if pydep.LIKELY_IMPORT_PAT.match( l) and not pydep.COMMENT_PAT.match(l): m = pydep.IMPORT_PAT.match(l) if m: items = pydep.get_imports_from_regex_match(m.group(1)) items = [flatten_module_name(m, modnames) for m in items] line = 'import %s' % ', '.join(items) else: m = pydep.FROM_IMPORT_PAT.match(l) if m: line = '%sfrom %s import %s' % ( l[0:m.start(1)], flatten_module_name(m.group(1), modnames), m.group(2)) txt += l + '\r\n' ioutil.write_if_different( fpath, txt, compare_func=text_diff.texts_differ_ignore_whitespace)
def exportFile(self, fullpath, relpath): m = STRINGSFILE_PAT.match(fullpath) locale = m.group(2) fullpath += ".xml" txt = TRANSFILE_HEADER % locale trans = self.byLocale.get(locale, None) if not trans: trans = {} en = self.byLocale["en"] ids = en.keys()[:] ids.sort() newCount = 0 reviewCount = 0 wordCountEng = 0 wordCountTrans = 0 chunk = u"" for id in ids: enstr = en[id] add = False for loc in enstr.fileLocs: if relpath[0 : relpath.rfind("/")] in loc.path: add = True if add: if not id in trans or trans[id].getValue() == u"?": newCount += 1 else: reviewCount += 1 if id in trans: wordCountTrans += trans[id].getWordCount() wordCountEng += en[id].getWordCount() if id in trans: strdef = trans[id] else: strdef = StrDef(id, "?", locale) chunk += u" <string>\n" chunk += u' <val lang="en">%s</val>\n' % prepForXml(enstr.getValue()) note = enstr.getNote() if note: chunk += u' <note lang="en">%s</note>\n' % note warnings = enstr.getWarnings() if warnings: enstr.warn() chunk += u" <warnings>" + " ".join(warnings) + u"</warnings>\n" chunk += u' <val lang="%s">%s</val>\n' % (locale, prepForXml(strdef.getValue())) chunk += u" </string>\n\n" txt += u" <info>\n" txt += u" <newStrings>%d</newStrings>\n" % newCount txt += u" <reviewStrings>%d</reviewStrings>\n" % reviewCount txt += u" <numStrings>%d</numStrings>\n" % (newCount + reviewCount) txt += u" <wordCountEnglish>%d</wordCountEnglish>\n" % wordCountEng txt += u" <wordCount%s>%d</wordCount%s>\n" % (locale, wordCountTrans, locale) txt += u" <relativePath>%s</relativePath>\n" % relpath txt += u" </info>\n\n" txt += chunk txt += u"</strings>\n" ioutil.write_if_different(fullpath, txt) print (fullpath)
def _update_bash_funcs(): funcs = read_file(join_path(APP_FOLDER, 'templates/' + _SADM_BASH_CMDS_FILE)) funcs = subst(funcs, 'app_path', APP_PATH) funcs = subst(funcs, 'app_folder', APP_FOLDER) funcs = subst(funcs, 'sandbox_container_folder', config.sandbox_container_folder) cmds_path = APP_FOLDER + '/' + _SADM_BASH_CMDS_FILE updated = ioutil.write_if_different(cmds_path, funcs, compare_func=text_diff.texts_differ_ignore_whitespace) return cmds_path, updated
def update(self, relpath): txt = self.getTransText(relpath) if txt: fullpath = self.root + relpath add = not os.path.isfile(fullpath) if ioutil.write_if_different(fullpath, txt, compare_func=jsIsDifferent): if add: os.system("bzr add %s" % fullpath) else: print ("%s has been modified and needs to be checked in." % relpath) return True return False
def flatten(fpath, modnames): txt = '' with open(fpath, 'r') as f: while True: line = f.readline() if not line: break l = line.rstrip() if pydep.LIKELY_IMPORT_PAT.match(l) and not pydep.COMMENT_PAT.match(l): m = pydep.IMPORT_PAT.match(l) if m: items = pydep.get_imports_from_regex_match(m.group(1)) items = [flatten_module_name(m, modnames) for m in items] line = 'import %s' % ', '.join(items) else: m = pydep.FROM_IMPORT_PAT.match(l) if m: line = '%sfrom %s import %s' % ( l[0:m.start(1)], flatten_module_name(m.group(1), modnames), m.group(2)) txt += l + '\r\n' ioutil.write_if_different(fpath, txt, compare_func=text_diff.texts_differ_ignore_whitespace)
def update(self, relpath): txt = self.getTransText(relpath) if txt: fullpath = self.root + relpath add = not os.path.isfile(fullpath) if ioutil.write_if_different(fullpath, txt, compare_func=jsIsDifferent): if add: os.system('bzr add %s' % fullpath) else: print('%s has been modified and needs to be checked in.' % relpath) return True return False
def exportFile(self, fullpath, relpath): m = STRINGSFILE_PAT.match(fullpath) locale = m.group(2) fullpath += '.xml' txt = TRANSFILE_HEADER % locale trans = self.byLocale.get(locale, None) if not trans: trans = {} en = self.byLocale['en'] ids = en.keys()[:] ids.sort() newCount = 0 reviewCount = 0 wordCountEng = 0 wordCountTrans = 0 chunk = u'' for id in ids: enstr = en[id] add = False for loc in enstr.fileLocs: if relpath[0:relpath.rfind('/')] in loc.path: add = True if add: if not id in trans or trans[id].getValue() == u'?': newCount += 1 else: reviewCount += 1 if id in trans: wordCountTrans += trans[id].getWordCount() wordCountEng += en[id].getWordCount() if id in trans: strdef = trans[id] else: strdef = StrDef(id, '?', locale) chunk += u' <string>\n' chunk += u' <val lang="en">%s</val>\n' % prepForXml( enstr.getValue()) note = enstr.getNote() if note: chunk += u' <note lang="en">%s</note>\n' % note warnings = enstr.getWarnings() if warnings: enstr.warn() chunk += u' <warnings>' + ' '.join( warnings) + u'</warnings>\n' chunk += u' <val lang="%s">%s</val>\n' % ( locale, prepForXml(strdef.getValue())) chunk += u' </string>\n\n' txt += u' <info>\n' txt += u' <newStrings>%d</newStrings>\n' % newCount txt += u' <reviewStrings>%d</reviewStrings>\n' % reviewCount txt += u' <numStrings>%d</numStrings>\n' % (newCount + reviewCount) txt += u' <wordCountEnglish>%d</wordCountEnglish>\n' % wordCountEng txt += u' <wordCount%s>%d</wordCount%s>\n' % ( locale, wordCountTrans, locale) txt += u' <relativePath>%s</relativePath>\n' % relpath txt += u' </info>\n\n' txt += chunk txt += u'</strings>\n' ioutil.write_if_different(fullpath, txt) print(fullpath)