#!/usr/bin/env python # # Sample of txt2tags being used as a module (http://txt2tags.org) # # Details: # The document body is a string. # Headers and config are set with Python code. # This way you can fully control txt2tags behavior. # import sys import setup setup.setup_paths() import txt2tags # Here is the marked body text, it must be a list. txt = "=Hi!=\nHave a **nice** day.\n\nBye." txt = txt.split('\n') # Set the three header fields headers = ['Header 1', 'Header 2', 'Header 3'] # Set the configuration on the 'config' dict. config = txt2tags.ConfigMaster()._get_defaults() config['outfile'] = txt2tags.MODULEOUT # results as list config['target'] = 'html' # target type: HTML config['encoding'] = 'UTF-8' # document encoding config['css-sugar'] = 1 # CSS friendly
if config.compile_caffe: print(bcolors.HEADER + ("==== PYGT: Compiling Caffe/Greentea ====").ljust(80,"=") + bcolors.ENDC) setup.compile_caffe(config.caffe_path) if config.compile_malis: print(bcolors.HEADER + ("==== PYGT: Compiling Malis ====").ljust(80,"=") + bcolors.ENDC) setup.compile_malis(config.malis_path) if (pygtpath != cmdpath): os.chdir(cmdpath) print(bcolors.OKGREEN + ("==== PYGT: Setup finished ====").ljust(80,"=") + bcolors.ENDC) sys.exit(0) setup.setup_paths(config.caffe_path, config.malis_path) setup.set_environment_vars() # Import Caffe import caffe as caffe # Import the network generator import network_generator as netgen # Import Malis import malis as malis # Wrapper around a networks set_input_arrays to prevent memory leaks of locked up arrays class NetInputWrapper:
setup.compile_caffe(config.caffe_path) if config.compile_malis: print(bcolors.HEADER + ("==== PYGT: Compiling Malis ====").ljust(80, "=") + bcolors.ENDC) setup.compile_malis(config.malis_path) if (pygtpath != cmdpath): os.chdir(cmdpath) print(bcolors.OKGREEN + ("==== PYGT: Setup finished ====").ljust(80, "=") + bcolors.ENDC) sys.exit(0) setup.setup_paths(config.caffe_path, config.malis_path) setup.set_environment_vars() # Import Caffe import caffe as caffe # Import the network generator import network_generator as netgen # Import Malis import malis as malis # Wrapper around a networks set_input_arrays to prevent memory leaks of locked up arrays class NetInputWrapper: def __init__(self, net, shapes):
#!/usr/bin/env python # # Sample of txt2tags being used as a module (http://txt2tags.org) # # Details: # The full marked text is a string with headers, config and body. # No post config or setting is made. # import sys import setup setup.setup_paths() import txt2tags # Here is the marked text, it must be a list. txt = "Header1\nHeader2\nHeader3\n%!target: html\nBody line 1." txt = txt.split('\n') # Let's do the conversion try: # First we parse the text, splitting parts and getting config. data = txt2tags.process_source_file(contents=txt) # Then we convert it, dumping results to the 'tagged' list. tagged, config = txt2tags.convert_this_files([data]) # Show the tagged file on the screen. print '\n'.join(tagged) # Txt2tags error, show the message to the user