[Cluster-devel] conga/luci/utils luci_admin
rmccabe at sourceware.org
rmccabe at sourceware.org
Thu Aug 3 03:30:04 UTC 2006
CVSROOT: /cvs/cluster
Module name: conga
Changes by: rmccabe at sourceware.org 2006-08-03 03:30:03
Modified files:
luci/utils : luci_admin
Log message:
save misc. member data (other than id and passwd)
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/utils/luci_admin.diff?cvsroot=cluster&r1=1.33&r2=1.34
--- conga/luci/utils/luci_admin 2006/08/02 23:29:27 1.33
+++ conga/luci/utils/luci_admin 2006/08/03 03:30:02 1.34
@@ -88,6 +88,27 @@
except:
return -1
+def restore_luci_fsattr():
+ try:
+ luci = pwd.getpwnam(LUCI_USER)[2:4]
+ if not luci or len(luci) != 2:
+ raise
+ except:
+ sys.stderr.write('Cannot find the \"' + LUCI_USER + '\" user.\n')
+ return -1
+
+ try:
+ os.chown(LUCI_DB_PATH, luci[0], luci[1])
+ os.chmod(LUCI_DB_PATH, 0600)
+ for i in [ '.tmp', '.old', '.index', '.lock' ]:
+ try:
+ os.chown(LUCI_DB_PATH + i, luci[0], luci[1])
+ os.chmod(LUCI_DB_PATH + i, 0600)
+ except: pass
+ except:
+ sys.stderr.write('Unable to change ownership of the Luci database back to user \"' + LUCI_USER + '\"\n')
+ return -1
+
def set_zope_passwd(user, passwd):
sys.stderr = null
import ZODB
@@ -155,30 +176,15 @@
raise
except:
sys.stderr.write('Unable to set the password for user \"' + user + '\"\n')
+
conn.close()
db.pack()
db.close()
fs.close()
- try:
- luci = pwd.getpwnam(LUCI_USER)[2:4]
- if not luci or len(luci) != 2:
- raise
- except:
- sys.stderr.write('Cannot find the \"' + LUCI_USER + '\" user.\n')
+ if restore_luci_fsattr():
return -1
- try:
- os.chown(LUCI_DB_PATH, luci[0], luci[1])
- os.chmod(LUCI_DB_PATH, 0600)
- for i in [ '.tmp', '.old', '.index', '.lock' ]:
- try:
- os.chown(LUCI_DB_PATH + i, luci[0], luci[1])
- os.chmod(LUCI_DB_PATH + i, 0600)
- except: pass
- except:
- sys.stderr.write('Unable to change ownership of the Luci database back to user \"' + LUCI_USER + '\"\n')
- return -1
return ret
@@ -254,9 +260,6 @@
import ImageFile
import Products.PluggableAuthService.plugins.ZODBUserManager
import BTrees.OOBTree
- # Zope wants to open a www/ok.gif and images/error.gif
- # when you initialize the application object. This keeps
- # the AppInitializer(app).initialize() call below from failing.
ImageFile.ImageFile.__init__ = lambda x,y,z:None
sys.stderr = orig_stderr
@@ -612,12 +615,10 @@
import transaction
import Products.CMFCore
import Products.CMFCore.MemberDataTool
+ from CMFPlone.utils import getToolByName
import ImageFile
import Products.PluggableAuthService.plugins.ZODBUserManager
import BTrees.OOBTree
- # Zope wants to open a www/ok.gif and images/error.gif
- # when you initialize the application object. This keeps
- # the AppInitializer(app).initialize() call below from failing.
ImageFile.ImageFile.__init__ = lambda x,y,z:None
sys.stderr = orig_stderr
@@ -662,11 +663,12 @@
sys.stderr.write('An error occurred while initializing the Luci installation for restoration from backup\n')
return -1
+ app.luci.portal_memberdata.pruneMemberDataContents()
+ transaction.commit()
+
try:
acl_users = app.acl_users.users
- portal_mem = app.luci.portal_membership
- portal_reg = app.luci.portal_registration
- if not (acl_users and len(acl_users) and portal_mem and portal_reg):
+ if not (acl_users and len(acl_users)):
raise
except:
sys.stderr.write('Your Luci installation appears to be corrupt.\n')
@@ -705,6 +707,23 @@
sys.stderr.write('An error occurred while saving user information.')
return -1
+ save_member_properties = [ 'login_time', 'last_login_time', 'must_change_password', 'email' ]
+ try:
+ membertool = getToolByName(app.luci, 'portal_membership')
+ if not membertool:
+ raise
+ for mem in membertool.listMembers():
+ try:
+ for i in save_member_properties:
+ prop = mem.getProperty(i)
+ if prop != '':
+ users[mem.id][i] = str(prop)
+ except:
+ continue
+ except:
+ pass
+
+
try:
storagedir = app.luci.systems.storage
clusterdir = app.luci.systems.cluster
@@ -714,7 +733,7 @@
if storagedir and len(storagedir):
for i in storagedir.objectItems():
- systems[i[0]] = { 'id': i[0], 'name': i[0] }
+ systems[i[0]] = { 'id': i[0] }
if hasattr(i[1], 'title'):
systems[i[0]]['title'] = getattr(i[1], 'title')
else:
@@ -742,32 +761,19 @@
clusters[cluster_name]['permList'] = {}
for csystem in i[1].objectItems():
- csystem_hash = { 'id': csystem[0] }
+ csystem_hash = { 'id': csystem[0], 'permList': {} }
if hasattr(csystem[1], 'title'):
csystem_hash['title'] = getattr(csystem[1], 'title')
else:
csystem_hash['title'] = '__luci__:csystem:' + cluster_name
-
- if hasattr(csystem[1], '__ac_local_roles__'):
- roles = getattr(csystem[1], '__ac_local_roles__')
- csystem_hash['permList'] = map(lambda x: x[0], filter(lambda x: len(x) > 1 and 'View' in x[1], roles.items()))
- else:
- csystem_hash['permList'] = {}
clusters[cluster_name]['csystemList'][csystem[0]] = csystem_hash
- sys.stderr = orig_stderr
conn.close()
+ db.pack()
db.close()
fs.close()
- junk = list()
- for i in users:
- if not 'passwd' in users[i]:
- junk.append(i)
- for i in junk:
- del users[i]
-
backup = {
'userList': users,
'systemList': systems,
@@ -809,6 +815,7 @@
return doc
+
def _execWithCaptureErrorStatus(command, argv, searchPath = 0, root = '/', stdin = 0, catchfd = 1, catcherrfd = 2, closefd = -1):
if not os.access (root + command, os.X_OK):
raise RuntimeError, command + " can not be run"
@@ -1009,25 +1016,8 @@
try: os.umask(077)
except: pass
- try:
- luci = pwd.getpwnam(LUCI_USER)[2:4]
- except:
- sys.stderr.write('Cannot find the \"' + LUCI_USER + '\" user.\n')
- sys.exit(1)
-
doc = luci_backup(argv[2:])
-
- try:
- os.chown(LUCI_DB_PATH, luci[0], luci[1])
- os.chmod(LUCI_DB_PATH, 0600)
- for i in [ '.tmp', '.old', '.index', '.lock' ]:
- try:
- os.chown(LUCI_DB_PATH + i, luci[0], luci[1])
- os.chmod(LUCI_DB_PATH + i, 0600)
- except: pass
- except:
- sys.stderr.write('Unable to change ownership of the Luci database back to user \"' + LUCI_USER + '\"\n')
-
+ restore_luci_fsattr()
if not doc:
sys.stderr.write('The Luci backup failed.\n')
sys.exit(1)
@@ -1039,6 +1029,7 @@
stat = os.stat(LUCI_BACKUP_PATH)
trynum = 1
basename = '/luci_backup-'
+
while True:
oldbackup = LUCI_BACKUP_DIR + basename + str(trynum) + '.xml'
if not os.path.exists(oldbackup):
@@ -1046,7 +1037,7 @@
os.rename(LUCI_BACKUP_PATH, oldbackup)
except:
sys.stderr.stderr('Unable to rename the existing backup file.\n')
- return -1
+ sys.stderr.write('The Luci backup failed.\n')
break
trynum += 1
except OSError, e:
@@ -1057,13 +1048,14 @@
f = file(LUCI_BACKUP_PATH, 'wb+')
except:
sys.stderr.write('Unable to open \"' + LUCI_BACKUP_PATH + '\" to write backup.\n')
+ sys.stderr.write('The Luci backup failed.\n')
sys.exit(1)
try:
os.chmod(LUCI_BACKUP_PATH, 0600)
except OSError, e:
- print "An error occurred while making",LUCI_BACKUP_PATH,"read-only:",e
- print "Please check that this file is not world-readable."
+ sys.stderr.write('An error occurred while making \"' + LUCI_BACKUP_PATH + '\" read-only: ' + e + '\n')
+ sys.stderr.write('Please check that this file is not world-readable.\n')
try:
f.write(doc.toprettyxml())
@@ -1081,27 +1073,17 @@
except: pass
if luci_restore(argv[2:]):
- retCode = False
+ ret = False
print 'The Luci restore failed. Try reinstalling Luci, then restoring again.'
else:
- retCode = True
+ ret = True
print 'Restore was successful.'
restart_message()
- try:
- luci = pwd.getpwnam(LUCI_USER)[2:4]
- os.chown(LUCI_DB_PATH, luci[0], luci[1])
- os.chmod(LUCI_DB_PATH, 0600)
- for i in [ '.tmp', '.old', '.index', '.lock' ]:
- try:
- os.chown(LUCI_DB_PATH + i, luci[0], luci[1])
- os.chmod(LUCI_DB_PATH + i, 0600)
- except: pass
- except:
- sys.stderr.write('Unable to change ownership of the Luci database back to user \"' + LUCI_USER + '\"\n')
+ if restore_luci_fsattr():
return False
- return retCode
+ return ret
def luci_help(argv):
@@ -1116,7 +1098,6 @@
print
-
def main(argv):
if len(argv) != 2:
luci_help(argv)
More information about the Cluster-devel
mailing list