[CalendarServer-changes] [10928] CalendarServer/trunk/calendarserver/tools/push.py
source_changes at macosforge.org
source_changes at macosforge.org
Thu Mar 14 22:15:14 PDT 2013
Revision: 10928
http://trac.calendarserver.org//changeset/10928
Author: dre at apple.com
Date: 2013-03-14 22:15:14 -0700 (Thu, 14 Mar 2013)
Log Message:
-----------
calendarserver_manage_push command line option parsing was busted. fixed and vastly simplified by switching from getopt to argparse
Modified Paths:
--------------
CalendarServer/trunk/calendarserver/tools/push.py
Modified: CalendarServer/trunk/calendarserver/tools/push.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/push.py 2013-03-15 00:01:31 UTC (rev 10927)
+++ CalendarServer/trunk/calendarserver/tools/push.py 2013-03-15 05:15:14 UTC (rev 10928)
@@ -19,39 +19,18 @@
from calendarserver.tap.util import getRootResource
from calendarserver.tools.cmdline import utilityMain
from errno import ENOENT, EACCES
-from getopt import getopt, GetoptError
+from argparse import ArgumentParser
from twext.python.log import Logger
from twisted.application.service import Service
from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks
from twistedcaldav.config import config, ConfigurationError
-import os
import sys
import time
log = Logger()
-def usage(e=None):
- name = os.path.basename(sys.argv[0])
- print("usage: %s [options] [user ...]" % (name,))
- print("")
- print(" Display Apple Push Notification subscriptions")
- print("")
- print("options:")
- print(" -h --help: print this help and exit")
- print(" -f --config <path>: Specify caldavd.plist configuration path")
- print(" -D --debug: debug logging")
- print("")
-
- if e:
- sys.stderr.write("%s\n" % (e,))
- sys.exit(64)
- else:
- sys.exit(0)
-
-
-
class WorkerService(Service):
def __init__(self, store):
@@ -109,45 +88,18 @@
def main():
- try:
- (optargs, args) = getopt(
- sys.argv[1:], "Df:h", [
- "config=",
- "help",
- "debug",
- ],
- )
- except GetoptError, e:
- usage(e)
+ parser = ArgumentParser(description='Display Apple Push Notification subscriptions')
+ parser.add_argument('-f', '--config', dest='configFileName', metavar='CONFIGFILE', help='caldavd.plist configuration file path')
+ parser.add_argument('-d', '--debug', action='store_true', help='show debug logging')
+ parser.add_argument('user', help='one or more users to display', nargs='+') # Required
+ args = parser.parse_args()
- #
- # Get configuration
- #
- configFileName = None
- debug = False
+ DisplayAPNSubscriptions.users = args.user
- for opt, arg in optargs:
- if opt in ("-h", "--help"):
- usage()
-
- elif opt in ("-f", "--config"):
- configFileName = arg
-
- if opt in ("-d", "--debug"):
- debug = True
-
- else:
- raise NotImplementedError(opt)
-
- if not args:
- usage("Not enough arguments")
-
- DisplayAPNSubscriptions.users = args
-
utilityMain(
- configFileName,
+ args.configFileName,
DisplayAPNSubscriptions,
- verbose=debug,
+ verbose=args.debug,
)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130314/83ea7f34/attachment.html>
More information about the calendarserver-changes
mailing list