document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #!/usr/bin/env python
  2. #file name : cm.py
  3. #Copyright (c) Arun.K.R
  4. #Creative Commons Attribution-Share Alike 3.0 Unported\' <http: 3.0="" by-sa="" creativecommons.org="" licenses="">
  5. #short for \'c\'ontact \'m\'anager
  6. #This is the entry point to the program
  7. #loads my own module cb.py which contains ContactBook class
  8. #which is the base of our implementation
  9. import cb
  10. import sys
  11.  
  12. def showHelp():
  13. \'\'\'show help for cm program\'\'\'
  14. print \'\'\'Usage: cm OPTION(S) [CONTACT_NAME]
  15. This program manages your contacts efficiently.
  16.  
  17. OPTIONS without CONTACT_NAME
  18. -h  help
  19. -v  version
  20. -a  add contact
  21. -l  list all contact\'s name
  22.  
  23. OPTIONS with CONTACT_NAME
  24. -r   remove contact
  25. -m  modify contact
  26. -c   show specified contact
  27.  
  28. No two OPTIONS can be specified at a time.
  29. example:
  30. cm -l   :lists all contact\'s name
  31. cm -r Ragu :removes contact of Ragu (if already there)\'\'\'
  32.  
  33. def showVer():
  34. \'\'\'prints version of program\'\'\'
  35. print \'\'\'cm (Contacts Manager) version 1.0
  36. Copyright (C) 2008 Arun.K.R, MegaWare(tm) <www.megaware.co.nr>
  37. This is free software.  You may redistribute copies of it under the terms of
  38. the \'Creative Commons Attribution-Share Alike 3.0 Unported\' <http: 3.0="" by-sa="" creativecommons.org="" licenses="">.\\
  39. There is NO WARRANTY, to the extent permitted by law.
  40. Written by Arun.K.R <code333>\'\'\'
  41.  
  42. cv = cb.ContactBook() #creates an object of ContactBook class
  43.  
  44. argLn = len(sys.argv) # this helps to speed up a littile bit (from my C++  experiance.)
  45. #this is because we don\'t need to calculate length again and again.
  46. if argLn <> 3:
  47. showHelp()
  48. elif argLn == 2:
  49. op = sys.argv[1][1] #reads second argument without trailing \'-\'
  50. #ToDo : what if argument is like this "cm -hv" which is obviously false
  51. op = op.lower()
  52. if op == \'h\' : #shows help
  53. showHelp()
  54. elif op == \'v\': #shows version
  55. showVer()
  56. elif op == \'a\': #add a contact
  57. name = str(raw_input(\'Enter Name : \'))
  58. #ToDo: for the next two we can add more than one items of each
  59. #also we can check for validity.ie., email address and phone number are
  60. #in proper format. also any constraints for name should also needs to be implemented.
  61. email = str(raw_input(\'Enter email, <enter> for none : \'))
  62. phone = str(raw_input(\'Enter phone, <enter> for none : \'))
  63. if email == \'\\n\': email = None
  64. if phone == \'\\n\': phone = None
  65. cv.updateContact(name, email, phone)
  66. elif op == \'l\': #print all contact\'s name
  67. cv.showNames()
  68. else: #invalied argument format
  69. print \'Invalied argument(s)\'
  70. showHelp()
  71. else: #there are 3 arguments
  72. op = sys.argv[1][1] #reads second argument without trailing \'-\'
  73. #ToDo : what if argument is like this "cm -cm" which is obviously false
  74. op = op.lower()
  75. name = sys.argv[2]
  76. if op == \'c\': #show specified contcat
  77. cv.showContact(name)
  78. elif op == \'m\': #modify given account
  79. #ToDo: for the next two we can add more than one items of each
  80. #also we can check for validity.ie., email address and phone number are
  81. #in proper format.
  82. print \'curent email is %s\' % cv.getEmail(name)
  83. email = str(raw_input(\'Enter new email, <enter> for current : \'))
  84. print \'current phone is %s\' % cv.getPhone(name)
  85. phone = str(raw_input(\'Enter new phone, <enter> for current : \'))
  86. if email == \'\\n\': email = cv.getEmail(name)
  87. if phone == \'\\n\': phone = cv.getPhone(name)
  88. cv.updateContact(name, email, phone)
  89. elif op == \'r\': #remove a contact
  90. if cv.hasContact(name) == True:
  91. print \'\\n following contact will be permanantly removed\'
  92. cv.showContact(name)
  93. if str(raw_input(\'do you want to continue (y/n): \')).lower() == \'y\':
  94. cv.rmContact(name)
  95. else:
  96. print \'There is no contact in this <%s> name\' % name
  97. else: #invalied argument format
  98. print \'Invalied arguments\'
  99. showHelp()
  100. #program ends here
  101. #|ലോകത്തിലെല്ലാവര്ക്കും നന്മ വരട്ടെ|लोका समस्ता सुखिनॊ भवन्तु| May there be well being to the people|
');