def __init__(self): # instance attributes, feels safer self.name = None self.options = None self.args = None self.__verbose = None self.__verbose_default = 0 self.__timeout = None self.__timeout_default = 10 self.__timeout_max = 86400 self.__total_run_time = time.time() self.topfile = get_topfile() self._docstring = get_file_docstring(self.topfile) if self._docstring: self._docstring = '\n' + self._docstring.strip() + '\n' if self._docstring is None: self._docstring = '' self._topfile_version = get_file_version(self.topfile) # this doesn't work in unit tests # if self._topfile_version: # raise CodingError('failed to get topfile version - did you set a __version__ in top cli program?') # pylint: disable=line-too-long self._cli_version = self.__version__ self._utils_version = harisekhon.utils.__version__ # returns 'python -m unittest' :-/ # prog = os.path.basename(sys.argv[0]) self._prog = os.path.basename(self.topfile) self._github_repo = get_file_github_repo(self.topfile) # _hidden attributes are shown in __dict__ self.version = '{prog} version {topfile_version} '.format(prog=self._prog, topfile_version=self._topfile_version) + \ '=> CLI version {cli_version} '.format(cli_version=self._cli_version) + \ '=> Utils version {utils_version}'.format(utils_version=self._utils_version) self.usagemsg = 'Hari Sekhon{sep}{github_repo}\n\n{prog}\n{docstring}\n'.format(\ sep=' - ' if self._github_repo else '', github_repo=self._github_repo, prog=self._prog, docstring=self._docstring) self.usagemsg_short = 'Hari Sekhon%(_github_repo)s\n\n' % self.__dict__ # set this in simpler client programs when you don't want to exclude # self.__parser = OptionParser(usage=self.usagemsg_short, version=self.version) # self.__parser = OptionParser(version=self.version) # will be added by default_opts later so that it's not annoyingly at the top of the option help # also this allows us to print full docstring for a complete description and not just the cli switches # description=self._docstring # don't want description printed for option errors width = os.getenv('COLUMNS', None) if not isInt(width) or not width: try: width = Terminal().width except _curses.error: width = 80 width = min(width, 200) self.__parser = OptionParser(add_help_option=False, formatter=IndentedHelpFormatter(width=width)) # duplicate key error or duplicate options, sucks # self.__parser.add_option('-V', dest='version', help='Show version and exit', action='store_true') self.setup()
def __init__(self): # instance attributes, feels safer self.options = None self.args = None self.__verbose = None self.__verbose_default = 0 self.__timeout = None self.__timeout_default = 10 self.__timeout_max = 86400 self.topfile = get_topfile() # this gets utrunner.py in PyCharm and runpy.py from unittest if os.path.basename(self.topfile) in ('utrunner.py', 'runpy.py'): self.topfile = __file__ #print('topfile = %s' % self.topfile) self._docstring = get_file_docstring(self.topfile) if self._docstring: self._docstring = '\n' + self._docstring.strip() + '\n' if self._docstring is None: self._docstring = '' self._topfile_version = get_file_version(self.topfile) # this doesn't work in unit tests # if self._topfile_version: # raise CodingError('failed to get topfile version - did you set a __version__ in top cli program?') # pylint: disable=line-too-long self._cli_version = self.__version__ self._utils_version = harisekhon.utils.__version__ # returns 'python -m unittest' :-/ # prog = os.path.basename(sys.argv[0]) self._prog = os.path.basename(self.topfile) self._github_repo = get_file_github_repo(self.topfile) # if not self.github_repo: # self.github_repo = 'https://github.com/harisekhon/pytools' if self._github_repo: self._github_repo = ' - ' + self._github_repo # _hidden attributes are shown in __dict__ self.version = '%(_prog)s version %(_topfile_version)s ' % self.__dict__ + \ '=> CLI version %(_cli_version)s => Utils version %(_utils_version)s' % self.__dict__ self.usagemsg = 'Hari Sekhon%(_github_repo)s\n\n%(_prog)s\n%(_docstring)s\n' \ % self.__dict__ self.usagemsg_short = 'Hari Sekhon%(_github_repo)s\n\n' % self.__dict__ # set this in simpler client programs when you don't want to exclude # self.__parser = OptionParser(usage=self.usagemsg_short, version=self.version) # self.__parser = OptionParser(version=self.version) # will be added by default_opts later so that it's not annoyingly at the top of the option help # also this allows us to print full docstring for a complete description and not just the cli switches # description=self._docstring # don't want description printed for option errors width = os.getenv('COLUMNS', None) if not isInt(width) or not width: width = Terminal().width width = min(width, 200) self.__parser = OptionParser(add_help_option=False, formatter=IndentedHelpFormatter(width=width)) # duplicate key error or duplicate options, sucks # self.__parser.add_option('-V', dest='version', help='Show version and exit', action='store_true') self.setup()
def __init__(self): # instance attributes, feels safer self.name = None self.default_host = None self.default_port = None self.default_user = None self.default_password = None self.options = None self.args = None self.__verbose_default = 0 self.__verbose = self.__verbose_default self.__timeout_default = 10 self.__timeout = None self.__timeout_max = 86400 self.__total_run_time = time.time() self.topfile = get_topfile() self._docstring = get_file_docstring(self.topfile) if self._docstring: self._docstring = '\n' + self._docstring.strip() + '\n' if self._docstring is None: self._docstring = '' self._topfile_version = get_file_version(self.topfile) # this doesn't work in unit tests # if self._topfile_version: # raise CodingError('failed to get topfile version - did you set a __version__ in top cli program?') self._cli_version = self.__version__ self._utils_version = harisekhon.utils.__version__ # returns 'python -m unittest' :-/ # prog = os.path.basename(sys.argv[0]) self._prog = os.path.basename(self.topfile) self._github_repo = get_file_github_repo(self.topfile) # _hidden attributes are shown in __dict__ self.version = '{prog} version {topfile_version} '.format(prog=self._prog, topfile_version=self._topfile_version) + \ '=> CLI version {cli_version} '.format(cli_version=self._cli_version) + \ '=> Utils version {utils_version}'.format(utils_version=self._utils_version) self.usagemsg = 'Hari Sekhon{sep}{github_repo}\n\n{prog}\n{docstring}\n'.format(\ sep=' - ' if self._github_repo else '', github_repo=self._github_repo, prog=self._prog, docstring=self._docstring) self.usagemsg_short = 'Hari Sekhon%(_github_repo)s\n\n' % self.__dict__ # set this in simpler client programs when you don't want to exclude # self.__parser = OptionParser(usage=self.usagemsg_short, version=self.version) # self.__parser = OptionParser(version=self.version) # will be added by default_opts later so that it's not annoyingly at the top of the option help # also this allows us to print full docstring for a complete description and not just the cli switches # description=self._docstring # don't want description printed for option errors width = os.getenv('COLUMNS', None) if not isInt(width) or not width: try: width = Terminal().width except _curses.error: width = 80 #width = min(width, 200) self.__parser = OptionParser( add_help_option=False, formatter=IndentedHelpFormatter(width=width)) # duplicate key error or duplicate options, sucks # self.__parser.add_option('-V', dest='version', help='Show version and exit', action='store_true') self.setup()