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
2df0ec93
Commit
2df0ec93
authored
Apr 25, 2011
by
Timothée Peignier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use django storage everywhere and add a staticfiles finder
parent
c8ed240d
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
79 additions
and
32 deletions
+79
-32
compress/compilers/__init__.py
+11
-10
compress/compressors/__init__.py
+4
-3
compress/conf/settings.py
+2
-0
compress/finders.py
+7
-0
compress/packager.py
+7
-8
compress/storage.py
+34
-0
compress/versioning/__init__.py
+6
-5
compress/versioning/hash/__init__.py
+4
-3
compress/versioning/mtime/__init__.py
+4
-3
No files found.
compress/compilers/__init__.py
View file @
2df0ec93
...
...
@@ -2,6 +2,7 @@ import os
import
subprocess
from
compress.conf
import
settings
from
compress.storage
import
storage
from
compress.utils
import
to_class
...
...
@@ -24,7 +25,7 @@ class Compiler(object):
compiled_content
=
compiler
.
compile_file
(
content
)
self
.
save_file
(
new_path
,
compiled_content
)
except
CompilerError
:
if
not
os
.
path
.
exists
(
new_path
):
if
not
storage
.
exists
(
new_path
):
raise
paths
[
index
]
=
new_path
return
paths
...
...
@@ -34,15 +35,15 @@ class Compiler(object):
return
'.'
.
join
((
path
[
0
],
extension
))
def
read_file
(
self
,
path
):
f
=
open
(
path
,
'rb'
)
content
=
f
.
read
()
f
.
close
()
f
ile
=
storage
.
open
(
path
,
'rb'
)
content
=
f
ile
.
read
()
f
ile
.
close
()
return
content
def
save_file
(
self
,
path
,
content
):
f
=
open
(
path
,
'w
'
)
f
.
write
(
content
)
f
.
close
()
f
ile
=
storage
.
open
(
path
,
'wb
'
)
f
ile
.
write
(
content
)
f
ile
.
close
()
class
CompilerBase
(
object
):
...
...
@@ -56,9 +57,9 @@ class CompilerBase(object):
raise
NotImplementedError
def
save_file
(
self
,
path
,
content
):
f
=
open
(
path
,
'w
'
)
f
.
write
(
content
)
f
.
close
()
f
ile
=
storage
.
open
(
path
,
'wb
'
)
f
ile
.
write
(
content
)
f
ile
.
close
()
return
path
...
...
compress/compressors/__init__.py
View file @
2df0ec93
...
...
@@ -4,6 +4,7 @@ import subprocess
import
urlparse
from
compress.conf
import
settings
from
compress.storage
import
storage
from
compress.utils
import
to_class
URL_DETECTOR
=
r'url\([\'"]?([^\s)]+\.[a-z]+)[\'"]?\)'
...
...
@@ -77,9 +78,9 @@ class Compressor(object):
def
read_file
(
self
,
path
):
"""Read file content in binary mode"""
f
=
open
(
path
,
'rb'
)
content
=
f
.
read
()
f
.
close
()
f
ile
=
storage
.
open
(
path
,
mode
=
'rb'
)
content
=
f
ile
.
read
()
f
ile
.
close
()
return
content
...
...
compress/conf/settings.py
View file @
2df0ec93
...
...
@@ -15,6 +15,8 @@ COMPRESS_VERSION_DEFAULT = getattr(settings, 'COMPRESS_VERSION_DEFAULT', '0')
COMPRESS_VERSION_REMOVE_OLD
=
getattr
(
settings
,
'COMPRESS_VERSION_REMOVE_OLD'
,
True
)
COMPRESS_VERSIONING
=
getattr
(
settings
,
'COMPRESS_VERSIONING'
,
'compress.versioning.mtime.MTimeVersioning'
)
COMPRESS_STORAGE
=
getattr
(
settings
,
'COMPRESS_STORAGE'
,
'compress.storage.CompressStorage'
)
COMPRESS_CSS_COMPRESSORS
=
getattr
(
settings
,
'COMPRESS_CSS_COMPRESSORS'
,
[
'compress.compressors.csstidy.YUICompressor'
...
...
compress/finders.py
0 → 100644
View file @
2df0ec93
from
django.contrib.staticfiles.finders
import
BaseStorageFinder
from
compress.storage
import
CompressStorage
class
CompressFinder
(
BaseStorageFinder
):
storage
=
CompressStorage
compress/packager.py
View file @
2df0ec93
...
...
@@ -5,8 +5,9 @@ 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_compressed
,
js_compressed
from
compress.storage
import
storage
from
compress.versioning
import
Versioning
class
Packager
(
object
):
...
...
@@ -65,12 +66,9 @@ class Packager(object):
return
self
.
pack
(
package
,
self
.
compressor
.
compress_js
,
js_compressed
)
def
save_file
(
self
,
filename
,
content
):
dirname
=
os
.
path
.
dirname
(
filename
)
if
not
os
.
path
.
exists
(
dirname
):
os
.
makedirs
(
dirname
)
fd
=
open
(
filename
,
'wb+'
)
fd
.
write
(
content
)
fd
.
close
()
file
=
storage
.
open
(
filename
,
mode
=
'wb+'
)
file
.
write
(
content
)
file
.
close
()
def
create_packages
(
self
,
config
):
packages
=
{}
...
...
@@ -81,7 +79,8 @@ class Packager(object):
paths
=
[]
for
path
in
config
[
name
][
'source_filenames'
]:
full_path
=
os
.
path
.
join
(
settings
.
COMPRESS_ROOT
,
path
)
paths
.
extend
([
os
.
path
.
normpath
(
path
)
for
path
in
glob
.
glob
(
full_path
)])
paths
.
extend
([
os
.
path
.
normpath
(
path
)
for
path
in
glob
.
glob
(
full_path
)])
packages
[
name
][
'paths'
]
=
paths
packages
[
name
][
'output'
]
=
config
[
name
][
'output_filename'
]
packages
[
name
][
'context'
]
=
{}
...
...
compress/storage.py
0 → 100644
View file @
2df0ec93
import
os
from
datetime
import
datetime
from
django.core.files.storage
import
FileSystemStorage
,
get_storage_class
from
django.utils.functional
import
LazyObject
from
compress.conf
import
settings
class
CompressStorage
(
FileSystemStorage
):
def
__init__
(
self
,
location
=
None
,
base_url
=
None
,
*
args
,
**
kwargs
):
if
location
is
None
:
location
=
settings
.
COMPRESS_ROOT
if
base_url
is
None
:
base_url
=
settings
.
COMPRESS_URL
super
(
CompressStorage
,
self
)
.
__init__
(
location
,
base_url
,
*
args
,
**
kwargs
)
def
accessed_time
(
self
,
name
):
return
datetime
.
fromtimestamp
(
os
.
path
.
getatime
(
self
.
path
(
name
)))
def
created_time
(
self
,
name
):
return
datetime
.
fromtimestamp
(
os
.
path
.
getctime
(
self
.
path
(
name
)))
def
modified_time
(
self
,
name
):
return
datetime
.
fromtimestamp
(
os
.
path
.
getmtime
(
self
.
path
(
name
)))
class
DefaultStorage
(
LazyObject
):
def
_setup
(
self
):
self
.
_wrapped
=
get_storage_class
(
settings
.
COMPRESS_STORAGE
)()
storage
=
DefaultStorage
()
compress/versioning/__init__.py
View file @
2df0ec93
...
...
@@ -2,6 +2,7 @@ import os
import
re
from
compress.conf
import
settings
from
compress.storage
import
storage
from
compress.utils
import
to_class
...
...
@@ -20,7 +21,7 @@ class Versioning(object):
filename
=
settings
.
COMPRESS_VERSION_PLACEHOLDER
.
join
([
re
.
escape
(
part
)
for
part
in
filename
.
split
(
settings
.
COMPRESS_VERSION_PLACEHOLDER
)])
regex
=
re
.
compile
(
r'^
%
s$'
%
self
.
output_filename
(
filename
,
r'([A-Za-z0-9]+)'
))
versions
=
[]
for
f
in
sorted
(
os
.
listdir
(
path
),
reverse
=
True
):
for
f
in
sorted
(
storage
.
listdir
(
path
),
reverse
=
True
):
version
=
regex
.
match
(
f
)
if
version
and
version
.
groups
():
versions
.
append
(
version
.
group
(
1
))
...
...
@@ -43,7 +44,7 @@ class Versioning(object):
def
need_update
(
self
,
output_file
,
paths
):
version
=
self
.
version
(
paths
)
output_file
=
self
.
output_filename
(
output_file
,
version
)
if
not
os
.
path
.
exists
(
self
.
relative_path
(
output_file
)):
if
not
storage
.
exists
(
self
.
relative_path
(
output_file
)):
return
True
,
version
return
getattr
(
self
.
versionner
,
'need_update'
)(
output_file
,
paths
,
version
)
...
...
@@ -53,12 +54,12 @@ class Versioning(object):
filename
=
settings
.
COMPRESS_VERSION_PLACEHOLDER
.
join
([
re
.
escape
(
part
)
for
part
in
filename
.
split
(
settings
.
COMPRESS_VERSION_PLACEHOLDER
)])
path
=
os
.
path
.
dirname
(
filename
)
regex
=
re
.
compile
(
r'^
%
s$'
%
os
.
path
.
basename
(
self
.
output_filename
(
filename
,
r'([A-Za-z0-9]+)'
)))
if
os
.
path
.
exists
(
path
):
for
f
in
os
.
listdir
(
path
):
if
storage
.
exists
(
path
):
for
f
in
storage
.
listdir
(
path
):
if
regex
.
match
(
f
):
if
self
.
verbose
:
print
"Removing outdated file
%
s"
%
f
os
.
unlink
(
os
.
path
.
join
(
path
,
f
))
storage
.
delete
(
os
.
path
.
join
(
path
,
f
))
class
VersioningBase
(
object
):
...
...
compress/versioning/hash/__init__.py
View file @
2df0ec93
...
...
@@ -2,6 +2,7 @@ import cStringIO
from
hashlib
import
md5
,
sha1
from
compress.conf
import
settings
from
compress.storage
import
storage
from
compress.versioning
import
VersioningBase
...
...
@@ -26,9 +27,9 @@ class HashVersioningBase(VersioningBase):
def
read_file
(
self
,
path
):
"""Read file content in binary mode"""
f
=
open
(
path
,
'rb'
)
content
=
f
.
read
()
f
.
close
()
f
ile
=
storage
.
open
(
path
,
'rb'
)
content
=
f
ile
.
read
()
f
ile
.
close
()
return
content
def
version
(
self
,
paths
):
...
...
compress/versioning/mtime/__init__.py
View file @
2df0ec93
import
os
import
time
from
compress.storage
import
storage
from
compress.versioning
import
VersioningBase
...
...
@@ -7,9 +8,9 @@ class MTimeVersioning(VersioningBase):
def
version
(
self
,
paths
):
# Return the modification time for the newest source file
return
str
(
max
(
[
int
(
os
.
stat
(
path
)
.
st_mtime
)
for
path
in
paths
]
[
int
(
time
.
mktime
(
storage
.
modified_time
(
path
)
.
timetuple
())
)
for
path
in
paths
]
))
def
need_update
(
self
,
output_file
,
paths
,
version
):
output_filename
=
self
.
output_filename
(
output_file
,
version
)
return
(
int
(
os
.
stat
(
output_filename
)
.
st_mtime
)
<
int
(
version
)),
version
return
(
int
(
time
.
mktime
(
storage
.
modified_time
(
output_filename
)
.
timetuple
())
)
<
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