def compile_bib(self, tempdir, master): base = os.path.realpath('.') cmd = shlex.split(self.config.get('compilation', 'bibliography')) cmd += [master] self.logger.debug(' '.join(cmd)) try: if tempdir.startswith(base): exclude = tempdir[len(base) + 1:] else: exclude = tempdir for f in find_files_of_type(os.path.realpath('.'), ('bib',), (exclude,)): self.logger.debug('Copying bib {!r} file to build dir' .format(f)) shutil.copyfile(f, os.path.join(tempdir, f)) subprocess.check_output(cmd, cwd=tempdir) pass except subprocess.CalledProcessError as e: self.logger.error(e.output) self.logger.error(e) else: self.logger.info('Bibliography updated')
def execute(self, args): base = os.path.realpath('.') files = utils.find_files_of_type( base, ('tex',), ('/build',), ('preamble.tex',), ) for f in files: if self.spellcheck_file(f) is False: self.logger.info('Process interrupted by user') break else: self.logger.info('Done')
def execute(self, args): files = args.files if not files: files = find_files_of_type(os.path.realpath('.'), 'tex') ignoredb = self.config.get('acronyms', 'ignoredb') ignored = set() if os.path.exists(ignoredb): with open(ignoredb) as fh: for line in fh: line = line.strip() if line: ignored.add(line) stdscr = curses.initscr() curses.savetty() curses.noecho() curses.cbreak() curses.curs_set(0) for f in files: with open(f) as fh: self.replacements = [] contents = fh.read() for m in re.finditer(self.acronym_regex, contents): ms, me = m.start(1), m.end(1) token = contents abbr = token[ms:me] if abbr.endswith('s'): abbr = abbr[:-1] if abbr in ignored: continue line = contents.count("\n", 0, ms) max_context = 20 prefix = postfix = '' # Isolate a single line cs = contents.rfind("\n", 0, ms) + 1 ce = contents.find("\n", me) if ms - cs > max_context: cs = ms - max_context cs = contents.rfind(" ", 0, cs) + 1 prefix = '...' if ce - me > max_context: ce = me + max_context ce = contents.find(" ", ce) postfix = '...' char = ms - cs ms -= cs me -= cs token = token[cs:ce] self.print_token_color(stdscr, f, token, line, char, ms, me, prefix, postfix) callbacks = { 'l': self.replace_lower, 'u': self.replace_upper, 'p': self.replace_lower_plural, 'j': self.replace_upper_plural, } try: c = stdscr.getch() try: callback = callbacks[chr(c)] except (KeyError, ValueError): if c == ord('f'): break else: continue else: callback(contents, m.start(1), m.end(1)) except KeyboardInterrupt: curses.resetty() curses.nocbreak() curses.echo() curses.endwin() return if self.replacements: for s, e, string in reversed(self.replacements): contents = contents[:s] + string + contents[e:] with open(f, 'w') as fh: fh.write(contents)