Merge pull request #839 from BuhtigithuB/pep8fileutils-py
PEP8 fileutils py
This commit is contained in:
+5
-5
@@ -56,13 +56,13 @@ debugger = pdb.Pdb(completekey=None, stdin=pipe_in, stdout=pipe_out,)
|
||||
|
||||
|
||||
def set_trace():
|
||||
"breakpoint shortcut (like pdb)"
|
||||
"""breakpoint shortcut (like pdb)"""
|
||||
logger.info("DEBUG: set_trace!")
|
||||
debugger.set_trace(sys._getframe().f_back)
|
||||
|
||||
|
||||
def stop_trace():
|
||||
"stop waiting for the debugger (called atexit)"
|
||||
"""stop waiting for the debugger (called atexit)"""
|
||||
# this should prevent communicate is wait forever a command result
|
||||
# and the main thread has finished
|
||||
logger.info("DEBUG: stop_trace!")
|
||||
@@ -72,7 +72,7 @@ def stop_trace():
|
||||
|
||||
|
||||
def communicate(command=None):
|
||||
"send command to debbuger, wait result"
|
||||
"""send command to debbuger, wait result"""
|
||||
if command is not None:
|
||||
logger.info("DEBUG: sending command %s" % command)
|
||||
pipe_in.write(command)
|
||||
@@ -97,7 +97,7 @@ run_lock = RLock()
|
||||
|
||||
|
||||
def check_interaction(fn):
|
||||
"Decorator to clean and prevent interaction when not available"
|
||||
"""Decorator to clean and prevent interaction when not available"""
|
||||
def check_fn(self, *args, **kwargs):
|
||||
interact_lock.acquire()
|
||||
try:
|
||||
@@ -110,7 +110,7 @@ def check_interaction(fn):
|
||||
|
||||
|
||||
class WebDebugger(qdb.Frontend):
|
||||
"Qdb web2py interface"
|
||||
"""Qdb web2py interface"""
|
||||
|
||||
def __init__(self, pipe, completekey='tab', stdin=None, stdout=None):
|
||||
qdb.Frontend.__init__(self, pipe)
|
||||
|
||||
+19
-13
@@ -65,9 +65,10 @@ def parse_semantic(version="Version 1.99.0-rc.1+timestamp.2011.09.19.08.23.26"):
|
||||
pre_release = m.group('pre') or ''
|
||||
build = m.group('build') or ''
|
||||
if build.startswith('timestamp'):
|
||||
build = datetime.datetime.strptime(build.split('.',1)[1], '%Y.%m.%d.%H.%M.%S')
|
||||
build = datetime.datetime.strptime(build.split('.', 1)[1], '%Y.%m.%d.%H.%M.%S')
|
||||
return (a, b, c, pre_release, build)
|
||||
|
||||
|
||||
def parse_legacy(version="Version 1.99.0 (2011-09-19 08:23:26)"):
|
||||
"""Parses "legacy" version string
|
||||
|
||||
@@ -85,6 +86,7 @@ def parse_legacy(version="Version 1.99.0 (2011-09-19 08:23:26)"):
|
||||
build = datetime.datetime.strptime(m.group('datetime'), '%Y-%m-%d %H:%M:%S')
|
||||
return (a, b, c, pre_release, build)
|
||||
|
||||
|
||||
def parse_version(version):
|
||||
"""Attempts to parse SemVer, fallbacks on legacy
|
||||
"""
|
||||
@@ -93,6 +95,7 @@ def parse_version(version):
|
||||
version_tuple = parse_legacy(version)
|
||||
return version_tuple
|
||||
|
||||
|
||||
def read_file(filename, mode='r'):
|
||||
"""Returns content from filename, making sure to close the file explicitly
|
||||
on exit.
|
||||
@@ -130,14 +133,13 @@ def mktree(path):
|
||||
os.mkdir(head)
|
||||
|
||||
|
||||
def listdir(
|
||||
path,
|
||||
expression='^.+$',
|
||||
drop=True,
|
||||
add_dirs=False,
|
||||
sort=True,
|
||||
maxnum = None,
|
||||
):
|
||||
def listdir(path,
|
||||
expression='^.+$',
|
||||
drop=True,
|
||||
add_dirs=False,
|
||||
sort=True,
|
||||
maxnum=None,
|
||||
):
|
||||
"""
|
||||
Like `os.listdir()` but you can specify a regex pattern to filter files.
|
||||
If `add_dirs` is True, the returned items will have the full path.
|
||||
@@ -212,6 +214,7 @@ def tar(file, dir, expression='^.+$', filenames=None):
|
||||
finally:
|
||||
tar.close()
|
||||
|
||||
|
||||
def untar(file, dir):
|
||||
"""Untar file into dir
|
||||
"""
|
||||
@@ -242,6 +245,7 @@ def w2p_pack(filename, path, compiled=False, filenames=None):
|
||||
tarfp.close()
|
||||
os.unlink(tarname)
|
||||
|
||||
|
||||
def create_welcome_w2p():
|
||||
if not os.path.exists('welcome.w2p') or os.path.exists('NEWINSTALL'):
|
||||
try:
|
||||
@@ -254,7 +258,7 @@ def create_welcome_w2p():
|
||||
|
||||
def w2p_unpack(filename, path, delete_tar=True):
|
||||
|
||||
if filename=='welcome.w2p':
|
||||
if filename == 'welcome.w2p':
|
||||
create_welcome_w2p()
|
||||
filename = abspath(filename)
|
||||
path = abspath(path)
|
||||
@@ -352,6 +356,7 @@ def get_session(request, other_application='admin'):
|
||||
osession = storage.Storage()
|
||||
return osession
|
||||
|
||||
|
||||
def set_session(request, session, other_application='admin'):
|
||||
"""Checks that user is authorized to access other_application"""
|
||||
if request.application == other_application:
|
||||
@@ -359,7 +364,8 @@ def set_session(request, session, other_application='admin'):
|
||||
session_id = request.cookies['session_id_' + other_application].value
|
||||
session_filename = os.path.join(
|
||||
up(request.folder), other_application, 'sessions', session_id)
|
||||
storage.save_storage(session,session_filename)
|
||||
storage.save_storage(session, session_filename)
|
||||
|
||||
|
||||
def check_credentials(request, other_application='admin',
|
||||
expiration=60 * 60, gae_login=True):
|
||||
@@ -381,7 +387,7 @@ def check_credentials(request, other_application='admin',
|
||||
r = (s.authorized and s.last_time and s.last_time > dt)
|
||||
if r:
|
||||
s.last_time = t0
|
||||
set_session(request,s,other_application)
|
||||
set_session(request, s, other_application)
|
||||
return r
|
||||
|
||||
|
||||
@@ -434,7 +440,7 @@ def make_fake_file_like_object():
|
||||
|
||||
|
||||
from settings import global_settings # we need to import settings here because
|
||||
# settings imports fileutils too
|
||||
# settings imports fileutils too
|
||||
|
||||
|
||||
def abspath(*relpath, **base):
|
||||
|
||||
Reference in New Issue
Block a user