Commit 6d8066d5 authored by Tres Seaver's avatar Tres Seaver

PEP 8.

parent 7efbdc00
......@@ -42,19 +42,22 @@ from zExceptions import Redirect
LOG = getLogger('ApplicationManager')
try: import thread
except: get_ident=lambda: 0
else: get_ident=thread.get_ident
try:
from thread import get_ident
except ImportError:
def get_ident():
return 0
class DatabaseManager(Item, Implicit):
"""Database management (legacy) """
"""Database management (legacy)
"""
manage = manage_main = DTMLFile('dtml/dbMain', globals())
manage_main._setName('manage_main')
id ='DatabaseManagement'
name=title='Database Management'
meta_type ='Database Management'
icon='p_/DatabaseManagement_icon'
id = 'DatabaseManagement'
name = title = 'Database Management'
meta_type = 'Database Management'
icon = 'p_/DatabaseManagement_icon'
manage_options=(
(
......@@ -89,7 +92,7 @@ class FakeConnection:
class DatabaseChooser(SimpleItem):
"""Lets you choose which database to view
""" Choose which database to view
"""
meta_type = 'Database Management'
name = title = 'Database Management'
......@@ -140,17 +143,18 @@ InitializeClass(DatabaseChooser)
# refcount snapshot info
_v_rcs=None
_v_rst=None
_v_rcs = None
_v_rst = None
class DebugManager(Item, Implicit):
"""Debug and profiling information"""
manage=manage_main = DTMLFile('dtml/debug', globals())
""" Debug and profiling information
"""
manage = manage_main = DTMLFile('dtml/debug', globals())
manage_main._setName('manage_main')
id ='DebugInfo'
name=title='Debug Information'
name = title = 'Debug Information'
meta_type = name
icon='p_/DebugManager_icon'
icon = 'p_/DebugManager_icon'
manage_options=(
( {'label':'Debugging Info', 'action':'manage_main',
......@@ -164,37 +168,36 @@ class DebugManager(Item, Implicit):
def refcount(self, n=None, t=(type(Implicit), )):
# return class reference info
dict={}
counts = {}
for m in sys.modules.values():
for sym in dir(m):
ob=getattr(m, sym)
ob = getattr(m, sym)
if type(ob) in t:
dict[ob]=sys.getrefcount(ob)
pairs=[]
append=pairs.append
for ob, v in dict.items():
counts[ob] = sys.getrefcount(ob)
pairs = []
for ob, v in counts.items():
if hasattr(ob, '__module__'):
name='%s.%s' % (ob.__module__, ob.__name__)
else: name='%s' % ob.__name__
append((v, name))
name = '%s.%s' % (ob.__module__, ob.__name__)
else:
name = '%s' % ob.__name__
pairs.append((v, name))
pairs.sort()
pairs.reverse()
if n is not None:
pairs=pairs[:n]
pairs = pairs[:n]
return pairs
def refdict(self):
rc=self.refcount()
dict={}
for v, n in rc:
dict[n]=v
return dict
counts = {}
for v, n in self.refcount():
counts[n] = v
return counts
def rcsnapshot(self):
global _v_rcs
global _v_rst
_v_rcs=self.refdict()
_v_rst=DateTime()
_v_rcs = self.refdict()
_v_rst = DateTime()
def rcdate(self):
return _v_rst
......@@ -202,21 +205,23 @@ class DebugManager(Item, Implicit):
def rcdeltas(self):
if _v_rcs is None:
self.rcsnapshot()
nc=self.refdict()
rc=_v_rcs
rd=[]
nc = self.refdict()
rc = _v_rcs
rd = []
for n, c in nc.items():
try:
prev=rc[n]
prev = rc[n]
if c > prev:
rd.append( (c - prev, (c, prev, n)) )
except: pass
rd.append((c - prev, (c, prev, n)))
except:
pass
rd.sort()
rd.reverse()
return map(lambda n: {'name': n[1][2],
return [{'name': n[1][2],
'delta': n[0],
'pc': n[1][1],
'rc': n[1][0]}, rd)
'rc': n[1][0],
} for n in rd]
def dbconnections(self):
import Globals # for data
......@@ -227,21 +232,24 @@ class DebugManager(Item, Implicit):
manage_profile = DTMLFile('dtml/profile', globals())
def manage_profile_stats(self, sort='time', limit=200, stripDirs=1, mode='stats'):
"""Return profile data if available"""
stats=getattr(sys, '_ps_', None)
def manage_profile_stats(self, sort='time',
limit=200, stripDirs=1, mode='stats'):
"""Return profile data if available
"""
stats = getattr(sys, '_ps_', None)
if stats is None:
return None
output=StringIO()
stdout=sys.stdout
output = StringIO()
stdout = sys.stdout
if stripDirs:
from copy import copy; stats= copy(stats)
from copy import copy
stats = copy(stats)
stats.strip_dirs()
stats.sort_stats(sort)
sys.stdout=output
sys.stdout = output
getattr(stats,'print_%s' % mode)(limit)
sys.stdout.flush()
sys.stdout=stdout
sys.stdout = stdout
return output.getvalue()
def manage_getSysPath(self):
......@@ -253,26 +261,17 @@ InitializeClass(DebugManager)
class ApplicationManager(Folder,CacheManager):
"""System management"""
__roles__=('Manager',)
isPrincipiaFolderish=1
Database= DatabaseChooser('Database') #DatabaseManager()
DebugInfo=DebugManager()
"""System management
"""
__roles__ = ('Manager',)
isPrincipiaFolderish = 1
Database = DatabaseChooser('Database') #DatabaseManager()
DebugInfo = DebugManager()
DavLocks = DavLockManager()
manage=manage_main = DTMLFile('dtml/cpContents', globals())
manage = manage_main = DTMLFile('dtml/cpContents', globals())
manage_main._setName('manage_main')
def version_txt(self):
if not hasattr(self, '_v_version_txt'):
self._v_version_txt=version_txt()
return self._v_version_txt
def sys_version(self): return sys.version
def sys_platform(self): return sys.platform
_objects=(
{'id': 'Database',
'meta_type': Database.meta_type},
......@@ -290,23 +289,23 @@ class ApplicationManager(Folder,CacheManager):
) + UndoSupport.manage_options
)
id ='Control_Panel'
name=title='Control Panel'
meta_type ='Control Panel'
icon='p_/ControlPanel_icon'
id = 'Control_Panel'
name = title = 'Control Panel'
meta_type = 'Control Panel'
icon = 'p_/ControlPanel_icon'
process_id=os.getpid()
process_start=int(time.time())
process_id = os.getpid()
process_start = int(time.time())
# Disable some inappropriate operations
manage_addObject=None
manage_delObjects=None
manage_addProperty=None
manage_editProperties=None
manage_delProperties=None
manage_addObject = None
manage_delObjects = None
manage_addProperty = None
manage_editProperties = None
manage_delProperties = None
def __init__(self):
self.Products=ProductFolder()
self.Products = ProductFolder()
def _canCopy(self, op=0):
return 0
......@@ -314,6 +313,18 @@ class ApplicationManager(Folder,CacheManager):
def _init(self):
pass
def version_txt(self):
if not hasattr(self, '_v_version_txt'):
self._v_version_txt = version_txt()
return self._v_version_txt
def sys_version(self):
return sys.version
def sys_platform(self):
return sys.platform
def manage_app(self, URL2):
"""Return to the main management screen"""
raise Redirect, URL2+'/manage'
......@@ -321,37 +332,40 @@ class ApplicationManager(Folder,CacheManager):
def process_time(self, _when=None):
if _when is None:
_when = time.time()
s=int(_when)-self.process_start
d=int(s/86400)
s=s-(d*86400)
h=int(s/3600)
s=s-(h*3600)
m=int(s/60)
s=s-(m*60)
d=d and ('%d day%s' % (d, (d != 1 and 's' or ''))) or ''
h=h and ('%d hour%s' % (h, (h != 1 and 's' or ''))) or ''
m=m and ('%d min' % m) or ''
s='%d sec' % s
s = int(_when) - self.process_start
d = int(s / 86400)
s = s - (d * 86400)
h = int(s / 3600)
s = s -(h * 3600)
m = int(s / 60)
s = s - (m * 60)
d = d and ('%d day%s' % (d, (d != 1 and 's' or ''))) or ''
h = h and ('%d hour%s' % (h, (h != 1 and 's' or ''))) or ''
m = m and ('%d min' % m) or ''
s = '%d sec' % s
return '%s %s %s %s' % (d, h, m, s)
def thread_get_ident(self): return get_ident()
def thread_get_ident(self):
return get_ident()
def db_name(self):
return self._p_jar.db().getName()
def db_size(self):
s=self._p_jar.db().getSize()
s = self._p_jar.db().getSize()
if type(s) is type(''):
return s
if s >= 1048576.0: return '%.1fM' % (s/1048576.0)
if s >= 1048576.0:
return '%.1fM' % (s/1048576.0)
return '%.1fK' % (s/1024.0)
if os.environ.has_key('ZMANAGED'):
manage_restartable=1
manage_restartable = 1
@requestmethod('POST')
def manage_restart(self, URL1, REQUEST=None):
"""Shut down the application"""
""" Shut down the application for restart.
"""
try:
user = '"%s"' % getSecurityManager().getUser().getUserName()
except:
......@@ -386,41 +400,38 @@ class ApplicationManager(Folder,CacheManager):
if _when is None:
_when = time.time()
t = _when - (days*86400)
t = _when - (days * 86400)
db=self._p_jar.db()
t=db.pack(t)
db = self._p_jar.db()
t = db.pack(t)
if REQUEST is not None:
REQUEST['RESPONSE'].redirect(
REQUEST['URL1']+'/manage_workspace')
REQUEST['URL1'] + '/manage_workspace')
return t
def revert_points(self): return ()
def revert_points(self):
return ()
def version_list(self):
# Return a list of currently installed products/versions
path_join=os.path.join
isdir=os.path.isdir
exists=os.path.exists
cfg = getConfiguration()
product_dir=path_join(cfg.softwarehome,'Products')
product_names=os.listdir(product_dir)
product_dir = os.path.join(cfg.softwarehome,'Products')
product_names = os.listdir(product_dir)
product_names.sort()
info=[]
info = []
for product_name in product_names:
package_dir=path_join(product_dir, product_name)
if not isdir(package_dir):
package_dir = os.path.join(product_dir, product_name)
if not os.path.isdir(package_dir):
continue
version_txt = None
for name in ('VERSION.TXT', 'VERSION.txt', 'version.txt'):
v = path_join(package_dir, name)
if exists(v):
v = os.path.join(package_dir, name)
if os.path.exists(v):
version_txt = v
break
if version_txt is not None:
file=open(version_txt, 'r')
data=file.readline()
file = open(version_txt, 'r')
data = file.readline()
file.close()
info.append(data.strip())
return info
......@@ -460,19 +471,19 @@ class ApplicationManager(Folder,CacheManager):
introduced in 2.4.
"""
meta_types = map(lambda x: x.get('meta_type',None) , self._objects)
meta_types = map(lambda x: x.get('meta_type', None), self._objects)
if not self.DavLocks.meta_type in meta_types:
lst = list(self._objects)
lst.append( {'id': 'DavLocks', \
lst.append({'id': 'DavLocks',
'meta_type': self.DavLocks.meta_type})
self._objects = tuple(lst)
return Folder.objectIds(self, spec)
class AltDatabaseManager(DatabaseManager, CacheManager):
"""Database management DBTab-style
""" Database management DBTab-style
"""
db_name = ApplicationManager.db_name.im_func
db_size = ApplicationManager.db_size.im_func
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment