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
18aefa70
Commit
18aefa70
authored
Jul 26, 2009
by
Bryan Chow
Browse files
Options
Browse Files
Download
Plain Diff
Merge from lincolnloop/master.
parents
c0e92749
2414bf61
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 @
18aefa70
...
@@ -2,6 +2,9 @@ from django.core.exceptions import ImproperlyConfigured
...
@@ -2,6 +2,9 @@ from django.core.exceptions import ImproperlyConfigured
from
django.conf
import
settings
from
django.conf
import
settings
COMPRESS
=
getattr
(
settings
,
'COMPRESS'
,
not
settings
.
DEBUG
)
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_AUTO
=
getattr
(
settings
,
'COMPRESS_AUTO'
,
True
)
COMPRESS_VERSION
=
getattr
(
settings
,
'COMPRESS_VERSION'
,
False
)
COMPRESS_VERSION
=
getattr
(
settings
,
'COMPRESS_VERSION'
,
False
)
COMPRESS_VERSION_PLACEHOLDER
=
getattr
(
settings
,
'COMPRESS_VERSION_PLACEHOLDER'
,
'?'
)
COMPRESS_VERSION_PLACEHOLDER
=
getattr
(
settings
,
'COMPRESS_VERSION_PLACEHOLDER'
,
'?'
)
...
...
compress/templatetags/compressed.py
View file @
18aefa70
...
@@ -5,7 +5,7 @@ from django import template
...
@@ -5,7 +5,7 @@ from django import template
from
django.conf
import
settings
as
django_settings
from
django.conf
import
settings
as
django_settings
from
compress.conf
import
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
()
register
=
template
.
Library
()
...
@@ -28,7 +28,7 @@ def render_common(obj, filename, version):
...
@@ -28,7 +28,7 @@ def render_common(obj, filename, version):
if
filename
.
startswith
(
'http://'
):
if
filename
.
startswith
(
'http://'
):
context
[
'url'
]
=
filename
context
[
'url'
]
=
filename
else
:
else
:
context
[
'url'
]
=
media
_url
(
filename
,
prefix
)
context
[
'url'
]
=
compress
_url
(
filename
,
prefix
)
return
obj
[
'template'
]
.
render
(
context
)
return
obj
[
'template'
]
.
render
(
context
)
...
@@ -61,7 +61,7 @@ class CompressedCSSNode(template.Node):
...
@@ -61,7 +61,7 @@ class CompressedCSSNode(template.Node):
filter_css
(
css
)
filter_css
(
css
)
else
:
else
:
filename_base
,
filename
=
os
.
path
.
split
(
css
[
'output_filename'
])
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
)
version
=
get_version_from_file
(
path_name
,
filename
)
return
render_css
(
css
,
css
[
'output_filename'
],
version
)
return
render_css
(
css
,
css
[
'output_filename'
],
version
)
...
@@ -102,7 +102,7 @@ class CompressedJSNode(template.Node):
...
@@ -102,7 +102,7 @@ class CompressedJSNode(template.Node):
filter_js
(
js
)
filter_js
(
js
)
else
:
else
:
filename_base
,
filename
=
os
.
path
.
split
(
js
[
'output_filename'
])
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
)
version
=
get_version_from_file
(
path_name
,
filename
)
return
render_js
(
js
,
js
[
'output_filename'
],
version
)
return
render_js
(
js
,
js
[
'output_filename'
],
version
)
...
...
compress/utils.py
View file @
18aefa70
...
@@ -46,7 +46,7 @@ def needs_update(output_file, source_files, verbosity=0):
...
@@ -46,7 +46,7 @@ def needs_update(output_file, source_files, verbosity=0):
version
=
get_version
(
source_files
)
version
=
get_version
(
source_files
)
on
=
get_output_filename
(
output_file
,
version
)
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
):
if
not
os
.
path
.
exists
(
compressed_file_full
):
return
True
,
version
return
True
,
version
...
@@ -54,16 +54,22 @@ def needs_update(output_file, source_files, verbosity=0):
...
@@ -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
)
update_needed
=
getattr
(
get_class
(
settings
.
COMPRESS_VERSIONING
)(),
'needs_update'
)(
output_file
,
source_files
,
version
)
return
update_needed
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
:
if
prefix
:
return
prefix
+
urlquote
(
url
)
return
prefix
+
urlquote
(
url
)
return
django_settings
.
MEDIA
_URL
+
urlquote
(
url
)
return
settings
.
COMPRESS
_URL
+
urlquote
(
url
)
def
concat
(
filenames
,
separator
=
''
):
def
concat
(
filenames
,
separator
=
''
):
"""
"""
...
@@ -71,20 +77,17 @@ def concat(filenames, separator=''):
...
@@ -71,20 +77,17 @@ def concat(filenames, separator=''):
"""
"""
r
=
''
r
=
''
for
filename
in
filenames
:
for
filename
in
filenames
:
fd
=
open
(
media_root
(
filename
),
'rb'
)
fd
=
open
(
compress_source
(
filename
),
'rb'
)
r
+=
fd
.
read
()
r
+=
fd
.
read
()
r
+=
separator
r
+=
separator
fd
.
close
()
fd
.
close
()
return
r
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
):
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
):
if
not
os
.
path
.
exists
(
dirname
):
os
.
makedirs
(
dirname
)
os
.
makedirs
(
dirname
)
fd
=
open
(
media
_root
(
filename
),
'wb+'
)
fd
=
open
(
compress
_root
(
filename
),
'wb+'
)
fd
.
write
(
contents
)
fd
.
write
(
contents
)
fd
.
close
()
fd
.
close
()
...
@@ -121,7 +124,7 @@ def filter_common(obj, verbosity, filters, attr, separator, signal):
...
@@ -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'
]))
filename
=
get_output_filename
(
obj
[
'output_filename'
],
get_version
(
obj
[
'source_filenames'
]))
if
settings
.
COMPRESS_VERSION
and
settings
.
COMPRESS_VERSION_REMOVE_OLD
:
if
settings
.
COMPRESS_VERSION
and
settings
.
COMPRESS_VERSION_REMOVE_OLD
:
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
:
if
verbosity
>=
1
:
print
"Saving
%
s"
%
filename
print
"Saving
%
s"
%
filename
...
...
compress/versioning/mtime/__init__.py
View file @
18aefa70
import
os
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
from
compress.versioning.base
import
VersioningBase
class
MTimeVersioning
(
VersioningBase
):
class
MTimeVersioning
(
VersioningBase
):
...
@@ -8,12 +8,13 @@ class MTimeVersioning(VersioningBase):
...
@@ -8,12 +8,13 @@ class MTimeVersioning(VersioningBase):
def
get_version
(
self
,
source_files
):
def
get_version
(
self
,
source_files
):
# Return the modification time for the newest source file
# 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
):
def
needs_update
(
self
,
output_file
,
source_files
,
version
):
output_file_name
=
get_output_filename
(
output_file
,
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
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