test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
update_db_credential.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 import sys
3 import getpass
4 import subprocess
5 import optparse
6 
7 def update_credential( serviceName, accountName, newPassword ):
8  command = 'cmscond_authentication_manager --update_conn -s %s -u %s -p %s' %(serviceName, accountName, newPassword )
9  pipe = subprocess.Popen( command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT )
10  stdout_val = pipe.communicate()[0]
11  return stdout_val
12 
13 def main():
14 
15  parser = optparse.OptionParser(usage =
16  'Usage: %prog <file> [<file> ...]\n'
17  )
18 
19  parser.add_option('-s', '--service',
20  dest = 'service',
21  help = 'the service hosting the account'
22  )
23 
24  parser.add_option('-a','--accountName',
25  dest = 'accountName',
26  help = 'the account name to change'
27  )
28 
29  (options, arguments) = parser.parse_args()
30 
31  if options.service == None or options.accountName == None:
32  parser.print_help()
33  return -2
34 
35  password = getpass.getpass( prompt= 'Enter the new password:')
36 
37  try:
38  print update_credential( options.service, options.accountName, password )
39  print 'Password changed.'
40  except e:
41  print 'Update credential failed.'
42 if __name__ == '__main__':
43  sys.exit(main())
Definition: main.py:1