summaryrefslogtreecommitdiffstats
path: root/cli-tools/cura/cura_options.py
blob: 429740a964ee1424a30d09e35fde2513e157bcb3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
# Copyright (C) 2012  Peter Hatina <phatina@redhat.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.

import sys
import optparse

class CuraBasicOptions(object):
    def __init__(self, epil = ""):
        optparse.OptionParser.format_epilog = lambda self, formatter: self.epilog
        self.m_parser = optparse.OptionParser(
            add_help_option = False,
            epilog = epil)
        self.m_parser.add_option("", "--help",
            action="help",
            help = "print this message")
        self.m_parser.add_option("-h", "--hostname",
            action = "store",
            dest = "hostname",
            help = "remote machine hostname")
        self.m_parser.add_option("-u", "--username",
            action = "store",
            dest = "username",
            help = "remote machine username")
        self.m_parser.add_option("-p", "--password",
            action = "store",
            dest = "password",
            help = "remote machine password")

    def parse(self, argv):
        (self.m_options, self.m_pos_options) = self.m_parser.parse_args(argv[1:])

    def printHelp(self):
        self.m_parser.print_help()

    @property
    def good(self):
        return len(self.m_pos_options) == 0

    @property
    def hostname(self):
        return self.m_options.hostname if self.m_options.hostname else ""

    @property
    def username(self):
       return self.m_options.username if self.m_options.username else ""

    @property
    def password(self):
        return self.m_options.password if self.m_options.password else ""