Improve PEP8 gluon/fileutils.py
This commit is contained in:
+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 ''
|
pre_release = m.group('pre') or ''
|
||||||
build = m.group('build') or ''
|
build = m.group('build') or ''
|
||||||
if build.startswith('timestamp'):
|
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)
|
return (a, b, c, pre_release, build)
|
||||||
|
|
||||||
|
|
||||||
def parse_legacy(version="Version 1.99.0 (2011-09-19 08:23:26)"):
|
def parse_legacy(version="Version 1.99.0 (2011-09-19 08:23:26)"):
|
||||||
"""Parses "legacy" version string
|
"""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')
|
build = datetime.datetime.strptime(m.group('datetime'), '%Y-%m-%d %H:%M:%S')
|
||||||
return (a, b, c, pre_release, build)
|
return (a, b, c, pre_release, build)
|
||||||
|
|
||||||
|
|
||||||
def parse_version(version):
|
def parse_version(version):
|
||||||
"""Attempts to parse SemVer, fallbacks on legacy
|
"""Attempts to parse SemVer, fallbacks on legacy
|
||||||
"""
|
"""
|
||||||
@@ -93,6 +95,7 @@ def parse_version(version):
|
|||||||
version_tuple = parse_legacy(version)
|
version_tuple = parse_legacy(version)
|
||||||
return version_tuple
|
return version_tuple
|
||||||
|
|
||||||
|
|
||||||
def read_file(filename, mode='r'):
|
def read_file(filename, mode='r'):
|
||||||
"""Returns content from filename, making sure to close the file explicitly
|
"""Returns content from filename, making sure to close the file explicitly
|
||||||
on exit.
|
on exit.
|
||||||
@@ -130,14 +133,13 @@ def mktree(path):
|
|||||||
os.mkdir(head)
|
os.mkdir(head)
|
||||||
|
|
||||||
|
|
||||||
def listdir(
|
def listdir(path,
|
||||||
path,
|
expression='^.+$',
|
||||||
expression='^.+$',
|
drop=True,
|
||||||
drop=True,
|
add_dirs=False,
|
||||||
add_dirs=False,
|
sort=True,
|
||||||
sort=True,
|
maxnum=None,
|
||||||
maxnum = None,
|
):
|
||||||
):
|
|
||||||
"""
|
"""
|
||||||
Like `os.listdir()` but you can specify a regex pattern to filter files.
|
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.
|
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:
|
finally:
|
||||||
tar.close()
|
tar.close()
|
||||||
|
|
||||||
|
|
||||||
def untar(file, dir):
|
def untar(file, dir):
|
||||||
"""Untar file into dir
|
"""Untar file into dir
|
||||||
"""
|
"""
|
||||||
@@ -242,6 +245,7 @@ def w2p_pack(filename, path, compiled=False, filenames=None):
|
|||||||
tarfp.close()
|
tarfp.close()
|
||||||
os.unlink(tarname)
|
os.unlink(tarname)
|
||||||
|
|
||||||
|
|
||||||
def create_welcome_w2p():
|
def create_welcome_w2p():
|
||||||
if not os.path.exists('welcome.w2p') or os.path.exists('NEWINSTALL'):
|
if not os.path.exists('welcome.w2p') or os.path.exists('NEWINSTALL'):
|
||||||
try:
|
try:
|
||||||
@@ -254,7 +258,7 @@ def create_welcome_w2p():
|
|||||||
|
|
||||||
def w2p_unpack(filename, path, delete_tar=True):
|
def w2p_unpack(filename, path, delete_tar=True):
|
||||||
|
|
||||||
if filename=='welcome.w2p':
|
if filename == 'welcome.w2p':
|
||||||
create_welcome_w2p()
|
create_welcome_w2p()
|
||||||
filename = abspath(filename)
|
filename = abspath(filename)
|
||||||
path = abspath(path)
|
path = abspath(path)
|
||||||
@@ -352,6 +356,7 @@ def get_session(request, other_application='admin'):
|
|||||||
osession = storage.Storage()
|
osession = storage.Storage()
|
||||||
return osession
|
return osession
|
||||||
|
|
||||||
|
|
||||||
def set_session(request, session, other_application='admin'):
|
def set_session(request, session, other_application='admin'):
|
||||||
"""Checks that user is authorized to access other_application"""
|
"""Checks that user is authorized to access other_application"""
|
||||||
if request.application == 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_id = request.cookies['session_id_' + other_application].value
|
||||||
session_filename = os.path.join(
|
session_filename = os.path.join(
|
||||||
up(request.folder), other_application, 'sessions', session_id)
|
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',
|
def check_credentials(request, other_application='admin',
|
||||||
expiration=60 * 60, gae_login=True):
|
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)
|
r = (s.authorized and s.last_time and s.last_time > dt)
|
||||||
if r:
|
if r:
|
||||||
s.last_time = t0
|
s.last_time = t0
|
||||||
set_session(request,s,other_application)
|
set_session(request, s, other_application)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
@@ -434,7 +440,7 @@ def make_fake_file_like_object():
|
|||||||
|
|
||||||
|
|
||||||
from settings import global_settings # we need to import settings here because
|
from settings import global_settings # we need to import settings here because
|
||||||
# settings imports fileutils too
|
# settings imports fileutils too
|
||||||
|
|
||||||
|
|
||||||
def abspath(*relpath, **base):
|
def abspath(*relpath, **base):
|
||||||
|
|||||||
Reference in New Issue
Block a user