metag.leo 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!-- Created by Leo: http://leoeditor.com/leo_toc.html -->
  3. <leo_file xmlns:leo="http://leoeditor.com/namespaces/leo-python-editor/1.1" >
  4. <leo_header file_format="2"/>
  5. <globals/>
  6. <preferences/>
  7. <find_panel_settings/>
  8. <vnodes>
  9. <v t="caminhante.20210809161116.1"><vh>@settings</vh>
  10. <v t="caminhante.20200618180759.1"><vh>@command terminal-here @key=Alt-T</vh></v>
  11. <v t="caminhante.20200619162742.1"><vh>@command open-url-here @key=Ctrl-U</vh></v>
  12. <v t="caminhante.20200313155940.99"><vh>nodeActions</vh>
  13. <v t="caminhante.20200604232050.1"><vh>@cmd *</vh></v>
  14. <v t="caminhante.20200619161501.1"><vh>@download *</vh></v>
  15. <v t="caminhante.20200619155412.1"><vh>@duck *</vh></v>
  16. <v t="caminhante.20200927204806.1"><vh>@gcc|@gcc .* [X]</vh></v>
  17. <v t="caminhante.20200808174417.1"><vh>@js|@js .* [X]</vh></v>
  18. <v t="caminhante.20200912185313.1"><vh>@lua|@lua .* [X]</vh></v>
  19. <v t="caminhante.20210430163831.1"><vh>@mkdir *</vh></v>
  20. <v t="caminhante.20210430170244.1"><vh>@mv file://*</vh></v>
  21. <v t="caminhante.20200619213937.1"><vh>@node|@node .* [X]</vh></v>
  22. <v t="caminhante.20210608171556.1"><vh>@odt *</vh></v>
  23. <v t="caminhante.20210905232208.1"><vh>@rm *</vh></v>
  24. <v t="caminhante.20210430164404.1"><vh>@rmdir /*/</vh></v>
  25. <v t="caminhante.20200618203115.1"><vh>@run|@run .* [X]</vh></v>
  26. <v t="caminhante.20200619154823.1"><vh>@web *</vh></v>
  27. </v>
  28. </v>
  29. <v t="caminhante.20210809161032.2"><vh>MetaG</vh>
  30. <v t="caminhante.20210809161105.1"><vh>@path .</vh>
  31. <v t="caminhante.20210809161108.6"><vh>/.git/</vh></v>
  32. <v t="caminhante.20210809161108.4"><vh>@auto README.md</vh></v>
  33. <v t="caminhante.20210809161108.5"><vh>@edit LICENSE</vh></v>
  34. <v t="caminhante.20210807141115.1"><vh>@file parser.js</vh></v>
  35. <v t="caminhante.20210809161411.1"><vh>@file SourceCodeToTokenize.hpp</vh></v>
  36. <v t="caminhante.20210809161108.2"><vh>metag.leo</vh></v>
  37. </v>
  38. </v>
  39. </vnodes>
  40. <tnodes>
  41. <t tx="caminhante.20200313155940.99">@language python
  42. </t>
  43. <t tx="caminhante.20200604232050.1">import subprocess
  44. def execute (cmd):
  45. return subprocess.run(cmd,shell=True,universal_newlines=True,stderr=subprocess.STDOUT,stdout=subprocess.PIPE).stdout
  46. if c.isChanged(): c.save()
  47. path = c.getNodePath(c.p)
  48. g.os.chdir(path)
  49. command = ''.join(c.p.h.split('@cmd ')[1:])
  50. command = "cat &lt;&lt;'EOFEOFEOFEOFEOFEOF' | bash\n"+command+'\nEOFEOFEOFEOFEOFEOF'
  51. g.es(c.p.h)
  52. c.p.b += execute(command)
  53. c.save()
  54. </t>
  55. <t tx="caminhante.20200618180759.1">@language python
  56. import subprocess
  57. def execute (cmd):
  58. return subprocess.run(cmd,shell=True,universal_newlines=True,stderr=subprocess.STDOUT,stdout=subprocess.PIPE).stdout
  59. if c.isChanged(): c.save()
  60. path = c.getNodePath(c.p)
  61. execute('terminator --working-directory="'+path+'"')
  62. </t>
  63. <t tx="caminhante.20200618203115.1">@language python
  64. import subprocess
  65. def execute (cmd):
  66. return subprocess.run(cmd,shell=True,universal_newlines=True,stderr=subprocess.STDOUT,stdout=subprocess.PIPE).stdout
  67. path = c.getNodePath(c.p)
  68. g.os.chdir(path)
  69. w = c.frame.body.wrapper
  70. s1,s2 = w.getSelectionRange()
  71. if s1 == s2:
  72. code = c.p.b
  73. else:
  74. linebr = c.p.b.find('\n',s2)
  75. if linebr == -1: linebr = len(c.p.b)
  76. code = c.p.b[s1:s2]
  77. g.es(c.p.h)
  78. command = "cat &lt;&lt;'EOFEOFEOFEOFEOFEOF' | bash\n"+code+'\nEOFEOFEOFEOFEOFEOF'
  79. cpc = c.p.copy()
  80. novoNo = cpc.insertAsLastChild()
  81. novoNo.h = c.p.h
  82. novoNo.b = execute(command)
  83. c.redraw()
  84. c.save()
  85. w.setSelectionRange(s1,s2)
  86. </t>
  87. <t tx="caminhante.20200619154823.1">import subprocess
  88. def execute (cmd):
  89. return subprocess.run(cmd,shell=True,universal_newlines=True,stderr=subprocess.STDOUT,stdout=subprocess.PIPE).stdout
  90. if c.isChanged(): c.save()
  91. url = ''.join(c.p.h.split('@web ')[1:])
  92. command = 'lynx -image_links -dump "'+url+'"'
  93. g.es(c.p.h)
  94. c.p.b = execute(command)
  95. c.save()
  96. </t>
  97. <t tx="caminhante.20200619155412.1">import subprocess
  98. import urllib.parse
  99. def execute (cmd):
  100. return subprocess.run(cmd,shell=True,universal_newlines=True,stderr=subprocess.STDOUT,stdout=subprocess.PIPE).stdout
  101. if c.isChanged(): c.save()
  102. search = ''.join(c.p.h.split('@duck ')[1:])
  103. searchenc = urllib.parse.quote(search)
  104. command = 'lynx -dump "https://duckduckgo.com/html/?q='+searchenc+'&amp;t=seamonkey"'
  105. g.es(c.p.h)
  106. c.p.b = execute(command)
  107. c.save()
  108. </t>
  109. <t tx="caminhante.20200619161501.1">import subprocess
  110. def execute (cmd):
  111. return subprocess.run(cmd,shell=True,universal_newlines=True,stderr=subprocess.STDOUT,stdout=subprocess.PIPE).stdout
  112. if c.isChanged(): c.save()
  113. path = c.getNodePath(c.p)
  114. g.os.chdir(path)
  115. url = ''.join(c.p.h.split('@download ')[1:])
  116. command = 'wget --no-config --continue --no-verbose --adjust-extension --tries=3 --content-on-error "'+url+'"'
  117. g.es(c.p.h)
  118. c.p.b += execute(command)
  119. c.save()
  120. </t>
  121. <t tx="caminhante.20200619162742.1">@language python
  122. # if c.isChanged(): c.save()
  123. w = c.frame.body.wrapper
  124. b = c.p.b
  125. i,j = w.getSelectionRange()
  126. selecao = b[i:j]
  127. cpc = c.p.copy()
  128. novoNo = cpc.insertAsLastChild()
  129. c.setHeadString(novoNo, '@web '+selecao)
  130. c.selectPosition(novoNo)
  131. c.redraw()
  132. </t>
  133. <t tx="caminhante.20200619213937.1">import subprocess
  134. import re
  135. def execute (cmd):
  136. return subprocess.run(cmd,shell=True,universal_newlines=True,stderr=subprocess.STDOUT,stdout=subprocess.PIPE).stdout
  137. path = c.getNodePath(c.p)
  138. g.os.chdir(path)
  139. code = re.sub(r'^#|\s+#', '\n///', g.getScript(c,c.p))
  140. g.es(c.p.h)
  141. command = "cat &lt;&lt;'EOFEOFEOFEOFEOFEOF' | node\n"+code+'\nEOFEOFEOFEOFEOFEOF'
  142. c.p.b += '\n' + execute(command)
  143. </t>
  144. <t tx="caminhante.20200808174417.1">import subprocess
  145. import re
  146. def execute (cmd):
  147. return subprocess.run(cmd,shell=True,universal_newlines=True,stderr=subprocess.STDOUT,stdout=subprocess.PIPE).stdout
  148. path = c.getNodePath(c.p)
  149. g.os.chdir(path)
  150. code = re.sub(r'^#|\s+#', '\n///', g.getScript(c,c.p))
  151. g.es(c.p.h)
  152. command = "cat &lt;&lt;'EOFEOFEOFEOFEOFEOF' | js\n"+code+'\nEOFEOFEOFEOFEOFEOF'
  153. c.p.b += '\n' + execute(command)
  154. </t>
  155. <t tx="caminhante.20200912185313.1">import subprocess
  156. import re
  157. def execute (cmd):
  158. return subprocess.run(cmd,shell=True,universal_newlines=True,stderr=subprocess.STDOUT,stdout=subprocess.PIPE).stdout
  159. path = c.getNodePath(c.p)
  160. g.os.chdir(path)
  161. code = re.sub(r'^#|\s+#', '\n---', g.getScript(c,c.p))
  162. g.es(c.p.h)
  163. command = "cat &lt;&lt;'EOFEOFEOFEOFEOFEOF' | lua\n"+code+'\nEOFEOFEOFEOFEOFEOF'
  164. c.p.b += '\n' + execute(command)
  165. </t>
  166. <t tx="caminhante.20200927204806.1">import subprocess
  167. import re
  168. def execute (cmd):
  169. return subprocess.run(cmd,shell=True,universal_newlines=True,stderr=subprocess.STDOUT,stdout=subprocess.PIPE).stdout
  170. path = c.getNodePath(c.p)
  171. g.os.chdir(path)
  172. code = re.sub(r'^#@|\s+#@', '\n///', g.getScript(c,c.p))
  173. args = ''.join(c.p.h.split('@gcc ')[1:])
  174. g.es(c.p.h)
  175. command = "cat &lt;&lt;'EOFEOFEOFEOFEOFEOF' | gcc -Wall -Werror -std=gnu11 -x c - -o t &amp;&amp; ./t "+args+"\n"+code+'\nEOFEOFEOFEOFEOFEOF'
  176. c.p.b += '\n' + execute(command)
  177. </t>
  178. <t tx="caminhante.20210430163831.1">import subprocess
  179. def execute (cmd):
  180. return subprocess.run(cmd,shell=True,universal_newlines=True,stderr=subprocess.STDOUT,stdout=subprocess.PIPE).stdout
  181. path = c.getNodePath(c.p)
  182. g.os.chdir(path)
  183. path = ''.join(c.p.h.split('@mkdir ')[1:])
  184. cmd = 'mkdir -p "' + path + '"'
  185. g.es(c.p.h)
  186. execute(cmd)
  187. c.p.h = '/'+path+'/'
  188. c.p.b = '@path ' + path</t>
  189. <t tx="caminhante.20210430164404.1">import subprocess
  190. import shutil
  191. def execute (cmd):
  192. return subprocess.run(cmd,shell=True,universal_newlines=True,stderr=subprocess.STDOUT,stdout=subprocess.PIPE).stdout
  193. ps = c.p.parents()
  194. for par in ps:
  195. break
  196. path = c.getNodePath(par)
  197. g.os.chdir(path)
  198. path = ''.join(c.p.h.split('@rmdir /')[1:]).split('/')[0]
  199. shutil.rmtree(path)</t>
  200. <t tx="caminhante.20210430170244.1">import subprocess
  201. def execute (cmd):
  202. return subprocess.run(cmd,shell=True,universal_newlines=True,stderr=subprocess.STDOUT,stdout=subprocess.PIPE).stdout
  203. path = c.getNodePath(c.p)
  204. g.os.chdir(path)
  205. path = ''.join(c.p.h.split('@mv file://')[1:])
  206. cmd = 'mv -v "' + path + '" ./'
  207. g.es(c.p.h)
  208. g.es(execute(cmd))</t>
  209. <t tx="caminhante.20210608171556.1">import subprocess
  210. import re
  211. def execute (cmd):
  212. return subprocess.run(cmd,shell=True,universal_newlines=True,stderr=subprocess.STDOUT,stdout=subprocess.PIPE).stdout
  213. def writeFile (_file,_content):
  214. f = open(_file, "w")
  215. f.write(_content)
  216. f.close()
  217. path = c.getNodePath(c.p)
  218. g.os.chdir(path)
  219. docName = ''.join(c.p.h.split('@odt ')[1:])
  220. docPath = './.odt/'+docName+'/'
  221. manifest_xml = """&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  222. &lt;manifest:manifest
  223. xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0" manifest:version="1.2"
  224. xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"&gt;
  225. &lt;manifest:file-entry manifest:full-path="/" manifest:version="1.2" manifest:media-type="application/vnd.oasis.opendocument.text"/&gt;
  226. &lt;manifest:file-entry manifest:full-path="content.xml" manifest:media-type="text/xml"/&gt;
  227. &lt;manifest:file-entry manifest:full-path="meta.xml" manifest:media-type="text/xml"/&gt;
  228. &lt;manifest:file-entry manifest:full-path="manifest.rdf" manifest:media-type="application/rdf+xml"/&gt;
  229. &lt;manifest:file-entry manifest:full-path="styles.xml" manifest:media-type="text/xml"/&gt;
  230. &lt;/manifest:manifest&gt;
  231. """
  232. mimetype = "application/vnd.oasis.opendocument.text"
  233. content_xml = (
  234. """&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  235. &lt;office:document-content
  236. xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
  237. xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
  238. xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
  239. xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
  240. xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
  241. xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
  242. xmlns:xlink="http://www.w3.org/1999/xlink"
  243. xmlns:dc="http://purl.org/dc/elements/1.1/"
  244. xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
  245. xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
  246. xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
  247. xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
  248. xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
  249. xmlns:math="http://www.w3.org/1998/Math/MathML"
  250. xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
  251. xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
  252. xmlns:ooo="http://openoffice.org/2004/office"
  253. xmlns:ooow="http://openoffice.org/2004/writer"
  254. xmlns:oooc="http://openoffice.org/2004/calc"
  255. xmlns:dom="http://www.w3.org/2001/xml-events"
  256. xmlns:xforms="http://www.w3.org/2002/xforms"
  257. xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  258. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  259. xmlns:rpt="http://openoffice.org/2005/report"
  260. xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2"
  261. xmlns:xhtml="http://www.w3.org/1999/xhtml"
  262. xmlns:grddl="http://www.w3.org/2003/g/data-view#"
  263. xmlns:officeooo="http://openoffice.org/2009/office"
  264. xmlns:tableooo="http://openoffice.org/2009/table"
  265. xmlns:drawooo="http://openoffice.org/2010/draw"
  266. xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0"
  267. xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"
  268. xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0"
  269. xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0"
  270. xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2"&gt;
  271. &lt;office:body&gt;
  272. &lt;office:text&gt;
  273. """,
  274. re.sub(r'^#@[^\n]+|\s+#@[^\n]+', '', g.getScript(c,c.p)),
  275. """
  276. &lt;/office:text&gt;
  277. &lt;/office:body&gt;
  278. &lt;/office:document-content&gt;
  279. """
  280. )
  281. manifest_rdf = """&lt;?xml version="1.0" encoding="utf-8"?&gt;
  282. &lt;rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"&gt;
  283. &lt;rdf:Description rdf:about="styles.xml"&gt;
  284. &lt;rdf:type rdf:resource="http://docs.oasis-open.org/ns/office/1.2/meta/odf#StylesFile"/&gt;
  285. &lt;/rdf:Description&gt;
  286. &lt;rdf:Description rdf:about=""&gt;
  287. &lt;ns0:hasPart xmlns:ns0="http://docs.oasis-open.org/ns/office/1.2/meta/pkg#" rdf:resource="styles.xml"/&gt;
  288. &lt;/rdf:Description&gt;
  289. &lt;rdf:Description rdf:about="content.xml"&gt;
  290. &lt;rdf:type rdf:resource="http://docs.oasis-open.org/ns/office/1.2/meta/odf#ContentFile"/&gt;
  291. &lt;/rdf:Description&gt;
  292. &lt;rdf:Description rdf:about=""&gt;
  293. &lt;ns0:hasPart xmlns:ns0="http://docs.oasis-open.org/ns/office/1.2/meta/pkg#" rdf:resource="content.xml"/&gt;
  294. &lt;/rdf:Description&gt;
  295. &lt;rdf:Description rdf:about=""&gt;
  296. &lt;rdf:type rdf:resource="http://docs.oasis-open.org/ns/office/1.2/meta/pkg#Document"/&gt;
  297. &lt;/rdf:Description&gt;
  298. &lt;/rdf:RDF&gt;
  299. """
  300. meta_xml = f"""&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  301. &lt;office:document-meta
  302. xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
  303. xmlns:xlink="http://www.w3.org/1999/xlink"
  304. xmlns:dc="http://purl.org/dc/elements/1.1/"
  305. xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
  306. xmlns:ooo="http://openoffice.org/2004/office"
  307. xmlns:grddl="http://www.w3.org/2003/g/data-view#" office:version="1.2"&gt;
  308. &lt;office:meta&gt;
  309. &lt;meta:generator&gt;LeoEditor/6.4$Linux_x64&lt;/meta:generator&gt;
  310. &lt;dc:title&gt;{docName}&lt;/dc:title&gt;
  311. &lt;/office:meta&gt;
  312. &lt;/office:document-meta&gt;
  313. """
  314. generate_odt = f"""cp -f styles.xml '{docPath}/styles.xml'; cd '{docPath}'; zip -q9ru doc.odt META-INF manifest.rdf meta.xml content.xml styles.xml mimetype"""
  315. generate_pdf = f"""libreoffice --headless --convert-to pdf '{docPath}/doc.odt' &amp;&amp; mv 'doc.pdf' '{docName}.pdf'"""
  316. execute('mkdir -p "'+docPath+'/META-INF/"')
  317. writeFile(docPath+'/META-INF/manifest.xml', manifest_xml)
  318. writeFile(docPath+'/mimetype', mimetype)
  319. writeFile(docPath+'/content.xml',''.join(content_xml))
  320. writeFile(docPath+'/manifest.rdf', manifest_rdf)
  321. writeFile(docPath+'/meta.xml', meta_xml)
  322. # writeFile(docPath+'/styles.xml', styles_xml)
  323. execute(generate_odt)
  324. g.es(execute(generate_pdf))
  325. </t>
  326. <t tx="caminhante.20210809161032.2"></t>
  327. <t tx="caminhante.20210809161105.1">@tabwidth -2</t>
  328. <t tx="caminhante.20210809161108.2"></t>
  329. <t tx="caminhante.20210809161108.6">@path .git</t>
  330. <t tx="caminhante.20210809161116.1"></t>
  331. <t tx="caminhante.20210905232208.1">import subprocess
  332. def execute (cmd):
  333. return subprocess.run(cmd,shell=True,universal_newlines=True,stderr=subprocess.STDOUT,stdout=subprocess.PIPE).stdout
  334. path = c.getNodePath(c.p)
  335. g.os.chdir(path)
  336. filename = ''.join(c.p.h.split('@rm ')[1:])
  337. cmd = 'rm -vf "' + filename + '"'
  338. g.es(c.p.h)
  339. g.es(execute(cmd))</t>
  340. </tnodes>
  341. </leo_file>