#!/usr/bin/env python # Copyright (C) 2012 Peter Hatina # # 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 . 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 ""