def compile(self): """ prototype:: action = this method launches the compilation defined via ``self.cmd`` in verbose mode or not the number of times that is indicated in ``self.repeat``. """ imax = self.repeat + 1 if imax == 1: start_compile = '# -- Start of the compilation -- #\n' end_compile = '\n# -- End of the compilation -- #' else: start_compile = '# -- Start of compilation Nb.{0} -- #\n' end_compile = '\n# -- End of compilation Nb.{0} -- #' for i in range(1, imax): if self.showoutput: if i != 1: print("") print(start_compile.format(i)) with cd(self.ppath.parent): runthis(cmd='{0} "{1}"'.format(self.cmd, self.ppath), showoutput=self.showoutput) if self.showoutput: print(end_compile.format(i)) self.cmd = None
def refresh(aboutlatex={}): """ prototype:: see = about arg = dict: aboutlatex = {} ; one dictionary similar to the one sent by the function ``about`` action = the list of packages directly known by the ¨latex distribution is refreshed warning:: You have to be in super user mode if you want this function to work. """ # We have to build infos about the ¨latex distribution. if aboutlatex == {}: aboutlatex = about() # We must be a super user ! _must_be_su(aboutlatex) # TeX Live if aboutlatex['latexname'] == TEXLIVE: runthis('mktexlsr') # MiKTex elif aboutlatex['latexname'] == MIKTEX: runthis('initexmf --update-fndb --verbose') # Unkonwn !!! else: raise LatexError('refreshing the list of LaTeX packages is not ' 'supported with your LaTeX distribution.')
def _localdir_texlive(osname=""): """ prototype:: arg = str: osname = "" in [OS_WIN , OS_LINUX , OS_MAC]; the name of the ¨os (logical, isn't it ?), that can be found automatically if you use the default value ``osname = ""`` return = PPath ; the path of the ¨texlive directory where we have to put special ¨latex packages. """ if osname == "": osname = system() if osname == OS_WIN: localdir = runthis("kpsexpand '$TEXMFLOCAL'") localdir = PPath(localdir.strip()).normpath elif osname in [OS_LINUX, OS_MAC]: localdir = runthis('kpsewhich --var-value=TEXMFLOCAL') localdir = PPath(localdir.strip()).normpath else: raise OSError("unsupported OS << {0} >>.".format(osname)) return localdir
def cookifyles(cookiecutter_temp, peuf_dir, all_peuf_choosen): title("LET'S WORK...") # Let's add the new json files. allprojects = projects_to_do(cookiecutter_temp, peuf_dir, all_peuf_choosen) for project in allprojects: SUB_STEPS = Step(start=1, textit=lambda n, t: f" {chr(96 + n)}/ {t}") projectreldir = f"{project['relpath']}" \ + f"/{project['json']['project_name']}" MAIN_STEPS(f"Building {projectreldir}") # Build the json file. SUB_STEPS("Updating the json file.") jsonpath = cookiecutter_temp \ / project['relpath'] \ / 'cookiecutter.json' with jsonpath.open(encoding='utf-8', mode='w') as f: f.write(json_dumps(project['json'])) # Call of cookiecutter. SUB_STEPS("Trying to launch cookiecutter.") cmddir = cookiecutter_temp / project['relpath'] cmddir = cmddir.parent with cd(cmddir): try: runthis(f"cookiecutter --no-input {project['kind']}", showoutput=True) except Exception as e: print('\nCookiecutter fails. See above why.') exit(1) SUB_STEPS("cookiecutter has done its local job.") # Moving, or not, the folder. SUB_STEPS("Do not forget to move the new folder.") # Open the cookie templates folder. print() title(f'Opening folder of the cookie templates') runthis(f'open "{cookiecutter_temp}"') print("Here are all the starting project build.") SUB_STEPS = Step(start=1, textit=lambda n, t: f" {n}: {t}") for project in allprojects: SUB_STEPS(f"{project['lang']}/{project['json']['project_name']}") print()
def make_miktex_localdir(aboutlatex): """ prototype:: see = about arg = dict: aboutlatex ; one dictionary similar to the one sent by the function ``about`` action = this function creates one local directory and add it to the list of directories automatically analysed by MiKTeX when it looks for packages. info:: Even it is a really bad idea, you can change the path ``MIKETEX_LOCALDIR`` to put your homemade packages where you want. """ if aboutlatex['osname'] != OS_WIN \ or aboutlatex['latexname'] != MIKTEX: raise OSError('this function can only be used with the OS "window" ' 'and the LaTeX distribution "miktex".') # Creation of the directory MIKETEX_LOCALDIR.create("dir") # Adding the directory to the ones analysed by MiKTex. runthis(cmd='initexmf --admin --user-roots={0} --verbose'.format( MIKETEX_LOCALDIR)) runthis(cmd='initexmf --update-fndb --verbose') print('', 'The following local directory for MiKTeX has been created.', '\t<< {0} >>'.format(MIKETEX_LOCALDIR), sep="\n")
option2suffix = { lname[2:]: f"[{suffix}]" for suffix, (_, lname) in SUFFIX_CFG.items() } allpaths = [p for pattern in PPATH_PATTERNS for p in THIS_DIR.walk(pattern)] allpaths.sort() for onepath in allpaths: filename = (onepath - THIS_DIR).stem nolaunch = False for option, suffix in option2suffix.items(): if getattr(ARGS, option) \ and filename.endswith(suffix): print(f"- No suffix {suffix} : << {filename} >> ignored.") nolaunch = True if nolaunch: continue print(f'+ Launching "{filename}"') cmd = EXT_2_CMDS[onepath.ext] runthis(cmd=f'{cmd} "{onepath}"', showoutput=True)
def about(): """ prototype:: return = dict ; this function gives informations used by the function ``install`. The dictionary returned looks like the following one. In this example, we are on a ¨mac computer where ¨texlive has been installed by ¨mactex. python:: { 'osname' : 'mac', 'latexname' : 'texlive', 'latexfound': True, 'localdir' : PPath('/usr/local/texlive/texmf-local') } The key ``'localdir'`` contains the path to use to install special packages. """ osname = system() latexfound = False latexname = '' localdir = None # Windows if osname == OS_WIN: winpath = pathenv() # Is MiKTeX installed ? if '\\miktex\\' in winpath: latexfound = True latexname = MIKTEX if MIKETEX_LOCALDIR.is_dir(): localdir = MIKETEX_LOCALDIR # Is TeX Live installed ? elif '\\texlive\\' in winpath: latexfound = True latexname = TEXLIVE localdir = _localdir_texlive(osname) # Linux and Mac elif osname in [OS_LINUX, OS_MAC]: # Is LaTeX installed ? try: if runthis('which pdftex'): latexfound = True latexname = TEXLIVE localdir = _localdir_texlive(osname) except CalledProcessError: ... # Unknown method... else: raise OSError("unsupported OS << {0} >>.".format(osname)) # The job has been done... return { 'osname': osname, 'latexname': latexname, 'latexfound': latexfound, 'localdir': localdir }
sep = "\n" ) # ----------------------------- # # -- LAUNCHING ALL THE TESTS -- # # ----------------------------- # with cd(THIS_DIR): printtile("Launching all the tests...") try: tests_passed = True runthis( cmd = "py.test -v", showoutput = True ) except Exception as e: tests_passed = False # ---------------------- # # -- UPDATING THE LOG -- # # ---------------------- # printtile("Updating the log file...") if tests_passed: message = ["OK"]
#!/usr/bin/env python3 # --------------------- # # -- SEVERAL IMPORTS -- # # --------------------- # from mistool.os_use import PPath, runthis # --------------- # # -- CONSTANTS -- # # --------------- # THIS_FILE = PPath(__file__) THIS_DIR = THIS_FILE.parent # -------------------------------------- # # -- LAUNCHING ALL THE BUILDING TOOLS -- # # -------------------------------------- # for onepath in THIS_DIR.walk("file::**build_*.py"): print('+ Launching "{0}"'.format(onepath.name)) runthis( cmd = 'python "{0}"'.format(onepath), showoutput = True )
sep = "\n" ) # ----------------------------- # # -- LAUNCHING ALL THE TESTS -- # # ----------------------------- # with cd(THIS_DIR): printtile("Launching all the tests...") try: tests_passed = True runthis( cmd = "py.test -v --resultlog=x-pytest_log-x.txt", showoutput = True ) except Exception as e: tests_passed = False # ---------------------------------------- # # -- LAUNCHING ALL THE "HUMAN CHECKING" -- # # ---------------------------------------- # printtile("Launching the scripts producing infos to be checked by a human...") for onepath in THIS_DIR.walk("file::human_checking/**.py"): print(' + "{0}" executed.'.format(onepath.name))
#!/usr/bin/env python3 # --------------------- # # -- SEVERAL IMPORTS -- # # --------------------- # from mistool.os_use import PPath, runthis # --------------- # # -- CONSTANTS -- # # --------------- # THIS_FILE = PPath(__file__) THIS_DIR = THIS_FILE.parent # -------------------------------------- # # -- LAUNCHING ALL THE BUILDING TOOLS -- # # -------------------------------------- # for onepath in THIS_DIR.walk("file::**build_*.py"): print('+ Launching "{0}"'.format(onepath.name)) runthis(cmd='python "{0}"'.format(onepath), showoutput=True)
def printtile(text): print("", withframe(text), "", sep="\n") # ----------------------------- # # -- LAUNCHING ALL THE TESTS -- # # ----------------------------- # with cd(THIS_DIR): printtile("Launching all the tests...") try: tests_passed = True runthis(cmd="py.test -v --resultlog=x-pytest_log-x.txt", showoutput=True) except Exception as e: tests_passed = False # ---------------------- # # -- UPDATING THE LOG -- # # ---------------------- # printtile("Updating the log file...") if tests_passed: message = ["OK"] else:
def extractchanges(partname, versions): global TOC content = [ "", "% -------------- %", f"% -- {partname} -- %", "% -------------- %", ] notfirstinfo = False with cd(PARTS_DIR / partname): print(f"{DECO*2}- Working on << {partname} >>.") try: runthis("git checkout master") except Exception as e: print(e) exit(1) for chgedate, versnb in versions: texpath = chgedate.replace("-", "/", 1) texpath = PARTS_DIR / f"{partname}/factory/99-major-change-log/changes/{texpath}.tex" if not texpath.is_file(): print( f"{DECO*2}- [{partname}] Following LaTeX file is missing." ) print( f"{DECO*2} << {texpath} >>." ) exit(1) with texpath.open( mode = "r", encoding = "utf-8" ) as file: chgecontent = file.read().strip() chgecontent = chgecontent.split("\n") chgecontent = chgecontent[1:] chgecontent = "\n".join(chgecontent) if not chgecontent: chgecontent += """ \\begin{itemize}[itemsep=.5em] \\item Simple migration depuis l'ancien code de \\verb+lymath+. \\end{itemize} """.strip() chgecontent = chgecontent.strip() chgecontent = chgecontent.replace('\\separation', '') if notfirstinfo: extraline = "" notfirstinfo = False else: extraline ="\n" chgecontent = f"""{extraline} \\begin{{center}} \\textbf{{\\textsc{{{TOC[partname]} [{versnb}]}}}} \\end{{center}} {chgecontent} """.rstrip() content.append(chgecontent) try: runthis("git checkout dev") except Exception as e: print(e) exit(1) content = "\n".join(content) return content