def __init__( self, parent = None, options = None, name = None, version = None, logo = None, engage_log = True, filename_log = None, instance = None ): global clock clock = shijian.Clock(name = "program run time") if options is None: options = dict() self.options = options self.username = self.options["--username"] self.verbose = self.options["--verbose"] self.silent = self.options["--silent"] self.name = name self.version = version self.logo = logo self.engage_log = engage_log self.filename_log = filename_log self.instance = instance if self.username is None: self.username = os.getenv("USER") if self.logo is not None: self.display_logo = True elif self.logo is None and self.name is not None: self.logo = pyprel.render_banner( text = self.name.upper() ) self.display_logo = True else: self.display_logo = False if self.instance is None: self.instance = str(uuid.uuid4()) # logging if engage_log: global log log = logging.getLogger(__name__) logging.root.addHandler(technicolor.ColorisingStreamHandler()) # logging level if self.verbose: logging.root.setLevel(logging.DEBUG) else: logging.root.setLevel(logging.INFO) if self.filename_log: logging.root.addHandler(logging.FileHandler(self.filename_log)) self.engage()
def main(options): global program program = propyte.Program( options = options, name = name, version = version, logo = logo ) global log from propyte import log interval = float(options["--interval"]) clock_restart = shijian.Clock(name = "restart") log.info("\nrestart interval: {interval} s".format(interval = interval)) while True: log.info("\ncurrent run time: {run_time}".format(run_time = clock_restart.time())) log.info("restart yet? (i.e. current run time >= interval): {restart}".format(restart = clock_restart.time() >= interval)) if clock_restart.time() >= interval: print(pyprel.center_string(text = pyprel.render_banner(text = "restart"))) propyte.restart() time.sleep(1)
def main(options): global program program = propyte.Program(options=options, name=name, version=version, logo=logo) global log from propyte import log interval = float(options["--interval"]) clock_restart = shijian.Clock(name="restart") log.info("\nrestart interval: {interval} s".format(interval=interval)) while True: log.info("\ncurrent run time: {run_time}".format( run_time=clock_restart.time())) log.info("restart yet? (i.e. current run time >= interval): {restart}". format(restart=clock_restart.time() >= interval)) if clock_restart.time() >= interval: print( pyprel.center_string(text=pyprel.render_banner( text="restart"))) propyte.restart() time.sleep(1)
def main(options): interval = float(options["--interval"]) print(pyprel.center_string(text = pyprel.render_banner(text = "start"))) clock_restart = shijian.Clock(name = "restart") print("restart interval: {interval} s".format(interval = interval)) while True: print("\ncurrent run time: {run_time}".format(run_time = clock_restart.time())) print("restart yet? (i.e. current run time >= interval): {restart}".format(restart = clock_restart.time() >= interval)) if clock_restart.time() >= interval: print(pyprel.center_string(text = pyprel.render_banner(text = "restart"))) os.execv(__file__, sys.argv) time.sleep(1)
def __init__(self, parent=None, options=None, name=None, version=None, logo=None, engage_log=True, filename_log=None, instance=None): global clock clock = shijian.Clock(name="program run time") if options is None: options = dict() self.options = options self.username = self.options["--username"] self.verbose = self.options["--verbose"] self.silent = self.options["--silent"] self.name = name self.version = version self.logo = logo self.engage_log = engage_log self.filename_log = filename_log self.instance = instance if self.username is None: self.username = os.getenv("USER") if self.logo is not None: self.display_logo = True elif self.logo is None and self.name is not None: self.logo = pyprel.render_banner(text=self.name.upper()) self.display_logo = True else: self.display_logo = False if self.instance is None: self.instance = str(uuid.uuid4()) # logging if engage_log: global log log = logging.getLogger(__name__) logging.root.addHandler(technicolor.ColorisingStreamHandler()) # logging level if self.verbose: logging.root.setLevel(logging.DEBUG) else: logging.root.setLevel(logging.INFO) if self.filename_log: logging.root.addHandler(logging.FileHandler(self.filename_log)) self.engage()
def __init__(self, parent=None, options=None): # internal options self.display_logo = True # clock global clock clock = shijian.Clock(name="program run time") # name, version, logo if "name" in globals(): self.name = name else: self.name = None if "version" in globals(): self.version = version else: self.version = None if "logo" in globals(): self.logo = logo elif "logo" not in globals() and hasattr(self, "name"): self.logo = pyprel.render_banner(text=self.name.upper()) else: self.display_logo = False self.logo = None # options self.options = options self.username = self.options["--username"] self.verbose = self.options["--verbose"] self.files = self.options["--files"] self.configuration_filename = self.options["--configuration"] # default values if self.username is None: self.username = os.getenv("USER") if self.files is not None: self.files = self.files.split(",") # logging global log log = logging.getLogger(__name__) logging.root.addHandler(technicolor.ColorisingStreamHandler()) # logging level if self.verbose: logging.root.setLevel(logging.DEBUG) else: logging.root.setLevel(logging.INFO) self.engage() # configuration self.configuration = pyrecon.open_configuration( self.configuration_filename)
def main(): print("\nexample: printout of dictionary") get_input("Press Enter to continue.") information = { "sample information": { "ID": 169888, "name": "ttH", "number of events": 124883, "cross section": 0.055519, "k factor": 1.0201, "generator": "pythia8", "variables": { "trk_n": 147, "zappo_n": 9001 } } } pyprel.print_line() pyprel.print_dictionary(dictionary = information) pyprel.print_line() print(pyprel.dictionary_string(dictionary = information)) pyprel.print_line() print("\nexample: printout of existing logo") get_input("Press Enter to continue.") text = ( " ____ _ _____ _ \n" " / ___|___ | | ___ _ __| ___| | _____ __ \n" " | | / _ \| |/ _ \| '__| |_ | |/ _ \ \ /\ / / \n" " | |__| (_) | | (_) | | | _| | | (_) \ V V / \n" " \____\___/|_|\___/|_| |_| |_|\___/ \_/\_/ " ) pyprel.print_center(text = text) print("\nexample: rendering and printout of logo") get_input("Press Enter to continue.") name = "aria" logo = pyprel.render_banner( text = name.upper() ) pyprel.print_line() print(pyprel.center_string(text = logo)) pyprel.print_line() print("\nexample: rendering and printout segment display") get_input("Press Enter to continue.") print(pyprel.render_segment_display(text = "0123456789")) print("\nexample: printout of tables") get_input("Press Enter to continue.") table_contents = [ ["heading 1", "heading 2"], ["some text", "some more text"], ["lots and lots and lots and lots and lots of text", "some more text"] ] print( pyprel.Table( contents = table_contents, column_width = 25 ) ) print( pyprel.Table( contents = table_contents, table_width_requested = 30 ) ) print( pyprel.Table( contents = table_contents, table_width_requested = 30, hard_wrapping = True ) ) print( pyprel.Table( contents = table_contents ) ) pyprel.print_center( text = pyprel.Table( contents = table_contents, table_width_requested = 30 ).__str__() ) print( pyprel.Table( contents = table_contents, column_width = 25, column_delimiter = "||" ) ) print( pyprel.Table( contents = table_contents, column_width = 25, row_delimiter = "~" ) ) table_contents = [ [ "heading 1", "heading 2", "heading 3" ], [ "some text", "some more text", "even more text" ], [ "lots and lots and lots and lots and lots of text", "some more text", "some more text" ] ] print( pyprel.Table( contents = table_contents ) ) table_contents = [ [ "heading 1", "heading 2", "heading 3", "heading 4" ], [ "some text", "some more text", "even more text", "yeah more text" ], [ "lots and lots and lots and lots and lots of text", "some more text", "some more text", "some more text" ] ] print( pyprel.Table( contents = table_contents ) )