Package caldavclientlibrary :: Package browser :: Package commands :: Module props
[hide private]
[frames] | no frames]

Source Code for Module caldavclientlibrary.browser.commands.props

  1  ## 
  2  # Copyright (c) 2007-2016 Apple Inc. All rights reserved. 
  3  # 
  4  # Licensed under the Apache License, Version 2.0 (the "License"); 
  5  # you may not use this file except in compliance with the License. 
  6  # You may obtain a copy of the License at 
  7  # 
  8  # http://www.apache.org/licenses/LICENSE-2.0 
  9  # 
 10  # Unless required by applicable law or agreed to in writing, software 
 11  # distributed under the License is distributed on an "AS IS" BASIS, 
 12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 13  # See the License for the specific language governing permissions and 
 14  # limitations under the License. 
 15  ## 
 16   
 17  from caldavclientlibrary.browser.command import Command 
 18  from caldavclientlibrary.browser.command import WrongOptions 
 19  from caldavclientlibrary.protocol.url import URL 
 20  from caldavclientlibrary.browser import utils 
 21  import os 
 22  import getopt 
 23  import shlex 
 24   
25 -class Cmd(Command):
26
27 - def __init__(self):
28 super(Command, self).__init__() 29 self.cmds = ("props",)
30
31 - def execute(self, name, options):
32 33 names = False 34 all = False 35 xmllist = False 36 path = None 37 38 opts, args = getopt.getopt(shlex.split(options), 'aln') 39 40 for name, _ignore_value in opts: 41 42 if name == "-a": 43 all = True 44 elif name == "-l": 45 xmllist = True 46 elif name == "-n": 47 names = True 48 else: 49 print "Unknown option: %s" % (name,) 50 print self.usage(name) 51 raise WrongOptions 52 53 if len(args) > 1: 54 print "Wrong number of arguments: %d" % (len(args),) 55 print self.usage(name) 56 raise WrongOptions 57 elif args: 58 path = args[0] 59 if not path.startswith("/"): 60 path = os.path.join(self.shell.wd, path) 61 else: 62 path = self.shell.wd 63 if not path.endswith("/"): 64 path += "/" 65 resource = URL(url=path) 66 67 if names: 68 results = self.shell.account.session.getPropertyNames(resource) 69 print " Properties: %s" % (utils.printList(results),) 70 else: 71 if all: 72 props = None 73 else: 74 props = self.shell.account.session.getPropertyNames(resource) 75 results, bad = self.shell.account.session.getProperties(resource, props, xmllist) 76 print "OK Properties:" 77 utils.printProperties(results) 78 if bad: 79 print "Failed Properties:" 80 utils.printProperties(bad) 81 82 return True
83
84 - def complete(self, text):
85 return self.shell.wdcomplete(text)
86
87 - def usage(self, name):
88 return """Usage: %s [OPTIONS] [PATH] 89 PATH is a relative or absolute path. 90 91 Options: 92 -n list property names only 93 -a list all properties via allprop 94 -l list actual property XML values 95 if neither -n nor -a are set then property names are first listed, and then values of those looked up. 96 only one of -n and -a can be set. 97 """ % (name,)
98
99 - def helpDescription(self):
100 return "List the properties of a directory or file."
101