Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
e080dab9
Commit
e080dab9
authored
Jul 21, 2016
by
Hanno Schlichting
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
flake8 Zope2/utilities.
parent
4903e67c
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
307 additions
and
198 deletions
+307
-198
src/Zope2/Startup/run.py
src/Zope2/Startup/run.py
+5
-1
src/Zope2/utilities/adduser.py
src/Zope2/utilities/adduser.py
+5
-5
src/Zope2/utilities/copyzopeskel.py
src/Zope2/utilities/copyzopeskel.py
+18
-13
src/Zope2/utilities/finder.py
src/Zope2/utilities/finder.py
+1
-1
src/Zope2/utilities/mkzopeinstance.py
src/Zope2/utilities/mkzopeinstance.py
+31
-21
src/Zope2/utilities/requestprofiler.py
src/Zope2/utilities/requestprofiler.py
+206
-132
src/Zope2/utilities/zpasswd.py
src/Zope2/utilities/zpasswd.py
+41
-25
No files found.
src/Zope2/Startup/run.py
View file @
e080dab9
...
...
@@ -12,6 +12,7 @@
#
##############################################################################
def
run
():
""" Start a Zope instance """
import
Zope2.Startup
...
...
@@ -25,6 +26,7 @@ def run():
raise
starter
.
run
()
def
configure
(
configfile
):
""" Provide an API which allows scripts like zopectl to configure
Zope before attempting to do 'app = Zope2.app(). Should be used as
...
...
@@ -38,6 +40,7 @@ def configure(configfile):
starter
.
dropPrivileges
()
return
starter
def
_setconfig
(
configfile
=
None
):
""" Configure a Zope instance based on ZopeOptions. Optionally
accept a configfile argument (string path) in order to specify
...
...
@@ -56,6 +59,7 @@ def _setconfig(configfile=None):
App
.
config
.
setConfiguration
(
opts
.
configroot
)
return
opts
def
make_wsgi_app
(
global_config
,
zope_conf
):
from
App.config
import
setConfiguration
from
Zope2.Startup
import
get_starter
...
...
@@ -72,6 +76,6 @@ def make_wsgi_app(global_config, zope_conf):
starter
.
prepare
()
return
publish_module
if
__name__
==
'__main__'
:
run
()
src/Zope2/utilities/adduser.py
View file @
e080dab9
...
...
@@ -28,18 +28,18 @@ def main(argv=sys.argv):
try
:
user
,
pwd
=
argv
[
1
],
argv
[
2
]
except
IndexError
:
print
"%s <username> <password>"
%
argv
[
0
]
print
(
"%s <username> <password>"
%
argv
[
0
])
sys
.
exit
(
255
)
finder
=
ZopeFinder
(
argv
)
finder
.
filter_warnings
()
app
=
finder
.
get_app
()
result
=
adduser
(
app
,
user
,
pwd
)
if
result
:
print
"User %s created."
%
user
print
(
"User %s created."
%
user
)
else
:
print
"Got no result back. User creation may have failed."
print
"Maybe the user already exists and nothing is done then."
print
"Or the implementation does not give info when it succeeds."
print
(
"Got no result back. User creation may have failed."
)
print
(
"Maybe the user already exists and nothing is done then."
)
print
(
"Or the implementation does not give info when it succeeds."
)
if
__name__
==
'__main__'
:
main
()
src/Zope2/utilities/copyzopeskel.py
View file @
e080dab9
...
...
@@ -65,18 +65,21 @@ import shutil
import
sys
import
getopt
CVS_DIRS
=
[
os
.
path
.
normcase
(
"CVS"
),
os
.
path
.
normcase
(
".svn"
)]
def
main
():
try
:
opts
,
args
=
getopt
.
getopt
(
sys
.
argv
[
1
:],
opts
,
args
=
getopt
.
getopt
(
sys
.
argv
[
1
:],
"hs:t:u:g:r:"
,
[
"help"
,
"sourcedir="
,
"targetdir="
,
"uid="
,
"gid="
,
"replace="
]
)
except
getopt
.
GetoptError
,
msg
:
)
except
getopt
.
GetoptError
as
msg
:
usage
(
sys
.
stderr
,
msg
)
sys
.
exit
(
2
)
script
=
os
.
path
.
abspath
(
sys
.
argv
[
0
])
sourcedir
=
None
targetdir
=
None
uid
=
None
...
...
@@ -120,7 +123,7 @@ def main():
sys
.
exit
(
2
)
except
(
ImportError
,
AttributeError
):
usage
(
sys
.
stderr
,
"Your system does not support the gid or uid options"
)
"Your system does not support the gid or uid options"
)
sys
.
exit
(
2
)
if
opt
in
(
"-g"
,
"--gid"
):
if
not
arg
:
...
...
@@ -143,7 +146,7 @@ def main():
sys
.
exit
(
2
)
except
(
ImportError
,
AttributeError
):
usage
(
sys
.
stderr
,
"Your system does not support the gid or uid options"
)
"Your system does not support the gid or uid options"
)
sys
.
exit
(
2
)
if
opt
in
(
"-r"
,
"--replace"
):
...
...
@@ -162,6 +165,7 @@ def main():
copyskel
(
sourcedir
,
targetdir
,
uid
,
gid
,
**
replacements
)
def
copyskel
(
sourcedir
,
targetdir
,
uid
,
gid
,
**
replacements
):
""" This is an independent function because we'd like to
import and call it from mkzopeinstance """
...
...
@@ -180,7 +184,7 @@ def copyskel(sourcedir, targetdir, uid, gid, **replacements):
(
targetdir
,
replacements
,
uid
,
gid
))
finally
:
os
.
chdir
(
pwd
)
except
(
IOError
,
OSError
)
,
msg
:
except
(
IOError
,
OSError
)
as
msg
:
print
>>
sys
.
stderr
,
msg
sys
.
exit
(
1
)
...
...
@@ -191,9 +195,8 @@ def copyskel(sourcedir, targetdir, uid, gid, **replacements):
os
.
chmod
(
fullname
,
0700
)
CVS_DIRS
=
[
os
.
path
.
normcase
(
"CVS"
),
os
.
path
.
normcase
(
".svn"
)]
def
copydir
((
targetdir
,
replacements
,
uid
,
gid
),
sourcedir
,
names
):
def
copydir
(
args
,
sourcedir
,
names
):
targetdir
,
replacements
,
uid
,
gid
=
args
# Don't recurse into CVS directories:
for
name
in
names
[:]:
if
os
.
path
.
normcase
(
name
)
in
CVS_DIRS
:
...
...
@@ -227,6 +230,7 @@ def copydir((targetdir, replacements, uid, gid), sourcedir, names):
if
uid
is
not
None
:
os
.
chown
(
dn
,
uid
,
gid
)
def
copyin
(
src
,
dst
,
replacements
,
uid
,
gid
):
ifp
=
open
(
src
)
text
=
ifp
.
read
()
...
...
@@ -240,12 +244,13 @@ def copyin(src, dst, replacements, uid, gid):
if
uid
is
not
None
:
os
.
chown
(
dst
,
uid
,
gid
)
def
usage
(
stream
,
msg
=
None
):
if
msg
:
print
>>
stream
,
msg
print
>>
stream
stream
.
write
(
msg
)
stream
.
write
(
'
\
n
'
)
program
=
os
.
path
.
basename
(
sys
.
argv
[
0
])
print
>>
stream
,
__doc__
%
{
"program"
:
program
}
stream
.
write
(
__doc__
%
{
"program"
:
program
})
if
__name__
==
'__main__'
:
main
()
src/Zope2/utilities/finder.py
View file @
e080dab9
...
...
@@ -14,7 +14,7 @@
import
os
class
ZopeFinder
:
class
ZopeFinder
(
object
)
:
def
__init__
(
self
,
argv
):
self
.
cmd
=
argv
[
0
]
...
...
src/Zope2/utilities/mkzopeinstance.py
View file @
e080dab9
...
...
@@ -31,13 +31,18 @@ import os
import
sys
import
copyzopeskel
if
sys
.
version_info
>
(
3
,
0
):
raw_input
=
input
def
main
():
try
:
opts
,
args
=
getopt
.
getopt
(
sys
.
argv
[
1
:],
opts
,
args
=
getopt
.
getopt
(
sys
.
argv
[
1
:],
"hu:d:s:p:"
,
[
"help"
,
"user="
,
"dir="
,
"skelsrc="
,
"python="
]
)
except
getopt
.
GetoptError
,
msg
:
)
except
getopt
.
GetoptError
as
msg
:
usage
(
sys
.
stderr
,
msg
)
sys
.
exit
(
2
)
...
...
@@ -74,7 +79,7 @@ def main():
if
not
arg
:
usage
(
sys
.
stderr
,
"user must not be empty"
)
sys
.
exit
(
2
)
if
not
":"
in
arg
:
if
":"
not
in
arg
:
usage
(
sys
.
stderr
,
"user must be specified as name:password"
)
sys
.
exit
(
2
)
user
,
password
=
arg
.
split
(
":"
,
1
)
...
...
@@ -85,10 +90,9 @@ def main():
# to skeltarget.
skeltarget
=
instancehome
=
os
.
path
.
abspath
(
os
.
path
.
expanduser
(
get_skeltarget
())
)
)
instancehome
=
skeltarget
configfile
=
os
.
path
.
join
(
instancehome
,
'etc'
,
'zope.conf'
)
if
skelsrc
is
None
:
# default to using stock Zope skeleton source
skelsrc
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
"skel"
)
...
...
@@ -105,14 +109,14 @@ def main():
# need be used.
if
python
is
None
:
python
=
sys
.
executable
psplit
=
os
.
path
.
split
(
python
)
exedir
=
os
.
path
.
join
(
*
psplit
[:
-
1
])
pythonexe
=
os
.
path
.
join
(
exedir
,
'python.exe'
)
pythonwexe
=
os
.
path
.
join
(
exedir
,
'pythonw.exe'
)
if
(
os
.
path
.
isfile
(
pythonwexe
)
and
os
.
path
.
isfile
(
pythonexe
)
and
(
python
in
[
pythonwexe
,
pythonexe
])
):
if
(
os
.
path
.
isfile
(
pythonwexe
)
and
os
.
path
.
isfile
(
pythonexe
)
and
(
python
in
[
pythonwexe
,
pythonexe
])
):
# we're using a Windows build with both python.exe and pythonw.exe
# in the same directory
PYTHON
=
pythonexe
...
...
@@ -124,17 +128,18 @@ def main():
zope2path
=
get_zope2path
(
PYTHON
)
kw
=
{
"PYTHON"
:
PYTHON
,
"PYTHONW"
:
PYTHONW
,
"PYTHON"
:
PYTHON
,
"PYTHONW"
:
PYTHONW
,
"INSTANCE_HOME"
:
instancehome
,
"ZOPE_SCRIPTS"
:
script_path
,
"ZOPE2PATH"
:
zope2path
,
}
}
copyzopeskel
.
copyskel
(
skelsrc
,
skeltarget
,
None
,
None
,
**
kw
)
if
user
and
password
:
write_inituser
(
inituser
,
user
,
password
)
def
usage
(
stream
,
msg
=
None
):
if
msg
:
print
>>
stream
,
msg
...
...
@@ -142,25 +147,27 @@ def usage(stream, msg=None):
program
=
os
.
path
.
basename
(
sys
.
argv
[
0
])
print
>>
stream
,
__doc__
%
{
"program"
:
program
}
def
get_skeltarget
():
print
'Please choose a directory in which you
\
'
d like to install'
print
'Zope "instance home" files such as database files, configuration'
print
'files, etc.'
print
(
'Please choose a directory in which you
\
'
d like to install'
)
print
(
'Zope "instance home" files such as database files, configuration'
)
print
(
'files, etc.'
)
print
while
1
:
skeltarget
=
raw_input
(
"Directory: "
).
strip
()
if
skeltarget
==
''
:
print
'You must specify a directory'
print
(
'You must specify a directory'
)
continue
else
:
break
return
skeltarget
def
get_inituser
():
import
getpass
print
'Please choose a username and password for the initial user.'
print
'These will be the credentials you use to initially manage'
print
'your new Zope instance.'
print
(
'Please choose a username and password for the initial user.'
)
print
(
'These will be the credentials you use to initially manage'
)
print
(
'your new Zope instance.'
)
print
user
=
raw_input
(
"Username: "
).
strip
()
if
user
==
''
:
...
...
@@ -172,9 +179,10 @@ def get_inituser():
break
else
:
passwd
=
verify
=
''
print
"Password mismatch, please try again..."
print
(
"Password mismatch, please try again..."
)
return
user
,
passwd
def
write_inituser
(
fn
,
user
,
password
):
import
binascii
try
:
...
...
@@ -185,7 +193,8 @@ def write_inituser(fn, user, password):
pw
=
binascii
.
b2a_base64
(
sha
(
password
).
digest
())[:
-
1
]
fp
.
write
(
'%s:{SHA}%s
\
n
'
%
(
user
,
pw
))
fp
.
close
()
os
.
chmod
(
fn
,
0644
)
os
.
chmod
(
fn
,
0o644
)
def
check_buildout
(
script_path
):
""" Are we running from within a buildout which supplies 'zopepy'?
...
...
@@ -197,6 +206,7 @@ def check_buildout(script_path):
parser
.
read
(
buildout_cfg
)
return
'zopepy'
in
parser
.
sections
()
def
get_zope2path
(
python
):
""" Get Zope2 path from selected Python interpreter.
"""
...
...
src/Zope2/utilities/requestprofiler.py
View file @
e080dab9
This diff is collapsed.
Click to expand it.
src/Zope2/utilities/zpasswd.py
View file @
e080dab9
...
...
@@ -37,13 +37,22 @@ for all necessary information. The available options are:
Filename is required and should be the name of the file to store the
information in (usually "inituser" or "access").
"""
import
sys
,
sha
,
binascii
,
random
,
getopt
,
getpass
,
os
import
binascii
import
getopt
import
getpass
import
os
import
random
import
sha
import
sys
try
:
from
crypt
import
crypt
except
ImportError
:
crypt
=
None
if
sys
.
version_info
>
(
3
,
0
):
raw_input
=
input
PROGRAM
=
sys
.
argv
[
0
]
COMMASPACE
=
', '
...
...
@@ -53,10 +62,11 @@ def generate_salt():
salt_choices
=
(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789./"
)
return
random
.
choice
(
salt_choices
)
+
random
.
choice
(
salt_choices
)
return
random
.
choice
(
salt_choices
)
+
random
.
choice
(
salt_choices
)
def
generate_passwd
(
password
,
encoding
):
encoding
=
encoding
.
upper
()
encoding
=
encoding
.
upper
()
if
encoding
==
'SHA'
:
pw
=
'{SHA}'
+
binascii
.
b2a_base64
(
sha
.
new
(
password
).
digest
())[:
-
1
]
elif
encoding
==
'CRYPT'
:
...
...
@@ -68,26 +78,28 @@ def generate_passwd(password, encoding):
return
pw
def
write_generated_password
(
home
,
ac_path
,
username
):
pw_choices
=
(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789!"
)
acfile
=
open
(
ac_path
,
'w'
)
acfile
=
open
(
ac_path
,
'w'
)
pw
=
''
for
i
in
range
(
8
):
pw
=
pw
+
random
.
choice
(
pw_choices
)
acfile
.
write
(
'%s:%s
\
n
'
%
(
username
,
generate_passwd
(
pw
,
'SHA'
)))
acfile
.
close
()
os
.
chmod
(
ac_path
,
0644
)
os
.
chmod
(
ac_path
,
0
o
644
)
return
pw
def
write_access
(
home
,
user
=
''
,
group
=
''
):
ac_path
=
os
.
path
.
join
(
home
,
'access'
)
ac_path
=
os
.
path
.
join
(
home
,
'access'
)
if
not
os
.
path
.
exists
(
ac_path
):
print
'-'
*
78
print
'creating default access file'
print
(
'-'
*
78
)
print
(
'creating default access file'
)
pw
=
write_generated_password
(
home
,
ac_path
,
'emergency'
)
print
"""Note:
print
(
"""Note:
The emergency user name and password are 'emergency'
and '%s'.
...
...
@@ -95,9 +107,11 @@ def write_access(home, user='', group=''):
zpasswd script. To find out more, type:
%s zpasswd.py
"""
%
(
pw
,
sys
.
executable
)
"""
%
(
pw
,
sys
.
executable
))
import
do
do
.
ch
(
ac_path
,
user
,
group
)
import
do
;
do
.
ch
(
ac_path
,
user
,
group
)
def
get_password
():
while
1
:
...
...
@@ -107,29 +121,31 @@ def get_password():
return
password
else
:
password
=
verify
=
''
print
"Password mismatch, please try again..."
print
(
"Password mismatch, please try again..."
)
def
write_inituser
(
home
,
user
=
''
,
group
=
''
):
ac_path
=
os
.
path
.
join
(
home
,
'inituser'
)
ac_path
=
os
.
path
.
join
(
home
,
'inituser'
)
if
not
os
.
path
.
exists
(
ac_path
):
print
'-'
*
78
print
'creating default inituser file'
print
(
'-'
*
78
)
print
(
'creating default inituser file'
)
pw
=
write_generated_password
(
home
,
ac_path
,
'admin'
)
print
"""Note:
print
(
"""Note:
The initial user name and password are 'admin'
and '%s'.
You can change the name and password through the web
interface or using the 'zpasswd.py' script.
"""
%
pw
"""
%
pw
)
import
do
;
do
.
ch
(
ac_path
,
user
,
group
)
import
do
do
.
ch
(
ac_path
,
user
,
group
)
def
usage
(
code
,
msg
=
''
):
print
>>
sys
.
stderr
,
__doc__
%
globals
(
)
sys
.
stderr
.
write
(
__doc__
%
globals
()
)
if
msg
:
print
>>
sys
.
stderr
,
msg
sys
.
stderr
.
write
(
msg
)
sys
.
exit
(
code
)
...
...
@@ -143,7 +159,7 @@ def main():
try
:
opts
,
args
=
getopt
.
getopt
(
sys
.
argv
[
1
:],
shortopts
,
longopts
)
except
getopt
.
error
,
msg
:
except
getopt
.
error
as
msg
:
usage
(
1
,
msg
)
# Defaults
...
...
@@ -183,15 +199,15 @@ def main():
break
password
=
get_password
()
while
1
:
print
"""
print
(
"""
Please choose a format from:
SHA - SHA-1 hashed password (default)
CRYPT - UNIX-style crypt password
CLEARTEXT - no protection
"""
"""
)
encoding
=
raw_input
(
"Encoding: "
)
if
encoding
==
''
:
encoding
=
'SHA'
...
...
@@ -210,5 +226,5 @@ CLEARTEXT - no protection
# If called from the command line
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment