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
9662e69f
Commit
9662e69f
authored
Oct 26, 2010
by
Timothée Peignier
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote branch 'ara818/master'
parents
f7917eca
4532912e
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
138 additions
and
13 deletions
+138
-13
compress/conf/settings.py
+7
-0
compress/filters/closure/__init__.py
+38
-0
compress/filters/yui/__init__.py
+7
-11
compress/templatetags/compressed.py
+2
-2
compress/utils.py
+11
-0
compress/versioning/git/__init__.py
+46
-0
docs/Versioning.textile
+27
-0
No files found.
compress/conf/settings.py
View file @
9662e69f
...
@@ -17,6 +17,13 @@ COMPRESS_JS_FILTERS = getattr(settings, 'COMPRESS_JS_FILTERS', ['compress.filter
...
@@ -17,6 +17,13 @@ COMPRESS_JS_FILTERS = getattr(settings, 'COMPRESS_JS_FILTERS', ['compress.filter
COMPRESS_CSS
=
getattr
(
settings
,
'COMPRESS_CSS'
,
{})
COMPRESS_CSS
=
getattr
(
settings
,
'COMPRESS_CSS'
,
{})
COMPRESS_JS
=
getattr
(
settings
,
'COMPRESS_JS'
,
{})
COMPRESS_JS
=
getattr
(
settings
,
'COMPRESS_JS'
,
{})
COMPRESS_YUI_BINARY
=
getattr
(
settings
,
'COMPRESS_YUI_BINARY'
,
'java -jar yuicompressor.jar'
)
COMPRESS_YUI_CSS_ARGUMENTS
=
getattr
(
settings
,
'COMPRESS_YUI_CSS_ARGUMENTS'
,
''
)
COMPRESS_YUI_JS_ARGUMENTS
=
getattr
(
settings
,
'COMPRESS_YUI_JS_ARGUMENTS'
,
''
)
COMPRESS_CLOSURE_BINARY
=
getattr
(
settings
,
'COMPRESS_CLOSURE_BINARY'
,
'java -jar compiler.jar'
)
COMPRESS_CLOSURE_JS_ARGUMENTS
=
getattr
(
settings
,
'COMPRESS_CLOSURE_JS_ARGUMENTS'
,
''
)
if
COMPRESS_CSS_FILTERS
is
None
:
if
COMPRESS_CSS_FILTERS
is
None
:
COMPRESS_CSS_FILTERS
=
[]
COMPRESS_CSS_FILTERS
=
[]
...
...
compress/filters/closure/__init__.py
0 → 100644
View file @
9662e69f
import
subprocess
from
compress.conf
import
settings
from
compress.filter_base
import
FilterBase
,
FilterError
class
ClosureCompressorFilter
(
FilterBase
):
def
filter_common
(
self
,
content
,
type_
,
arguments
):
command
=
'
%
s
%
s'
%
(
settings
.
COMPRESS_CLOSURE_BINARY
,
arguments
)
if
self
.
verbose
:
command
+=
' --verbose'
p
=
subprocess
.
Popen
(
command
,
shell
=
True
,
stdout
=
subprocess
.
PIPE
,
\
stdin
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
p
.
stdin
.
write
(
content
)
p
.
stdin
.
close
()
filtered_css
=
p
.
stdout
.
read
()
p
.
stdout
.
close
()
err
=
p
.
stderr
.
read
()
p
.
stderr
.
close
()
if
p
.
wait
()
!=
0
:
if
not
err
:
err
=
'Unable to apply Closure Compressor filter'
raise
FilterError
(
err
)
if
self
.
verbose
:
print
err
return
filtered_css
def
filter_js
(
self
,
js
):
return
self
.
filter_common
(
js
,
'js'
,
settings
.
COMPRESS_CLOSURE_JS_ARGUMENTS
)
\ No newline at end of file
compress/filters/yui/__init__.py
View file @
9662e69f
import
subprocess
import
subprocess
from
django.conf
import
settings
from
compress.conf
import
settings
from
compress.filter_base
import
FilterBase
,
FilterError
from
compress.filter_base
import
FilterBase
,
FilterError
BINARY
=
getattr
(
settings
,
'COMPRESS_YUI_BINARY'
,
'java -jar yuicompressor.jar'
)
CSS_ARGUMENTS
=
getattr
(
settings
,
'COMPRESS_YUI_CSS_ARGUMENTS'
,
''
)
JS_ARGUMENTS
=
getattr
(
settings
,
'COMPRESS_YUI_JS_ARGUMENTS'
,
''
)
class
YUICompressorFilter
(
FilterBase
):
class
YUICompressorFilter
(
FilterBase
):
def
filter_common
(
self
,
content
,
type_
,
arguments
):
def
filter_common
(
self
,
content
,
type_
,
arguments
):
command
=
'
%
s --type=
%
s
%
s'
%
(
BINARY
,
type_
,
arguments
)
command
=
'
%
s --type=
%
s
%
s'
%
(
settings
.
COMPRESS_YUI_
BINARY
,
type_
,
arguments
)
if
self
.
verbose
:
if
self
.
verbose
:
command
+=
' --verbose'
command
+=
' --verbose'
p
=
subprocess
.
Popen
(
command
,
shell
=
True
,
stdout
=
subprocess
.
PIPE
,
stdin
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
p
=
subprocess
.
Popen
(
command
,
shell
=
True
,
stdout
=
subprocess
.
PIPE
,
\
stdin
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
p
.
stdin
.
write
(
content
)
p
.
stdin
.
write
(
content
)
p
.
stdin
.
close
()
p
.
stdin
.
close
()
...
@@ -38,7 +34,7 @@ class YUICompressorFilter(FilterBase):
...
@@ -38,7 +34,7 @@ class YUICompressorFilter(FilterBase):
return
filtered_css
return
filtered_css
def
filter_js
(
self
,
js
):
def
filter_js
(
self
,
js
):
return
self
.
filter_common
(
js
,
'js'
,
JS_ARGUMENTS
)
return
self
.
filter_common
(
js
,
'js'
,
settings
.
COMPRESS_YUI_
JS_ARGUMENTS
)
def
filter_css
(
self
,
css
):
def
filter_css
(
self
,
css
):
return
self
.
filter_common
(
css
,
'css'
,
CSS_ARGUMENTS
)
return
self
.
filter_common
(
css
,
'css'
,
settings
.
COMPRESS_YUI_CSS_ARGUMENTS
)
\ No newline at end of file
\ No newline at end of file
compress/templatetags/compressed.py
View file @
9662e69f
...
@@ -59,7 +59,7 @@ class CompressedCSSNode(template.Node):
...
@@ -59,7 +59,7 @@ class CompressedCSSNode(template.Node):
css
[
'source_filenames'
])
css
[
'source_filenames'
])
if
u
:
if
u
:
filter_css
(
css
)
filter_css
(
css
)
el
if
not
css
.
get
(
'extra_context'
,
{})
.
get
(
'prefix'
,
None
)
:
el
se
:
filename_base
,
filename
=
os
.
path
.
split
(
css
[
'output_filename'
])
filename_base
,
filename
=
os
.
path
.
split
(
css
[
'output_filename'
])
path_name
=
compress_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
)
...
@@ -100,7 +100,7 @@ class CompressedJSNode(template.Node):
...
@@ -100,7 +100,7 @@ class CompressedJSNode(template.Node):
js
[
'source_filenames'
])
js
[
'source_filenames'
])
if
u
:
if
u
:
filter_js
(
js
)
filter_js
(
js
)
el
if
not
js
.
get
(
'extra_context'
,
{})
.
get
(
'prefix'
,
None
)
:
el
se
:
filename_base
,
filename
=
os
.
path
.
split
(
js
[
'output_filename'
])
filename_base
,
filename
=
os
.
path
.
split
(
js
[
'output_filename'
])
path_name
=
compress_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
)
...
...
compress/utils.py
View file @
9662e69f
...
@@ -37,6 +37,17 @@ def get_mod_func(callback):
...
@@ -37,6 +37,17 @@ def get_mod_func(callback):
except
ValueError
:
except
ValueError
:
return
callback
,
''
return
callback
,
''
return
callback
[:
dot
],
callback
[
dot
+
1
:]
return
callback
[:
dot
],
callback
[
dot
+
1
:]
def
get_hexdigest
(
plaintext
):
"""
Create a hexdigest from a plaintext string
"""
try
:
import
hashlib
return
hashlib
.
sha1
(
plaintext
)
.
hexdigest
()
except
ImportError
:
import
sha
return
sha
.
new
(
plaintext
)
.
hexdigest
()
def
needs_update
(
output_file
,
source_files
,
verbosity
=
0
):
def
needs_update
(
output_file
,
source_files
,
verbosity
=
0
):
"""
"""
...
...
compress/versioning/git/__init__.py
0 → 100644
View file @
9662e69f
import
os
from
compress.conf
import
settings
from
compress.utils
import
get_output_filename
,
get_hexdigest
,
compress_source
from
compress.versioning.base
import
VersioningBase
,
VersioningError
try
:
import
git
except
ImportError
:
raise
VersioningError
(
"Must have GitPython package installed to use git versioning"
)
class
GitVersioningBase
(
VersioningBase
):
def
needs_update
(
self
,
output_file
,
source_files
,
version
):
output_file_name
=
get_output_filename
(
output_file
,
version
)
ph
=
settings
.
COMPRESS_VERSION_PLACEHOLDER
of
=
output_file
try
:
phi
=
of
.
index
(
ph
)
old_version
=
output_file_name
[
phi
:
phi
+
len
(
ph
)
-
len
(
of
)]
return
(
version
!=
old_version
),
version
except
ValueError
:
# no placeholder found, do not update, manual update if needed
return
False
,
version
class
GitRevVersioning
(
GitVersioningBase
):
"""
Version as hash of revision of all files in sources_files list.
"""
def
get_version
(
self
,
source_files
):
repo
=
git
.
Repo
(
compress_source
(
source_files
[
0
]))
kwargs
=
{
'max_count'
:
1
}
commit_revs
=
[]
for
f
in
source_files
:
commit
=
[
i
for
i
in
repo
.
iter_commits
(
paths
=
compress_source
(
f
),
**
kwargs
)][
0
]
commit_revs
.
append
(
commit
.
name_rev
)
return
get_hexdigest
(
', '
.
join
(
commit_revs
))[
0
:
16
]
class
GitHeadRevVersioning
(
GitVersioningBase
):
"""
Version as hash of latest revision in HEAD. Assumes all sources_files in same git repo.
"""
def
get_version
(
self
,
source_files
):
f
=
source_files
[
0
]
repo
=
git
.
Repo
(
compress_source
(
f
))
return
get_hexdigest
(
repo
.
head
.
commit
.
name_rev
)[
0
:
16
]
\ No newline at end of file
docs/Versioning.textile
View file @
9662e69f
...
@@ -26,6 +26,33 @@ To generate SHA-1 version strings, put this in your settings.py:
...
@@ -26,6 +26,33 @@ To generate SHA-1 version strings, put this in your settings.py:
COMPRESS_VERSIONING = 'compress.versioning.hash.SHA1Versioning'
COMPRESS_VERSIONING = 'compress.versioning.hash.SHA1Versioning'
</code></pre>
</code></pre>
h3. Git version strings
Versions formed on git revisions in codebase. Provides a fast way to check if any of your files changed that
will be consistent across multiple web servers so that they all generate the same version numbers for each
set of source files, assuming their git repositories are all in sync.
Assumes deployment is git repositiory. Requires GitPython 0.2.0.
GitPython 0.3.0 uses an async library that does not currently play well with Django. To install using Git just do
pip install GitPython==0.2.0-beta1.
h4. Git revision version strings.
To generate versions based on revision of every file in your source file list, put this in your settings.py:
<pre><code>
COMPRESS_VERSIONING = 'compress.versioning.git.GitVersioningBase'
</code></pre>
h4.Git HEAD last revision version strings.
To generate versions based on the latest revision of HEAD in your git repository (which assumes all of your source files are in the
same repository), put this in your settings.py:
<pre><code>
COMPRESS_VERSIONING = 'compress.versioning.git.GitHeadRevVersioning'
</code></pre>
h3. Write your own versioning class
h3. Write your own versioning class
To write your own versioning class, you can subclass one of the available versioning classes.
To write your own versioning class, you can subclass one of the available versioning classes.
...
...
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