Gnumed.timelinelib.config.arguments

Package Gnumed :: Package timelinelib :: Package config :: Module arguments |
[frames] | no frames]

# Source Code for Module Gnumed.timelinelib.config.arguments

     1  # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018  Rickard Lindberg, Roger Lindberg
     2  #
     3  # This file is part of Timeline.
     4  #
     5  # Timeline is free software: you can redistribute it and/or modify
     6  # it under the terms of the GNU General Public License as published by
     7  # the Free Software Foundation, either version 3 of the License, or
     8  # (at your option) any later version.
     9  #
    10  # Timeline is distributed in the hope that it will be useful,
    11  # but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  # GNU General Public License for more details.
    14  #
    15  # You should have received a copy of the GNU General Public License
    16  # along with Timeline.  If not, see <http://www.gnu.org/licenses/>.
    17
    18  """
    19  The ApplicationArguments class parses the command line arguments and
    20  options when the application is started.
    21
    22  If the application is started with:
    23      python3 timeline.py -h
    24
    25  a text will be displayed that describes valid arguments and valid
    26  options.
    27
    28  :doc:`Tests are found here <unit_config_arguments>`.
    29  """
    30
    31
    32  from optparse import OptionParser
    33  import os.path
    34
    35  from timelinelib.meta.version import get_full_version
    36
    37  import wx
    38
    39
    40 -class ApplicationArguments(object):
    41
    42 -    def __init__(self):
    43          self._option_parser = self._create_option_parser()
    44          self._create_config_file_option()
    45          self._create_debug_option()
    46
    47 -    def parse_from(self, arguments):
    48          (self.options, self.arguments) = self._option_parser.parse_args(arguments)
    49
    50 -    def get_files(self):
    51          return self.arguments
    52
    53 -    def get_first_file(self):
    54          try:
    55              return self.arguments[0]
    56          except IndexError:
    57              return None
    58
    59 -    def has_files(self):
    60          return len(self.arguments) > 0
    61
    62 -    def get_debug_flag(self):
    63          return self.options.debug
    64
    65 -    def get_config_file_path(self):
    66          if self.options.config_file_path:
    67              return self.options.config_file_path
    68          else:
    69              return os.path.join(
    70                  wx.StandardPaths.Get().GetUserConfigDir(),
    71                  ".thetimelineproj.cfg")
    72
    73 -    def _create_option_parser(self):
    74          return OptionParser(
    75              usage="%prog [options] [filename]",
    76              version=self._create_version_string())
    77
    78 -    def _create_version_string(self):
    79          return "%prog " + get_full_version()
    80
    81 -    def _create_config_file_option(self):
    82          self._option_parser.add_option(
    83              "-c", "--config-file", dest="config_file_path", default=None,
    84              help="Path to config file")
    85
    86 -    def _create_debug_option(self):
    87          self._option_parser.add_option(
    88              "--debug",
    89              default=False, action="store_true",
    90              help="Run Timeline with extra debug output")
    91