コード例 #1
0
ファイル: gsend.py プロジェクト: nandub/pygale
def main():
	global RETURN_RECEIPT, DONT_SEND
	opts, args = getopt.getopt(sys.argv[1:], 'pPd:vn')
	for (opt, val) in opts:
		if opt == '-P':
			RETURN_RECEIPT = 0
		elif opt == '-p':
			RETURN_RECEIPT = 1
		elif opt == '-n':
			DONT_SEND = 1
		elif opt == '-d':
			pygale.DEBUG = int(val)
		elif opt == '-v':
			usage(sys.argv[0])
			sys.exit(0)
		else:
			usage(sys.argv[0])
			print 'Unknown option:', opt
			sys.exit(0)

	# Initialize PyGale before processing locations
	pygale.init()
	sys.exitfunc = pygale.shutdown
	pygale.set_error_handler(print_msg)
	pygale.set_update_handler(print_msg)

	if not gale_env.get('GALE_DOMAIN', None):
		print 'Please run pygale-config to set up your PyGale environment.'
		sys.exit(0)

	# Extract locations and keywords from cmdline args
	locs = filter(lambda x: x[0] != '/', args)
	# default domain and alias expansion
	locs = map(pygale.expand_aliases, locs)
	keywords = map(lambda x: x[1:], filter(lambda x: x[0] == '/', args))
	if not locs:
		usage(sys.argv[0])
		sys.exit()
	
	# Send it
	try:
		sendpuff(locs, keywords)
	except KeyboardInterrupt:
		sys.exit(0)
コード例 #2
0
ファイル: gsub.py プロジェクト: nandub/pygale
	if not good:
		print_msg('No locations found')
		sys.exit(-1)
	else:
		for g in good:
			print_msg('Subscribed to %s' % g)

if __name__ == '__main__':
	opts, args = getopt.getopt(sys.argv[1:], 'd:av')
	quiet = 0
	for opt, val in opts:
		if opt == '-d':
			pygale.DEBUG = int(val)
		elif opt == '-a':
			quiet = 1
		elif opt == '-v':
			usage(sys.argv[0])
			sys.exit()
	if len(args) < 1:
		usage(sys.argv[0])
		sys.exit()
	
	pygale.init()
	sys.exitfunc = pygale.shutdown
	pygale.set_error_handler(print_msg)
	pygale.set_update_handler(print_msg)
	try:
		recvpuffs(args, quiet)
	except KeyboardInterrupt:
		sys.exit(0)