|
import sys, getopt
def myapp(argv):
FILE_NAME = argv[0] # command line argumentsÀÇ Ã¹¹ø°´Â ÆÄÀϸí
INSTANCE_NAME = "" # ÀνºÅϽº¸í ÃʱâÈ
CHANNEL_NAME = "" # ä³Î¸í ÃʱâÈ
try:
# opts: getopt ¿É¼Ç¿¡ µû¶ó ÆÄ½Ì ex) [('-i', 'myinstancce1')]
# etc_args: getopt ¿É¼Ç ÀÌ¿Ü¿¡ ÀÔ·ÂµÈ ÀÏ¹Ý Argument
# argv ù¹ø°(index:0)´Â ÆÄÀϸí, µÎ¹ø°(index:1)ºÎÅÍ Arguments
opts, etc_args = getopt.getopt(argv[1:], \
"hi:c:", ["help","instance=","channel="])
except getopt.GetoptError: # ¿É¼ÇÁöÁ¤ÀÌ ¿Ã¹Ù¸£Áö ¾ÊÀº °æ¿ì
print(FILE_NAME, '-i <instance name> -c <channel name>')
sys.exit(2)
for opt, arg in opts: # ¿É¼ÇÀÌ ÆÄ½ÌµÈ °æ¿ì
if opt in ("-h", "--help"): # HELP ¿äûÀÎ °æ¿ì »ç¿ë¹ý Ãâ·Â
print(FILE_NAME, '-i <instance name> -c <channel name>')
sys.exit()
elif opt in ("-i", "--instance"): # ÀνºÅϸí ÀÔ·ÂÀÎ °æ¿ì
INSTANCE_NAME = arg
elif opt in ("-c", "--channel"): # ä³Î¸í ÀÔ·ÂÀÎ °æ¿ì
CHANNEL_NAME = arg
if len(INSTANCE_NAME) < 1: # ÇʼöÇ׸ñ °ªÀÌ ºñ¾îÀÖ´Ù¸é
print(FILE_NAME, "-i option is mandatory") # ÇʼöÀÓÀ» Ãâ·Â
sys.exit(2)
print("INSTANCE_NAME:", INSTANCE_NAME)
print("CHANNEL_NAME:", CHANNEL_NAME)
# moduleÀÌ ¾Æ´Ñ mainÀ¸·Î ½ÇÇàµÈ °æ¿ì ½ÇÇàµÈ´Ù
if __name__ == "__main__":
myapp(sys.argv) |
|