Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-pipeline
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
django-pipeline
Commits
1ce0fab9
Commit
1ce0fab9
authored
Mar 19, 2009
by
Patrick Altman
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'integration'
parents
5038b5b0
0ee308a2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
20 deletions
+27
-20
compress/conf/settings.py
+3
-0
compress/templatetags/compressed.py
+4
-4
compress/utils.py
+16
-13
compress/versioning/mtime/__init__.py
+4
-3
No files found.
compress/conf/settings.py
View file @
1ce0fab9
...
...
@@ -2,6 +2,9 @@ from django.core.exceptions import ImproperlyConfigured
from
django.conf
import
settings
COMPRESS
=
getattr
(
settings
,
'COMPRESS'
,
not
settings
.
DEBUG
)
COMPRESS_SOURCE
=
getattr
(
settings
,
'COMPRESS_SOURCE'
,
settings
.
MEDIA_ROOT
)
COMPRESS_ROOT
=
getattr
(
settings
,
'COMPRESS_ROOT'
,
settings
.
MEDIA_ROOT
)
COMPRESS_URL
=
getattr
(
settings
,
'COMPRESS_URL'
,
settings
.
MEDIA_URL
)
COMPRESS_AUTO
=
getattr
(
settings
,
'COMPRESS_AUTO'
,
True
)
COMPRESS_VERSION
=
getattr
(
settings
,
'COMPRESS_VERSION'
,
False
)
COMPRESS_VERSION_PLACEHOLDER
=
getattr
(
settings
,
'COMPRESS_VERSION_PLACEHOLDER'
,
'?'
)
...
...
compress/templatetags/compressed.py
View file @
1ce0fab9
...
...
@@ -5,7 +5,7 @@ from django import template
from
django.conf
import
settings
as
django_settings
from
compress.conf
import
settings
from
compress.utils
import
media_root
,
media
_url
,
needs_update
,
filter_css
,
filter_js
,
get_output_filename
,
get_version
,
get_version_from_file
from
compress.utils
import
compress_root
,
compress
_url
,
needs_update
,
filter_css
,
filter_js
,
get_output_filename
,
get_version
,
get_version_from_file
register
=
template
.
Library
()
...
...
@@ -18,7 +18,7 @@ def render_common(template_name, obj, filename, version):
if
filename
.
startswith
(
'http://'
):
context
[
'url'
]
=
filename
else
:
context
[
'url'
]
=
media
_url
(
filename
,
prefix
)
context
[
'url'
]
=
compress
_url
(
filename
,
prefix
)
return
template
.
loader
.
render_to_string
(
template_name
,
context
)
...
...
@@ -51,7 +51,7 @@ class CompressedCSSNode(template.Node):
filter_css
(
css
)
else
:
filename_base
,
filename
=
os
.
path
.
split
(
css
[
'output_filename'
])
path_name
=
media
_root
(
filename_base
)
path_name
=
compress
_root
(
filename_base
)
version
=
get_version_from_file
(
path_name
,
filename
)
return
render_css
(
css
,
css
[
'output_filename'
],
version
)
...
...
@@ -92,7 +92,7 @@ class CompressedJSNode(template.Node):
filter_js
(
js
)
else
:
filename_base
,
filename
=
os
.
path
.
split
(
js
[
'output_filename'
])
path_name
=
media
_root
(
filename_base
)
path_name
=
compress
_root
(
filename_base
)
version
=
get_version_from_file
(
path_name
,
filename
)
return
render_js
(
js
,
js
[
'output_filename'
],
version
)
...
...
compress/utils.py
View file @
1ce0fab9
...
...
@@ -46,7 +46,7 @@ def needs_update(output_file, source_files, verbosity=0):
version
=
get_version
(
source_files
)
on
=
get_output_filename
(
output_file
,
version
)
compressed_file_full
=
media
_root
(
on
)
compressed_file_full
=
compress
_root
(
on
)
if
not
os
.
path
.
exists
(
compressed_file_full
):
return
True
,
version
...
...
@@ -54,16 +54,22 @@ def needs_update(output_file, source_files, verbosity=0):
update_needed
=
getattr
(
get_class
(
settings
.
COMPRESS_VERSIONING
)(),
'needs_update'
)(
output_file
,
source_files
,
version
)
return
update_needed
def
media
_root
(
filename
):
def
compress
_root
(
filename
):
"""
Return the full path to ``filename``. ``filename`` is a relative path name in
MEDIA
_ROOT
Return the full path to ``filename``. ``filename`` is a relative path name in
COMPRESS
_ROOT
"""
return
os
.
path
.
join
(
django_settings
.
MEDIA
_ROOT
,
filename
)
return
os
.
path
.
join
(
settings
.
COMPRESS
_ROOT
,
filename
)
def
media_url
(
url
,
prefix
=
None
):
def
compress_source
(
filename
):
"""
Return the full path to ``filename``. ``filename`` is a relative path name in COMPRESS_SOURCE
"""
return
os
.
path
.
join
(
settings
.
COMPRESS_SOURCE
,
filename
)
def
compress_url
(
url
,
prefix
=
None
):
if
prefix
:
return
prefix
+
urlquote
(
url
)
return
django_settings
.
MEDIA
_URL
+
urlquote
(
url
)
return
settings
.
COMPRESS
_URL
+
urlquote
(
url
)
def
concat
(
filenames
,
separator
=
''
):
"""
...
...
@@ -71,20 +77,17 @@ def concat(filenames, separator=''):
"""
r
=
''
for
filename
in
filenames
:
fd
=
open
(
media_root
(
filename
),
'rb'
)
fd
=
open
(
compress_source
(
filename
),
'rb'
)
r
+=
fd
.
read
()
r
+=
separator
fd
.
close
()
return
r
def
max_mtime
(
files
):
return
int
(
max
([
os
.
stat
(
media_root
(
f
))
.
st_mtime
for
f
in
files
]))
def
save_file
(
filename
,
contents
):
dirname
=
os
.
path
.
dirname
(
media
_root
(
filename
))
dirname
=
os
.
path
.
dirname
(
compress
_root
(
filename
))
if
not
os
.
path
.
exists
(
dirname
):
os
.
makedirs
(
dirname
)
fd
=
open
(
media
_root
(
filename
),
'wb+'
)
fd
=
open
(
compress
_root
(
filename
),
'wb+'
)
fd
.
write
(
contents
)
fd
.
close
()
...
...
@@ -121,7 +124,7 @@ def filter_common(obj, verbosity, filters, attr, separator, signal):
filename
=
get_output_filename
(
obj
[
'output_filename'
],
get_version
(
obj
[
'source_filenames'
]))
if
settings
.
COMPRESS_VERSION
:
remove_files
(
os
.
path
.
dirname
(
media
_root
(
filename
)),
obj
[
'output_filename'
],
verbosity
)
remove_files
(
os
.
path
.
dirname
(
compress
_root
(
filename
)),
obj
[
'output_filename'
],
verbosity
)
if
verbosity
>=
1
:
print
"Saving
%
s"
%
filename
...
...
compress/versioning/mtime/__init__.py
View file @
1ce0fab9
import
os
from
compress.utils
import
get_output_filename
,
media
_root
from
compress.utils
import
get_output_filename
,
compress_source
,
compress
_root
from
compress.versioning.base
import
VersioningBase
class
MTimeVersioning
(
VersioningBase
):
...
...
@@ -8,12 +8,13 @@ class MTimeVersioning(VersioningBase):
def
get_version
(
self
,
source_files
):
# Return the modification time for the newest source file
return
str
(
max
([
int
(
os
.
stat
(
media_root
(
f
))
.
st_mtime
)
for
f
in
source_files
]))
return
str
(
max
(
[
int
(
os
.
stat
(
compress_source
(
f
))
.
st_mtime
)
for
f
in
source_files
]))
def
needs_update
(
self
,
output_file
,
source_files
,
version
):
output_file_name
=
get_output_filename
(
output_file
,
version
)
compressed_file_full
=
media
_root
(
output_file_name
)
compressed_file_full
=
compress
_root
(
output_file_name
)
return
(
int
(
os
.
stat
(
compressed_file_full
)
.
st_mtime
)
<
int
(
version
)),
version
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