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
13c2004b
Commit
13c2004b
authored
Apr 25, 2011
by
Timothée Peignier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add compilers
parent
c9240c02
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
93 additions
and
28 deletions
+93
-28
compress/__init__.py
+0
-5
compress/compilers/__init__.py
+48
-1
compress/compilers/coffee/__init__.py
+4
-2
compress/compilers/less/__init__.py
+2
-0
compress/compilers/sass/__init__.py
+2
-0
compress/conf/settings.py
+5
-0
compress/management/commands/synccompress.py
+12
-8
compress/packager.py
+18
-10
compress/signals.py
+2
-2
No files found.
compress/__init__.py
View file @
13c2004b
from
compress.packager
import
Packager
__all__
=
[
'packager'
]
packager
=
Packager
()
compress/compilers/__init__.py
View file @
13c2004b
import
os
import
subprocess
from
compress.conf
import
settings
from
compress.utils
import
to_class
class
Compiler
(
object
):
def
__init__
(
self
,
verbose
=
False
):
self
.
verbose
=
verbose
def
compilers
(
self
):
return
[
to_class
(
compiler
)
for
compiler
in
settings
.
COMPRESS_COMPILERS
]
compilers
=
property
(
compilers
)
def
compile
(
self
,
paths
):
for
index
,
path
in
enumerate
(
paths
):
for
compiler
in
self
.
compilers
:
compiler
=
compiler
(
self
.
verbose
)
if
compiler
.
match_file
(
path
):
new_path
=
self
.
output_path
(
path
,
compiler
.
output_extension
)
content
=
self
.
read_file
(
path
)
compiled_content
=
compiler
.
compile_file
(
content
)
self
.
save_file
(
new_path
,
compiled_content
)
paths
[
index
]
=
new_path
return
paths
def
output_path
(
self
,
path
,
extension
):
path
=
os
.
path
.
splitext
(
path
)
return
'.'
.
join
((
path
[
0
],
extension
))
def
read_file
(
self
,
path
):
f
=
open
(
path
,
'rb'
)
content
=
f
.
read
()
f
.
close
()
return
content
def
save_file
(
self
,
path
,
content
):
f
=
open
(
path
,
'w'
)
f
.
write
(
content
)
f
.
close
()
class
CompilerBase
(
object
):
def
__init__
(
self
,
verbose
):
self
.
verbose
=
verbose
...
...
@@ -10,6 +51,12 @@ class CompilerBase(object):
def
compile_file
(
self
,
content
):
raise
NotImplementedError
def
save_file
(
self
,
path
,
content
):
f
=
open
(
path
,
'w'
)
f
.
write
(
content
)
f
.
close
()
return
path
class
CompilerError
(
Exception
):
pass
...
...
@@ -31,7 +78,7 @@ class SubProcessCompiler(CompilerBase):
if
pipe
.
wait
()
!=
0
:
if
not
error
:
error
=
"Unable to apply
%
s compiler"
%
self
.
__class__
.
__name__
raise
Filt
erError
(
error
)
raise
Compil
erError
(
error
)
if
self
.
verbose
:
print
error
...
...
compress/compilers/coffee/__init__.py
View file @
13c2004b
...
...
@@ -3,8 +3,10 @@ from compress.compilers import SubProcessCompiler
class
CoffeeScriptCompiler
(
SubProcessCompiler
):
def
match_file
(
self
,
filename
):
return
filename
.
endswith
(
'.coffee'
)
output_extension
=
'js'
def
match_file
(
self
,
path
):
return
path
.
endswith
(
'.coffee'
)
def
compile_file
(
self
,
content
):
command
=
"
%
s
%
s"
%
(
settings
.
COMPRESS_COFFEE_SCRIPT_BINARY
,
settings
.
COMPRESS_COFFEE_SCRIPT_ARGUMENTS
)
...
...
compress/compilers/less/__init__.py
View file @
13c2004b
...
...
@@ -6,6 +6,8 @@ from compress.compilers import CompilerBase
class
LessCompiler
(
CompilerBase
):
output_extension
=
'css'
def
match_file
(
self
,
filename
):
return
filename
.
endswith
(
'.less'
)
...
...
compress/compilers/sass/__init__.py
View file @
13c2004b
...
...
@@ -3,6 +3,8 @@ from compress.compilers import SubProcessCompiler
class
SASSCompiler
(
SubProcessCompiler
):
output_extension
=
'css'
def
match_file
(
self
,
filename
):
return
filename
.
endswith
(
'.scss'
)
...
...
compress/conf/settings.py
View file @
13c2004b
...
...
@@ -22,6 +22,8 @@ COMPRESS_CSS_COMPRESSORS = getattr(settings, 'COMPRESS_CSS_COMPRESSORS', [
COMPRESS_JS_COMPRESSORS
=
getattr
(
settings
,
'COMPRESS_JS_COMPRESSORS'
,
[
'compress.compressors.csstidy.YUICompressor'
])
COMPRESS_COMPILERS
=
getattr
(
settings
,
'COMPRESS_COMPILERS'
,
[])
COMPRESS_CSS
=
getattr
(
settings
,
'COMPRESS_CSS'
,
{})
COMPRESS_JS
=
getattr
(
settings
,
'COMPRESS_JS'
,
{})
...
...
@@ -49,3 +51,6 @@ if COMPRESS_CSS_COMPRESSORS is None:
if
COMPRESS_JS_COMPRESSORS
is
None
:
COMPRESS_JS_COMPRESSORS
=
[]
if
COMPRESS_COMPILERS
is
None
:
COMPRESS_COMPILERS
=
[]
compress/management/commands/synccompress.py
View file @
13c2004b
...
...
@@ -15,21 +15,25 @@ class Command(NoArgsCommand):
args
=
''
def
handle_noargs
(
self
,
**
options
):
from
compress
import
packager
packager
.
force
=
options
.
get
(
'force'
,
False
)
packager
.
verbose
=
int
(
options
.
get
(
'verbosity'
,
1
))
>=
2
for
package_name
,
package
in
packager
.
packages
[
'css'
]
.
items
():
from
compress.packager
import
Packager
packager
=
Packager
(
force
=
options
.
get
(
'force'
,
False
),
verbose
=
int
(
options
.
get
(
'verbosity'
,
1
))
>=
2
)
for
package_name
in
packager
.
packages
[
'css'
]:
package
=
packager
.
package_for
(
'css'
,
package_name
)
if
packager
.
verbose
or
packager
.
force
:
print
print
message
=
"CSS Group '
%
s'"
%
package_name
print
message
print
len
(
message
)
*
'-'
packager
.
pack_stylesheets
(
package
)
for
package_name
,
package
in
packager
.
packages
[
'js'
]
.
items
():
for
package_name
in
packager
.
packages
[
'js'
]:
package
=
packager
.
package_for
(
'js'
,
package_name
)
if
packager
.
verbose
or
packager
.
force
:
print
print
message
=
"JS Group '
%
s'"
%
package_name
print
message
print
len
(
message
)
*
'-'
...
...
compress/packager.py
View file @
13c2004b
...
...
@@ -3,9 +3,10 @@ import os
import
urlparse
from
compress.conf
import
settings
from
compress.compilers
import
Compiler
from
compress.compressors
import
Compressor
from
compress.versioning
import
Versioning
from
compress.signals
import
css_
filtered
,
js_filter
ed
from
compress.signals
import
css_
compressed
,
js_compress
ed
class
Packager
(
object
):
...
...
@@ -14,6 +15,7 @@ class Packager(object):
self
.
verbose
=
verbose
self
.
compressor
=
Compressor
(
verbose
)
self
.
versioning
=
Versioning
(
verbose
)
self
.
compiler
=
Compiler
(
verbose
)
self
.
packages
=
{
'css'
:
self
.
create_packages
(
settings
.
COMPRESS_CSS
),
'js'
:
self
.
create_packages
(
settings
.
COMPRESS_JS
),
...
...
@@ -21,20 +23,25 @@ class Packager(object):
def
package_for
(
self
,
kind
,
package_name
):
try
:
return
self
.
packages
[
kind
][
package_name
]
return
self
.
packages
[
kind
][
package_name
]
.
copy
()
except
KeyError
:
raise
PackageNotFound
(
"No corresponding package for
%
s package name :
%
s"
%
(
kind
,
package_name
)
raise
PackageNotFound
(
"No corresponding package for
%
s package name :
%
s"
%
(
kind
,
package_name
)
)
def
individual_url
(
self
,
filename
):
return
urlparse
.
urljoin
(
settings
.
COMPRESS_URL
,
self
.
compressor
.
relative_path
(
filename
)[
1
:])
return
urlparse
.
urljoin
(
settings
.
COMPRESS_URL
,
self
.
compressor
.
relative_path
(
filename
)[
1
:])
def
pack_stylesheets
(
self
,
package
):
css
=
self
.
compressor
.
compress_css
(
package
[
'paths'
])
return
self
.
pack
(
package
,
css
,
css_filtered
)
return
self
.
pack
(
package
,
self
.
compressor
.
compress_css
,
css_compressed
)
def
pack
(
self
,
package
,
content
,
signal
):
def
compile
(
self
,
paths
):
return
self
.
compiler
.
compile
(
paths
)
def
pack
(
self
,
package
,
compress
,
signal
):
if
settings
.
COMPRESS_AUTO
or
self
.
force
:
need_update
,
version
=
self
.
versioning
.
need_update
(
package
[
'output'
],
package
[
'paths'
])
...
...
@@ -45,6 +52,8 @@ class Packager(object):
if
self
.
verbose
or
self
.
force
:
print
"Version:
%
s"
%
version
print
"Saving:
%
s"
%
self
.
compressor
.
relative_path
(
output_filename
)
paths
=
self
.
compile
(
package
[
'paths'
])
content
=
compress
(
paths
)
self
.
save_file
(
output_filename
,
content
)
signal
.
send
(
sender
=
self
,
package
=
package
,
version
=
version
)
else
:
...
...
@@ -53,8 +62,7 @@ class Packager(object):
return
self
.
versioning
.
output_filename
(
package
[
'output'
],
version
)
def
pack_javascripts
(
self
,
package
):
js
=
self
.
compressor
.
compress_js
(
package
[
'paths'
])
return
self
.
pack
(
package
,
js
,
js_filtered
)
return
self
.
pack
(
package
,
self
.
compressor
.
compress_js
,
js_compressed
)
def
save_file
(
self
,
filename
,
content
):
dirname
=
os
.
path
.
dirname
(
filename
)
...
...
compress/signals.py
View file @
13c2004b
from
django.dispatch
import
Signal
css_
filter
ed
=
Signal
(
providing_args
=
[
"package"
,
"version"
])
js_
filter
ed
=
Signal
(
providing_args
=
[
"package"
,
"version"
])
css_
compress
ed
=
Signal
(
providing_args
=
[
"package"
,
"version"
])
js_
compress
ed
=
Signal
(
providing_args
=
[
"package"
,
"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