Esempio n. 1
0
 def inner(*fargs, **fkwargs):
     inpath = fkwargs.get('inpath') or (fargs[dkwargs['inpath']] if (
         'inpath' in dkwargs.keys() and dkwargs['inpath'] < len(fargs))
                                        else None)
     outpath = fkwargs.get('outpath') or (fargs[dkwargs['outpath']] if (
         'outpath' in dkwargs.keys()
         and dkwargs['outpath'] < len(fargs)) else None)
     inpath, outpath, to_delete = handler(inpath, outpath)
     fargs = list(fargs)
     # The following tries to intelligently handle function arguments so
     # that this decorator can be generalized. Need to handle conditions
     # where arguments may positional or keyword.
     for var, key in ((inpath, "inpath"), (outpath, "outpath")):
         if key in dkwargs.keys():
             if not var:
                 continue
             if key in fkwargs.keys():
                 fkwargs[key] = var
             elif dkwargs[key] < len(fargs):
                 fargs[dkwargs[key]] = var
             else:
                 fkwargs[key] = var
     if to_delete:
         if op.isdir(inpath):
             # If using a temporary directory to hold the template (e.g.
             # downloaded from Github), don't include that directory
             # name in the output paths.
             fkwargs['pathsubs'] = [[op.basename(to_delete), "."]]
     retval = func(*fargs, **fkwargs)
     if to_delete:
         fsys.delete(to_delete)
     return retval
Esempio n. 2
0
 def _talk():
     """Pronounces the given text in the given language."""
     with TALK_LOCK:
         tpath = op.join(tempfile.gettempdir(),
                         f"__temp-talk-{randomize(6)}.mp3")
         tts(text=text, lang=lang, slow=slow).save(tpath)
         playsound(tpath)
         delete(tpath)
Esempio n. 3
0
def run(inpath, tmpldict, outpath=None, execute=None, runargs=None):
    """Handles logic for `run` command."""
    if not outpath:
        outpath = op.join(os.getcwd(), "__temp-poppage-" + _getrands(6))
    make(inpath, tmpldict, outpath=outpath)
    qprompt.hrule()
    if not execute:
        execute = outpath
    tmpldict.update({'outpath': outpath})
    tmpldict.update({'runargs': " ".join(runargs or [])})
    execute = render_str(execute, tmpldict)
    for line in execute.splitlines():
        sh.call(line.strip())
    fsys.delete(outpath)
Esempio n. 4
0
 def test_makedirs_2(test):
     """Make nested dirs."""
     path = op.join(DIR[0], DIR[1])
     test.assertIsNone(isempty(path))
     test.assertFalse(op.exists(path))
     test.assertTrue(makedirs(path))
     test.assertTrue(op.exists(path))
     test.assertTrue(op.isdir(path))
     test.assertFalse(isempty(DIR[0]))
     test.assertTrue(isempty(path))
     test.assertTrue(delete(path))
     test.assertIsNone(isempty(path))
     test.assertFalse(op.exists(path))
     test.assertTrue(op.isdir(DIR[0]))
     test.assertTrue(delete(DIR[0]))
Esempio n. 5
0
def readme_excerpt():
    tempxml = "temp.xml"
    shell.call(f"asciidoctor -b docbook -o {tempxml} README.adoc")
    e = ElementTree.parse(tempxml).getroot()
    fsys.delete(tempxml)
    ns = {'db': 'http://docbook.org/ns/docbook', 'xml': 'http://www.w3.org/XML/1998/namespace'}
    rst = ""
    for sect in ["_introduction", "_status", "_requirements", "_installation"]:
        xml = ElementTree.tostring(e.find(f".//db:section[@xml:id='{sect}']", ns)).decode("utf-8")
        fsys.File(tempxml).write(xml)
        rst += shell.strout(f"pandoc -r docbook -w rst --base-header-level=2 {tempxml}")
        rst += "\n\n"
    fsys.File(r"doc\source\readme_excerpt.rst").write(rst)
    fsys.delete(tempxml)
    print("Readme excerpt generated.")
Esempio n. 6
0
 def test_makedirs_1(test):
     """Make a single dir."""
     path = DIR[0]
     test.assertFalse(op.exists(path))
     test.assertTrue(makedirs(path))
     test.assertTrue(op.isdir(path))
     test.assertTrue(isempty(path))
     test.assertTrue(delete(path))
     test.assertFalse(op.exists(path))
Esempio n. 7
0
def readme_excerpt():
    tempxml = "temp.xml"
    shell.call(f"asciidoctor -b docbook -o {tempxml} README.adoc")
    e = ElementTree.parse(tempxml).getroot()
    fsys.delete(tempxml)
    ns = {
        'db': 'http://docbook.org/ns/docbook',
        'xml': 'http://www.w3.org/XML/1998/namespace'
    }
    rst = ""
    for sect in ["_introduction", "_status", "_requirements", "_installation"]:
        xml = ElementTree.tostring(
            e.find(f".//db:section[@xml:id='{sect}']", ns)).decode("utf-8")
        fsys.File(tempxml).write(xml)
        rst += shell.strout(
            f"pandoc -r docbook -w rst --base-header-level=2 {tempxml}")
        rst += "\n\n"
    fsys.File(r"doc\source\readme_excerpt.rst").write(rst)
    fsys.delete(tempxml)
    print("Readme excerpt generated.")
Esempio n. 8
0
 def test_isempty_1(test):
     path = FNAME[0]
     test.assertIsNone(isempty(path))
     with open(path, "w") as fo:
         pass
     test.assertTrue(isempty(path))
     with open(path, "w") as fo:
         fo.write(TEXT[0])
     test.assertFalse(isempty(path))
     test.assertTrue(delete(path))
     test.assertIsNone(isempty(path))
Esempio n. 9
0
 def tearDown(test):
     super(BaseTest, test).tearDown()
     while op.exists("./__output__"):
         # NOTE: This is a hacky fix to avoid Dropbox related error.
         try: delete("./__output__")
         except: pass
Esempio n. 10
0
sys.dont_write_bytecode = True

from _Check_Versions import VERCHK
from _Install_Package import generate_readme, cleanup_readme

##==============================================================#
## SECTION: Main Body                                           #
##==============================================================#

if __name__ == '__main__':
    pause = True
    if len(sys.argv) > 1 and "nopause" == sys.argv[1]:
        pause = False
    ver = VERCHK.run()
    if not ver:
        qprompt.alert("Issue with version info!")
        sys.exit(1)
    if 0 != qprompt.status("Running tests...", sh.silent,
                           [r"python ..\tests\_Run_Tests.py nopause"]):
        qprompt.alert("Issue running tests!")
        sys.exit(1)
    if qprompt.ask_yesno("Upload version `%s`?" % (ver)):
        generate_readme()
        fs.copy(r"..\LICENSE", "LICENSE")
        sh.call("python setup.py sdist upload")
        fs.delete("LICENSE")
        cleanup_readme()
    if pause:
        qprompt.pause()
    sys.exit(0)
Esempio n. 11
0
 def tearDown(test):
     super(BaseTest, test).tearDown()
     for i in FNAME + DIR:
         delete(i)
Esempio n. 12
0
from auxly.filesys import delete

delete("__pycache__")
delete("__output__")
delete("poppage.egg-info")
delete("dist")
delete("build")
delete(".", "\.log$")
delete(".", "\.pyc$")