Changeset 62f3dd9 for fedd/federation


Ignore:
Timestamp:
Dec 10, 2010 9:00:16 AM (13 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master
Children:
913dc7a
Parents:
fbee30a
git-author:
Ted Faber <faber@…> (12/09/10 11:41:45)
git-committer:
Ted Faber <faber@…> (12/10/10 09:00:16)
Message:

allow command line progams to expand tildes. Added a class derived from OptionParser? to make that easily available.

Location:
fedd/federation
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • fedd/federation/client_lib.py

    rfbee30a r62f3dd9  
    1010
    1111from fedid import fedid
    12 from util import fedd_ssl_context
     12from util import fedd_ssl_context, file_expanding_opts
    1313from remote_service import service_caller
    1414from service_error import service_error
     
    1717
    1818
    19 class client_opts(OptionParser):
     19class client_opts(file_expanding_opts):
    2020    """
    2121    Standatd set of options that all clients talking to fedd can probably use.
    2222    Client code usually specializes this.
    2323    """
     24
    2425    def __init__(self):
    25         OptionParser.__init__(self, usage="%prog [opts] (--help for details)",
     26        file_expanding_opts.__init__(self,
     27                usage="%prog [opts] (--help for details)",
    2628                version="0.1")
    2729
    28         self.add_option("--cert", action="store", dest="cert",
     30        self.add_option("--cert", action="callback", dest="cert",
     31                callback=self.expand_file,
    2932                type="string", help="my certificate file")
    30         self.add_option("--abac", action="store", dest="abac_dir",
    31                 type="string", help="Directory with abac certs")
     33        self.add_option("--abac", action="callback", dest="abac_dir",
     34                callback=self.expand_file,
     35                type="string", default=os.path.expanduser('~/.abac'),
     36                help="Directory with abac certs")
     37        self.add_option('--no_abac', action='store_const', const=None,
     38                dest='abac_dir', help='Do not use abac authorization')
    3239        self.add_option( "--debug", action="count", dest="debug",
    3340                default=0, help="Set debug.  Repeat for more information")
     
    3542                dest="serialize_only", default=False,
    3643                help="Print the SOAP request that would be sent and exit")
    37         self.add_option("--trusted", action="store", dest="trusted",
     44        self.add_option("--trusted", action="callback", dest="trusted",
     45                callback=self.expand_file,
    3846                type="string", help="Trusted certificates (required)")
    3947        self.add_option("--url", action="store", dest="url",
     
    98106    '''
    99107    rv = [ ]
    100     if dir:
     108    if dir and os.path.isdir(dir):
    101109        for fn in ["%s/%s" % (dir, p) for p in os.listdir(dir) \
    102110                if os.path.isfile("%s/%s" % (dir,p))]:
  • fedd/federation/util.py

    rfbee30a r62f3dd9  
    88
    99import httplib
     10
     11from optparse import OptionParser
    1012
    1113from socket import sslerror
     
    9597            self.set_allow_unknown_ca(True)
    9698            self.set_verify(SSL.verify_peer, 10, callback=callb)
     99
     100class file_expanding_opts(OptionParser):
     101    def expand_file(self, option, opt_str, v, p):
     102        """
     103        Store the given value to the given destination after expanding home
     104        directories.
     105        """
     106        setattr(p.values, option.dest, os.path.expanduser(v))
     107
     108    def __init__(self, usage=None, version=None):
     109        OptionParser.__init__(self)
     110
    97111
    98112def read_simple_accessdb(fn, auth, mask=[]):
Note: See TracChangeset for help on using the changeset viewer.