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
f5e8443c
Commit
f5e8443c
authored
Apr 17, 2011
by
Timothée Peignier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
factorize subprocess based filters
parent
a01f1275
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
81 deletions
+36
-81
compress/filters/__init__.py
+27
-0
compress/filters/closure/__init__.py
+3
-27
compress/filters/uglifyjs/__init__.py
+3
-27
compress/filters/yui/__init__.py
+3
-27
No files found.
compress/filters/__init__.py
View file @
f5e8443c
import
subprocess
class
FilterBase
:
class
FilterBase
:
def
__init__
(
self
,
verbose
):
def
__init__
(
self
,
verbose
):
self
.
verbose
=
verbose
self
.
verbose
=
verbose
...
@@ -12,3 +15,27 @@ class FilterBase:
...
@@ -12,3 +15,27 @@ class FilterBase:
class
FilterError
(
Exception
):
class
FilterError
(
Exception
):
"""This exception is raised when a filter fails"""
"""This exception is raised when a filter fails"""
pass
pass
class
SubProcessFilter
(
FilterBase
):
def
execute_command
(
self
,
command
,
content
):
pipe
=
subprocess
.
Popen
(
command
,
shell
=
True
,
stdout
=
subprocess
.
PIPE
,
stdin
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
pipe
.
stdin
.
write
(
content
)
pipe
.
stdin
.
close
()
compressed_content
=
pipe
.
stdout
.
read
()
pipe
.
stdout
.
close
()
error
=
pipe
.
stderr
.
read
()
pipe
.
stderr
.
close
()
if
pipe
.
wait
()
!=
0
:
if
not
error
:
error
=
"Unable to apply
%
s filter"
%
self
.
__class__
.
__name__
raise
FilterError
(
error
)
if
self
.
verbose
:
print
error
return
compressed_content
compress/filters/closure/__init__.py
View file @
f5e8443c
import
subprocess
from
compress.conf
import
settings
from
compress.conf
import
settings
from
compress.filters
import
FilterBase
,
FilterErro
r
from
compress.filters
import
SubProcessFilte
r
class
ClosureCompressorFilter
(
FilterBase
):
class
ClosureCompressorFilter
(
SubProcessFilter
):
def
filter_js
(
self
,
js
):
def
filter_js
(
self
,
js
):
command
=
'
%
s
%
s'
%
(
settings
.
COMPRESS_CLOSURE_BINARY
,
settings
.
COMPRESS_CLOSURE_ARGUMENTS
)
command
=
'
%
s
%
s'
%
(
settings
.
COMPRESS_CLOSURE_BINARY
,
settings
.
COMPRESS_CLOSURE_ARGUMENTS
)
if
self
.
verbose
:
if
self
.
verbose
:
command
+=
' --verbose'
command
+=
' --verbose'
return
self
.
execute_command
(
command
,
js
)
p
=
subprocess
.
Popen
(
command
,
shell
=
True
,
stdout
=
subprocess
.
PIPE
,
stdin
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
p
.
stdin
.
write
(
js
)
p
.
stdin
.
close
()
filtered_js
=
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_js
compress/filters/uglifyjs/__init__.py
View file @
f5e8443c
import
subprocess
from
compress.conf
import
settings
from
compress.conf
import
settings
from
compress.filters
import
FilterBase
,
FilterErro
r
from
compress.filters
import
SubProcessFilte
r
class
UglifyJSCompressorFilter
(
FilterBase
):
class
UglifyJSCompressorFilter
(
SubProcessFilter
):
def
filter_js
(
self
,
js
):
def
filter_js
(
self
,
js
):
command
=
'
%
s
%
s'
%
(
settings
.
COMPRESS_UGLIFYJS_BINARY
,
settings
.
COMPRESS_UGLIFYJS_ARGUMENTS
)
command
=
'
%
s
%
s'
%
(
settings
.
COMPRESS_UGLIFYJS_BINARY
,
settings
.
COMPRESS_UGLIFYJS_ARGUMENTS
)
if
self
.
verbose
:
if
self
.
verbose
:
command
+=
' --verbose'
command
+=
' --verbose'
return
self
.
execute_command
(
command
,
js
)
p
=
subprocess
.
Popen
(
command
,
shell
=
True
,
stdout
=
subprocess
.
PIPE
,
stdin
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
p
.
stdin
.
write
(
js
)
p
.
stdin
.
close
()
filtered_js
=
p
.
stdout
.
read
()
p
.
stdout
.
close
()
err
=
p
.
stderr
.
read
()
p
.
stderr
.
close
()
if
p
.
wait
()
!=
0
:
if
not
err
:
err
=
'Unable to apply UglifyJS Compressor filter'
raise
FilterError
(
err
)
if
self
.
verbose
:
print
err
return
filtered_js
compress/filters/yui/__init__.py
View file @
f5e8443c
import
subprocess
from
compress.conf
import
settings
from
compress.conf
import
settings
from
compress.filters
import
FilterBase
,
FilterErro
r
from
compress.filters
import
SubProcessFilte
r
class
YUICompressorFilter
(
FilterBase
):
class
YUICompressorFilter
(
SubProcessFilter
):
def
filter_common
(
self
,
content
,
type_
,
arguments
):
def
filter_common
(
self
,
content
,
type_
,
arguments
):
command
=
'
%
s --type=
%
s
%
s'
%
(
settings
.
COMPRESS_YUI_BINARY
,
type_
,
arguments
)
command
=
'
%
s --type=
%
s
%
s'
%
(
settings
.
COMPRESS_YUI_BINARY
,
type_
,
arguments
)
if
self
.
verbose
:
if
self
.
verbose
:
command
+=
' --verbose'
command
+=
' --verbose'
return
self
.
execute_command
(
command
,
content
)
p
=
subprocess
.
Popen
(
command
,
shell
=
True
,
stdout
=
subprocess
.
PIPE
,
stdin
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
p
.
stdin
.
write
(
content
)
p
.
stdin
.
close
()
compressed_content
=
p
.
stdout
.
read
()
p
.
stdout
.
close
()
err
=
p
.
stderr
.
read
()
p
.
stderr
.
close
()
if
p
.
wait
()
!=
0
:
if
not
err
:
err
=
'Unable to apply YUI Compressor filter'
raise
FilterError
(
err
)
if
self
.
verbose
:
print
err
return
compressed_content
def
filter_js
(
self
,
js
):
def
filter_js
(
self
,
js
):
return
self
.
filter_common
(
js
,
'js'
,
settings
.
COMPRESS_YUI_JS_ARGUMENTS
)
return
self
.
filter_common
(
js
,
'js'
,
settings
.
COMPRESS_YUI_JS_ARGUMENTS
)
...
...
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