Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
webcache
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
webcache
Commits
c6c47384
Commit
c6c47384
authored
Feb 11, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Configured folders now should end with a slash (/).
parent
cb869fa4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
19 deletions
+39
-19
cache.py
cache.py
+23
-11
importer.py
importer.py
+16
-8
No files found.
cache.py
View file @
c6c47384
...
...
@@ -8,7 +8,7 @@ from hashlib import md5
from
copy
import
copy
ADMINISTRATION_FILE
=
'administration.p
y
'
ADMINISTRATION_FILE
=
'administration.p
ickle
'
def
to_dir
(
path
):
...
...
@@ -34,7 +34,7 @@ class Cache:
a concatenation of the file list.
"""
def
__init__
(
self
,
root
=
''
,
files
=
[],
cached
=
'cached'
,
def
__init__
(
self
,
root
=
''
,
files
=
[],
cached
=
'cached
/
'
,
expires
=
{
'days'
:
365
}):
"""
The constructor takes the following arguments (all are optional):
...
...
@@ -45,19 +45,24 @@ class Cache:
4. A dictionary containing arguments to the timedelta constructor, that
indicates how long the cache object sould live.
"""
self
.
root
=
to_dir
(
root
+
'/'
)
self
.
cached
=
to_dir
(
cached
+
'/'
)
self
.
files
=
map
(
lambda
f
:
self
.
root
+
f
,
files
)
self
.
root
=
to_dir
(
root
)
self
.
cached
=
to_dir
(
cached
)
self
.
files
=
[]
self
.
expires
=
expires
for
f
in
files
:
self
.
add
(
f
)
web
.
debug
(
str
(
self
))
self
.
assert_files_exist
()
def
assert_files_exist
(
self
):
map
(
assert_file_exists
,
self
.
files
)
def
__str__
(
self
):
return
'<Cache filename=%s files=[%s]>'
\
%
(
self
.
filename
(),
','
.
join
(
self
.
files
))
return
'<Cache
root=%s
filename=%s files=[%s]>'
\
%
(
self
.
root
,
self
.
filename
(),
','
.
join
(
self
.
files
))
def
add
(
self
,
path
,
absolute
=
False
):
"""
...
...
@@ -68,6 +73,7 @@ class Cache:
if
not
absolute
:
path
=
self
.
root
+
path
web
.
debug
(
'Adding file "%s"...'
%
path
)
assert_file_exists
(
path
)
self
.
files
.
append
(
path
)
...
...
@@ -169,7 +175,8 @@ class Cache:
admin
=
self
.
load_administration
()
if
not
exists
(
path
):
web
.
debug
(
'Cached file "%s" does not exist yet, generating it...'
)
web
.
debug
(
'Cached file "%s" does not exist yet, generating it...'
\
%
path
)
server_modified
=
True
else
:
server_modified
=
False
...
...
@@ -191,14 +198,19 @@ class Cache:
f
.
close
()
try
:
web
.
http
.
modified
(
seconds_to_datetime
(
last_modified
),
self
.
etag
())
web
.
http
.
expires
(
timedelta
(
**
self
.
expires
))
# Set headers
web
.
header
(
'Cache-Control'
,
'private'
)
if
not
server_modified
:
web
.
http
.
modified
(
seconds_to_datetime
(
last_modified
),
self
.
etag
())
web
.
http
.
expires
(
timedelta
(
**
self
.
expires
))
if
not
server_modified
:
# Concatenated content has not been loaded yet, read the cached
# file
web
.
debug
(
'Cached file "%s" already exists
, sending content...'
)
web
.
debug
(
'Cached file "%s" already exists
...'
%
path
)
f
=
open
(
path
,
'r'
)
content
=
f
.
read
()
f
.
close
()
...
...
importer.py
View file @
c6c47384
...
...
@@ -5,7 +5,7 @@ import os.path
from
cache
import
Cache
,
to_dir
,
assert_file_exists
ALIAS_PREFIX
=
'
@
'
ALIAS_PREFIX
=
'
.
'
def
separate_imports
(
content
):
...
...
@@ -37,8 +37,9 @@ def separate_imports(content):
content
=
content
.
lstrip
()
imports
=
[]
filename
=
'[a-zA-Z0-9
\
._-]+
'
comma = re.compile('
*
,
*
(
?
:
\\\\\
r
?
\
n
*
)
?
')
file_list
=
'
\
w+(?:%s
\
w+?)*'
%
comma
.
pattern
file_list = '
%
s
(
?
:
%
s
%
s
?
)
*
' % (filename, comma.pattern, filename)
m = re.match('
^
import
(
%
s
)(
?
:(
?
:
\
r
?
\
n
)
+
(.
*
))
?$
' % file_list, content, re.M)
if m:
...
...
@@ -52,9 +53,9 @@ def separate_imports(content):
class Importer(Cache):
def
__init__
(
self
,
root
,
extension
=
None
):
Cache
.
__init__
(
self
)
self
.
root
=
to_dir
(
root
+
'/'
)
def __init__(self,
files=[], extension=None, **kwargs
):
Cache.__init__(self
, **kwargs
)
self.aliases = {}
if extension:
...
...
@@ -62,7 +63,14 @@ class Importer(Cache):
else:
self.extension = ''
def
set_alias
(
self
,
name
,
path
):
for f in files:
self.add(f)
def add(self, path):
path = self.create_full_paths([path])[0]
Cache.add(self, path, absolute=True)
def set_alias(self, alias, path):
"""
Add an alias for the path to a file, relative to the importer'
s
root
directory
.
Aliases
are
used
to
shorten
the
names
of
imports
.
E
.
g
.
using
...
...
@@ -70,7 +78,8 @@ class Importer(Cache):
"""
path = self.root + path + self.extension
assert_file_exists(path)
self
.
aliases
[
name
]
=
path
self.aliases[alias] = path
web.debug('Added alias "%s" for path "%s".' % (alias, path))
def create_full_paths(self, files, relative_file=None):
"""
...
...
@@ -112,7 +121,6 @@ class Importer(Cache):
return replaced
def concatenate(self, files):
files
=
self
.
create_full_paths
(
files
)
map(assert_file_exists, files)
self.loaded = []
self.import_map = {}
...
...
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