def main(): fpn1 = sys.argv[1] bridge = leoBridge.controller(gui='nullGui', verbose=False, loadPlugins=False, readSettings=False) cmdr1 = bridge.openLeoFile(fpn1) cmdr1.save() cmdr1.close()
def main (): trace = False readSettings = True tag = 'leoDynamicTests.leo' if trace: t1 = time.time() # Setting verbose=True prints messages that would be sent to the log pane. path,gui,readSettings,silent = scanOptions() # print('(leoDynamicTest.py:main)','readSettings',readSettings) # print('(leoDynamicTest.py:main)','silent',silent) # Not loading plugins and not reading settings speeds things up considerably. bridge = leoBridge.controller(gui=gui, loadPlugins=False, # Must be False: plugins will fail when run externally. readSettings=True, # True: adds about 0.3 seconds. Very useful for some tests. silent=True, verbose=False) if trace: t2 = time.time() print('%s open bridge: %0.2fsec' % (tag,t2-t1)) if bridge.isOpen(): g = bridge.globals() g.app.silentMode = silent g.app.isExternalUnitTest = True path = g.os_path_finalize_join(g.app.loadDir,'..','test',path) c = bridge.openLeoFile(path) if trace: t3 = time.time() print('%s open file: %0.2fsec' % (tag,t3-t2)) runUnitTests(c,g)
def main(): """ Command Line Utility Entry Point Arguments: sys.argv: Command line arguments Returns: None """ args = cmdLineHandler() leoG.IdleTime = idle_time.IdleTime bridge = leoBridge.controller(gui='nullGui', silent=True, verbose=False, loadPlugins=True, readSettings=True) cmdrT = bridge.openLeoFile(args.fpnTests) if os.path.exists(args.fpnResults): os.remove(args.fpnResults) fdR = codecs.open(args.fpnResults, 'w', encoding='utf-8') testCmdr = lib_test.TestCmdr(cmdrT, fdR) genFindTests = lib_test.findTests(cmdrT) itPoll = leoG.IdleTime((lambda itRunTests: lib_test.runTests( itRunTests, cmdrT, fdR, testCmdr, genFindTests)), delay=10) itPoll.start() idle_time.IdleTime.idle()
def bridge(self): """Return an instance of Leo's bridge.""" return leoBridge.controller( gui='nullGui', loadPlugins=False, readSettings=False, silent=True, verbose=False, )
def __init__(self): self.gnx_to_vnode = [ ] # utility array - see leoflexx.py in leoPluginsRef.leo self.bridge = leoBridge.controller( gui='nullGui', loadPlugins=False, # True: attempt to load plugins. readSettings=True, # True: read standard settings files. silent=True, # True: don't print signon messages. verbose=False) # True: print informational messages. self.currentActionId = 1 # Id of action being processed, STARTS AT 1 = Initial 'ready'
def open_bridge(): '''Open Leo bridge and return g.''' print('opening leoBridge...') controller = leoBridge.controller( gui='nullGui', loadPlugins=False, # True: attempt to load plugins. readSettings=False, # True: read standard settings files. silent=True, # True: don't print signon messages. verbose=False, # True: print informational messages. ) g = controller.globals() return controller, g
def main(): if os.path.exists(TestDir): shutil.rmtree(TestDir) os.makedirs(TestDir) bridge = leoBridge.controller(gui='nullGui', verbose=False, loadPlugins=False, readSettings=False) fpn1 = os.path.join(TestDir, 'test{0}.leo'.format(1)) cmdrx = bridge.openLeoFile(fpn1) cmdrx.save() cmdrx.close() if True: returnCode = subprocess.call(['python', 'lfloS.py', fpn1]) if returnCode: print("Subprocess.call() returned {0}".format(returnCode))
def main(gui='nullGui'): trace = False tag = 'leoTestBridge' # Setting verbose=True prints messages that would be sent to the log pane. bridge = leoBridge.controller(gui=gui, verbose=False) if bridge.isOpen(): g = bridge.globals() path = g.os_path_finalize_join(g.app.loadDir, '..', 'test', 'unitTest.leo') c = bridge.openLeoFile(path) if trace: g.es('%s %s' % (tag, c.shortFileName())) runUnitTests(c, g) g.pr(tag, 'done')
def main (gui='nullGui'): trace = False tag = 'leoTestBridge' # Setting verbose=True prints messages that would be sent to the log pane. bridge = leoBridge.controller(gui=gui,verbose=False) if bridge.isOpen(): g = bridge.globals() path = g.os_path_finalize_join( g.app.loadDir,'..','test','unitTest.leo') c = bridge.openLeoFile(path) if trace: g.es('%s %s' % (tag,c.shortFileName())) runUnitTests(c,g) g.pr(tag,'done')
def main(gui="nullGui"): trace = False tag = "leoTestBridge" # Setting verbose=True prints messages that would be sent to the log pane. bridge = leoBridge.controller(gui=gui, verbose=False) if bridge.isOpen(): g = bridge.globals() path = g.os_path_finalize_join(g.app.loadDir, "..", "test", "unitTest.leo") c = bridge.openLeoFile(path) if trace: g.es("%s %s" % (tag, c.shortFileName())) runUnitTests(c, g) g.pr(tag, "done")
def test_bridge(self): # The most basic test. controller = leoBridge.controller( gui='nullGui', # 'nullGui', 'qt' loadPlugins=False, # True: attempt to load plugins., readSettings=False, # True: read standard settings files. silent=True, # True: don't print signon messages. verbose=True, ) g = controller.globals() self.assertTrue(g) unittest_dir = os.path.abspath(os.path.dirname(__file__)) self.assertTrue(os.path.exists(unittest_dir)) test_dot_leo = g.os_path_finalize_join(unittest_dir, '..', '..', 'test', 'test.leo') self.assertTrue(os.path.exists(test_dot_leo), msg=test_dot_leo) c = controller.openLeoFile(test_dot_leo) self.assertTrue(c)
def main(): '''The main line of leoBridgeTest.py.''' tag = 'leoTestBridge' options = scanOptions() bridge = leoBridge.controller( gui=options.gui, loadPlugins = options.load_plugins, readSettings = options.read_settings, # adds 0.3 sec. Useful! silent = options.silent, tracePlugins = options.trace_plugins, verbose = options.verbose, # True: prints log messages. ) if bridge.isOpen(): g = bridge.globals() path = g.os_path_finalize_join(g.app.loadDir, '..', 'test') #relative_path) c = bridge.openLeoFile(path) if c: runUnitTests(c, g) g.pr(tag, 'done')
def main(): """The main line of leoBridgeTest.py.""" tag = 'leoTestBridge' options = scanOptions() bridge = leoBridge.controller( gui=options.gui, loadPlugins = options.load_plugins, readSettings = options.read_settings, # adds 0.3 sec. Useful! silent = options.silent, tracePlugins = options.trace_plugins, verbose = options.verbose, # True: prints log messages. ) if bridge.isOpen(): g = bridge.globals() path = g.os_path_finalize_join(g.app.loadDir, '..', 'test') #relative_path) c = bridge.openLeoFile(path) if c: runUnitTests(c, g) g.pr(tag, 'done')
def main(): if os.path.exists(TestDir): shutil.rmtree(TestDir) os.makedirs(TestDir) cnt = 0 infoList = list() bridge = leoBridge.controller(gui='nullGui', verbose=False, loadPlugins=False, readSettings=False) leoG = bridge.globals() infoList.append('After bridge create: {0}'.format(leoG.app.nodeIndices.lastIndex)) fpn1 = os.path.join(TestDir, 'test{0}.leo'.format(1)) cmdrx = bridge.openLeoFile(fpn1) infoList.append('After {fpn}: {idx}'.format(fpn=fpn1, idx=leoG.app.nodeIndices.lastIndex)) rp = cmdrx.rootPosition() rp.h = '1 - 1' for idx in xrange(2, 7): posx = rp.insertAfter() posx.h = '{cnt} - {idx}'.format(cnt=1, idx=idx) infoList.append('After 5 vnode creates: {0}'.format(leoG.app.nodeIndices.lastIndex)) again = True while again: again = False for posx in cmdrx.all_positions_iter(): if posx.h not in ['1 - 3', '1 - 6']: posx.doDelete() again = True break infoList.append('After sorting and 3 vnode deletes: {0}'.format(leoG.app.nodeIndices.lastIndex)) cmdrx.save() cmdrx.close() if True: returnCode = subprocess.call(['python', 'hrngpS2.py', fpn1]) infoList.append('subprocess return code = {0}'.format(returnCode)) fpnError = os.path.join(TestDir, 'MasterLog.txt') fdError = open(fpnError, 'w') fdError.write('\n'.join(infoList) + '\n') fdError.close()
def main(): """The main line of leoBridgeTest.py.""" tag = "leoTestBridge" options = scanOptions() bridge = leoBridge.controller( gui=options.gui, loadPlugins=options.load_plugins, readSettings=options.read_settings, # adds 0.3 sec. Useful! silent=options.silent, tracePlugins=options.trace_plugins, verbose=options.verbose, # True: prints log messages. ) if bridge.isOpen(): g = bridge.globals() path = g.os_path_finalize_join(g.app.loadDir, "..", "test") # relative_path) c = bridge.openLeoFile(path) if trace: g.es("%s %s" % (tag, c.shortFileName())) if c: runUnitTests(c, g) g.pr(tag, "done")
def main(): infoList = list() fpn1 = sys.argv[1] bridge = leoBridge.controller(gui='nullGui', verbose=False, loadPlugins=False, readSettings=False) leoG = bridge.globals() infoList.append('After bridge create: {0}'.format(leoG.app.nodeIndices.lastIndex)) cmdr1 = bridge.openLeoFile(fpn1) infoList.append('After {fpn} open: {idx}'.format(fpn=fpn1, idx=leoG.app.nodeIndices.lastIndex)) rp = cmdr1.rootPosition() posx = rp.insertAfter() posx.h = '{cnt} - {idx}'.format(cnt=2, idx=1) infoList.append('After adding 1 vnode: {idx}'.format(fpn=fpn1, idx=leoG.app.nodeIndices.lastIndex)) gnxRepeats(cmdr1, infoList) cmdr1.save() cmdr1.close() fpnError = os.path.join(TestDir, 'SlaveLog.txt') fdError = open(fpnError, 'w') fdError.write('\n'.join(infoList) + '\n') fdError.close()
def main(): '''Run a dynamic test using the Leo bridge.''' trace = True tag = 'leoDynamicTests.leo' if trace: t1 = time.time() options = scanOptions() if trace and trace_main: print('leoDynamicTest.py:main: options...') print(' curdir %s' % cwd) print(' path: %s' % options.path) print(' gui: %s' % options.gui) print(' load_plugins: %s' % options.load_plugins) print(' read_settings: %s' % options.read_settings) print(' silent: %s' % options.silent) print(' trace_plugins: %s' % options.trace_plugins) print(' verbose: %s' % options.verbose) bridge = leoBridge.controller( gui=options.gui, loadPlugins=options.load_plugins, readSettings=options.read_settings, # adds ~0.3 sec. Useful! silent=options.silent, tracePlugins=options.trace_plugins, verbose=options.verbose, # True: prints log messages. ) if trace and trace_time: t2 = time.time() print('%s open bridge: %0.2fsec' % (tag, t2 - t1)) if bridge.isOpen(): g = bridge.globals() g.app.silentMode = options.silent g.app.isExternalUnitTest = True path = g.os_path_finalize_join(g.app.loadDir, '..', 'test', options.path) c = bridge.openLeoFile(path) if trace: t3 = time.time() print('%s open file: %0.2fsec' % (tag, t3 - t2)) runUnitTests(c, g)
def main(): """Run a dynamic test using the Leo bridge.""" tag = 'leoDynamicTests.leo' if g_trace: t1 = time.time() options = scanOptions() if g_trace and trace_main: print('leoDynamicTest.py:main: options...') print(f" curdir {cwd}") print(f" path: {options.path}") print(f" gui: {options.gui}") print(f" load_plugins: {options.load_plugins}") print(f" read_settings: {options.read_settings}") print(f" silent: {options.silent}") print(f" trace_plugins: {options.trace_plugins}") print(f" verbose: {options.verbose}") bridge = leoBridge.controller( gui=options.gui, loadPlugins=options.load_plugins, readSettings=options.read_settings, # adds ~0.3 sec. Useful! silent=options.silent, tracePlugins=options.trace_plugins, verbose=options.verbose, # True: prints log messages. ) if g_trace and trace_time: t2 = time.time() print(f"{tag} open bridge: {t2 - t1:0.2f} sec") if bridge.isOpen(): g = bridge.globals() g.app.silentMode = options.silent g.app.isExternalUnitTest = True path = g.os_path_finalize_join(g.app.loadDir, '..', 'test', options.path) c = bridge.openLeoFile(path) if g_trace: t3 = time.time() print(f"{tag} open file: {t3 - t2:0.2f} sec") runUnitTests(c, g)
def main(): trace = False readSettings = True tag = 'leoDynamicTests.leo' if trace: t1 = time.time() # Setting verbose=True prints messages that would be sent to the log pane. path, gui, readSettings, silent = scanOptions() # print('(leoDynamicTest.py:main)','readSettings',readSettings) # print('(leoDynamicTest.py:main)','silent',silent) # Not loading plugins and not reading settings speeds things up considerably. bridge = leoBridge.controller( gui=gui, loadPlugins= False, # Must be False: plugins will fail when run externally. readSettings= True, # True: adds about 0.3 seconds. Very useful for some tests. silent=True, verbose=False) if trace: t2 = time.time() print('%s open bridge: %0.2fsec' % (tag, t2 - t1)) if bridge.isOpen(): g = bridge.globals() g.app.silentMode = silent g.app.isExternalUnitTest = True path = g.os_path_finalize_join(g.app.loadDir, '..', 'test', path) c = bridge.openLeoFile(path) if trace: t3 = time.time() print('%s open file: %0.2fsec' % (tag, t3 - t2)) runUnitTests(c, g)
def main(): """ Command Line Utility Entry Point Arguments: sys.argv: Command line arguments Returns: None """ args = cmdLineHandler() leoG.IdleTime = idle_time.IdleTime bridge = leoBridge.controller(gui='nullGui', silent=True, verbose=False, loadPlugins=True, readSettings=True) cmdrT = bridge.openLeoFile(args.fpnTests) if os.path.exists(args.fpnResults): os.remove(args.fpnResults) fdR = codecs.open(args.fpnResults, 'w', encoding='utf-8') testCmdr = lib_test.TestCmdr(cmdrT, fdR) genFindTests = lib_test.findTests(cmdrT) itPoll = leoG.IdleTime((lambda itRunTests: lib_test.runTests(itRunTests, cmdrT, fdR, testCmdr, genFindTests)), delay=10) itPoll.start() idle_time.IdleTime.idle()
python leoftsindex.py "workbook.leo#Links" """ import sys # add folder containing 'leo' folder to path sys.path.append("/home/tbrown/Package/leo/bzr/leo.repo/trunk") import leo.core.leoBridge as leoBridge import leo.plugins.leofts as leofts controller = leoBridge.controller( gui='nullGui', loadPlugins=False, # True: attempt to load plugins. readSettings=False, # True: read standard settings files. silent=False, # True: don't print signon messages. verbose=False ) g = controller.globals() # list of "files" to process files = sys.argv[1:] # set up leofts leofts.set_leo(g) g._gnxcache = leofts.GnxCache() fts = leofts.get_fts() fn2c = {} # cache to avoid loading same outline twice done = set() # outlines scanned, to avoid repetition repetition
def main(fname): #@+others #@+node:vitalije.20180518114847.1: *3* create_app def create_app(): app = Tk() app.columnconfigure(0, weight=1) app.rowconfigure(0, weight=1) # Adjust fonts font.nametofont('TkFixedFont').config(size=18) font.nametofont('TkTextFont').config(size=18) font.nametofont('TkDefaultFont').config(size=18) return app #@+node:vitalije.20180518114953.1: *3* create_gui def create_gui(app): f1 = PanedWindow( app, orient='horizontal', width=800, height=600, sashrelief='ridge', sashwidth=4, ) f1.grid( row=0, column=0, sticky="nesw", ) f2 = PanedWindow(f1, orient='vertical') canvW = Canvas(f2, bg='#113333') f2.add(canvW) logW = scrolledtext.ScrolledText(f2, bg='#223399', fg='#cccc99', font=font.nametofont('TkDefaultFont')) f2.add(logW) bodyW = makeBodyW(f1) f1.add(f2) f1.add(bodyW) return f1, f2, bodyW, canvW, logW #@+node:vitalije.20180518114840.1: *3* load_xml def load_xml(fname): ltm = loadLeo(fname) ltm.selectedPosition = ltm.positions[1] ltmbytes = ltm.tobytes() return ltm, ltmbytes #@+node:vitalije.20180518115038.1: *3* start_thread & helper functions def start_thread(app, f1, f2, ltmbytes): #@+others #@+node:ekr.20180530110733.1: *4* f_later def f_later(): f1.sash_place(0, 270, 1) f2.sash_place(0, 1, 350) app.geometry("800x600+120+50") app.wm_title(fname) app.after_idle(update_model) #@+node:ekr.20180530110731.1: *4* loadex (collects stats) def loadex(): '''The target of threading.Thread.''' if profile_load: # Profile the code. cProfile.runctx( 'loadex_helper()', globals(), locals(), 'profile_stats', # 'profile-%s.out' % process_name ) print('===== writing profile_stats') p = pstats.Stats('profile_stats') p.strip_dirs().sort_stats('tottime').print_stats(50) # .print_stats('leoDataModel.py', 50) else: loadex_helper() def loadex_helper(): ltm2 = LeoTreeModel.frombytes(ltmbytes) loaddir = os.path.dirname(fname) loadExternalFiles(ltm2, loaddir) G.q.put(ltm2) #@+node:ekr.20180530110733.2: *4* update_model def update_model(): try: m = G.q.get(False) ltm.positions = m.positions ltm.nodes = m.nodes ltm.parPos = m.parPos ltm.levels = m.levels ltm.attrs = m.attrs ltm.gnx2pos = m.gnx2pos draw_tree(G.tree, ltm) tend = time.monotonic() t1 = (tend - tstart) if bridge: logW.insert('end', '***Bridge loaded***\n') logW.insert('end', 'External files loaded in %.3fs\n' % t1) except queue.Empty: app.after(100, update_model) #@-others threading.Thread(target=loadex, name='externals-loader').start() app.after_idle(f_later) #@-others c = None if bridge: import leo.core.leoBridge as leoBridge controller = leoBridge.controller( gui='nullGui', loadPlugins=False, readSettings=False, silent=False, # Print signons, so we know why loading is slow. verbose=False, ) g = controller.globals() c = controller.openLeoFile(fname) g.trace(c) else: import leo.core.leoGlobals as g g.cls() # tstart = time.monotonic() ltm, ltmbytes = load_xml(fname) app = create_app() f1, f2, bodyW, canvW, logW = create_gui(app) start_thread(app, f1, f2, ltmbytes) return bunch( c=c, # EKR g=g, # EKR ltm=ltm, app=app, tree=canvW, body=bodyW, log=logW, q=queue.Queue(1), topIndex=IntVar())
python leoftsindex.py "workbook.leo#Links" """ import sys # add folder containing 'leo' folder to path # sys.path.append("/home/tbrown/Package/leo/bzr/leo.repo/trunk") import leo.core.leoBridge as leoBridge import leo.plugins.leofts as leofts controller = leoBridge.controller( gui='nullGui', loadPlugins=False, # True: attempt to load plugins. readSettings=False, # True: read standard settings files. silent=False, # True: don't print signon messages. verbose=False ) g = controller.globals() # list of "files" to process files = sys.argv[1:] # set up leofts leofts.set_leo(g) g._gnxcache = leofts.GnxCache() fts = leofts.get_fts() fn2c = {} # cache to avoid loading same outline twice done = set() # outlines scanned, to avoid repetition repetition
It may be necessary to quote the "file" on the command line, as the '#' may be interpreted as a comment delimiter:: python leoftsindex.py "workbook.leo#Links" """ import sys # add folder containing 'leo' folder to path sys.path.append("/home/tbrown/Package/leo/bzr/leo.repo/trunk") import leo.core.leoBridge as leoBridge import leo.plugins.leofts as leofts controller = leoBridge.controller(gui='nullGui') g = controller.globals() # list of "files" to process files = sys.argv[1:] # set up leofts leofts.set_leo(g) g._gnxcache = leofts.GnxCache() fts = leofts.get_fts() fn2c = {} # cache to avoid loading same outline twice done = set() # outlines scanned, to avoid repetition repetition todo = list(files)
dir_ = os.path.abspath('.') if dir_ not in sys.path: if trace_sys_path: print(f"appending {dir_} to sys.path") sys.path.append(dir_) if trace_sys_path: print('sys.path:...\n%s' % '\n'.join(sorted(sys.path))) print('sys.argv: %s %s' % (len(sys.argv), '\n'.join(sys.argv))) if gui == 'qt': # Do this here to bypass leoQt g.in_bridge logic. import leo.core.leoQt as leoQt assert leoQt import leo.core.leoBridge as leoBridge controller = leoBridge.controller(gui=gui, loadPlugins=loadPlugins, readSettings=readSettings, silent=silent, verbose=verbose) g = controller.globals() # This kills all output from commanders. if kill_leo_output: def do_nothing(*args, **keys): pass g.es_print = do_nothing for path in files: if os.path.exists(path): c = controller.openLeoFile(path)
# Import stuff... dir_ = os.path.abspath('.') if dir_ not in sys.path: if trace_sys_path: print('appending %s to sys.path' % dir_) sys.path.append(dir_) if trace_sys_path: print('sys.path:...\n%s' % '\n'.join(sorted(sys.path))) print('sys.argv: %s %s' % (len(sys.argv), '\n'.join(sys.argv))) if gui == 'qt': # Do this here to bypass leoQt g.in_bridge logic. import leo.core.leoQt as leoQt import leo.core.leoBridge as leoBridge controller = leoBridge.controller( gui=gui, loadPlugins=loadPlugins, readSettings=readSettings, silent=silent, verbose=verbose) g = controller.globals() # This kills all output from commanders. if kill_leo_output: def do_nothing(*args, **keys): pass g.es_print = do_nothing for path in files: if os.path.exists(path): c = controller.openLeoFile(path)
# -*- coding: utf-8 -*- import leo.core.leoBridge as leoBridge import os import sys # import pdb ; pdb.set_trace() import unittest load_dir = os.path.abspath(os.path.dirname(__file__)) test_dir = os.path.join(load_dir, 'leo', 'test') path = os.path.join(test_dir, 'unitTest.leo') assert os.path.exists(path), repr(path) controller = leoBridge.controller(gui='nullGui', loadPlugins=False, readSettings=True, silent=False, verbose=False) g = controller.globals() c = controller.openLeoFile(path) try: # Run all unit tests locally. root = g.findTopLevelNode(c, 'Active Unit Tests', exact=True) assert root, 'Not found: Active Unit Tests' c.selectPosition(root) tm = c.testManager g.unitTesting = g.app.unitTesting = True suite = unittest.makeSuite(unittest.TestCase) aList = tm.findAllUnitTestNodes(all=False, marked=False) setup_script = None found = False for p in aList: if tm.isTestSetupNode(p): setup_script = p.b test = None
It may be necessary to quote the "file" on the command line, as the '#' may be interpreted as a comment delimiter:: python leoftsindex.py "workbook.leo#Links" """ import sys # add folder containing 'leo' folder to path sys.path.append("/home/tbrown/Package/leo/bzr/leo.repo/trunk") import leo.core.leoBridge as leoBridge import leo.plugins.leofts as leofts controller = leoBridge.controller(gui='nullGui') g = controller.globals() # list of "files" to process files = sys.argv[1:] # set up leofts leofts.set_leo(g) g._gnxcache = leofts.GnxCache() fts = leofts.get_fts() fn2c = {} # cache to avoid loading same outline twice done = set() # outlines scanned, to avoid repetition repetition for item in files: