~ziad-sawalha/keystone/trunk

« back to all changes in this revision

Viewing changes to management/setuserlock.py

  • Committer: Brian Lamar
  • Date: 2011-05-24 15:36:52 UTC
  • mto: This revision was merged to the branch mainline in revision 103.
  • Revision ID: git-v1:6fdc83234f821a3b893c92ab496e6170818fefd2
-Removed .project file from project and added it to .gitignore
-Moved pylintrc -> .pylintrc, personal preference that this file should be available, but not seen
-Moved echo to examples directory, seemed a bit odd to be in the top level
-Moved management directory to tools, seemed a bit odd to be in the top level
-Moved pip-requires to tools/, and updated the reference to it in README.md

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
# Copyright (c) 2010-2011 OpenStack, LLC.
3
 
#
4
 
# Licensed under the Apache License, Version 2.0 (the "License");
5
 
# you may not use this file except in compliance with the License.
6
 
# You may obtain a copy of the License at
7
 
#
8
 
#    http://www.apache.org/licenses/LICENSE-2.0
9
 
#
10
 
# Unless required by applicable law or agreed to in writing, software
11
 
# distributed under the License is distributed on an "AS IS" BASIS,
12
 
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
 
# implied.
14
 
# See the License for the specific language governing permissions and
15
 
# limitations under the License.
16
 
 
17
 
import os
18
 
import sys
19
 
 
20
 
# If ../keystone/__init__.py exists, add ../ to Python search path, so that
21
 
# it will override what happens to be installed in /usr/(local/)lib/python...
22
 
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
23
 
                                   os.pardir,
24
 
                                   os.pardir))
25
 
if os.path.exists(os.path.join(possible_topdir, 'keystone', '__init__.py')):
26
 
    sys.path.insert(0, possible_topdir)
27
 
 
28
 
import optparse
29
 
import keystone.db.sqlalchemy.api as db_api
30
 
 
31
 
 
32
 
def main():
33
 
    usage = "usage: %prog username enabled"
34
 
    parser = optparse.OptionParser(usage)
35
 
    options, args = parser.parse_args()
36
 
    if len(args) != 2:
37
 
        parser.error("Incorrect number of arguments")
38
 
    else:
39
 
        username = args[0]
40
 
        enabled = args[1].capitalize().strip()
41
 
 
42
 
        if enabled == 'True' or enabled == '1':
43
 
            enabled = 1
44
 
        elif enabled == 'False' or enabled == '0':
45
 
            enabled = 0
46
 
        else:
47
 
            parser.error("Incorrect arguments value")
48
 
 
49
 
        try:
50
 
            u = db_api.user_get(username)
51
 
            if u == None:
52
 
                raise IndexError("User not found")
53
 
            else:
54
 
                values = {'enabled': enabled}
55
 
                db_api.user_update(username, values)
56
 
            print 'User', u.id, 'updated. Enabled =', enabled
57
 
        except Exception, e:
58
 
            print 'Error updating user', username, ':', str(e)
59
 
 
60
 
if __name__ == '__main__':
61
 
    main()