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
930bbc4d
Commit
930bbc4d
authored
Feb 22, 2012
by
Timothée Peignier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix writinh trouble with FinderStorage
parent
cc66882b
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
40 additions
and
26 deletions
+40
-26
pipeline/compilers/__init__.py
+9
-11
pipeline/compressors/__init__.py
+7
-7
pipeline/glob.py
+3
-3
pipeline/packager.py
+3
-3
pipeline/storage.py
+17
-1
tests/tests/compressor.py
+1
-1
No files found.
pipeline/compilers/__init__.py
View file @
930bbc4d
import
os
import
subprocess
from
django.core.files.base
import
ContentFile
from
django.utils.encoding
import
smart_str
from
pipeline.conf
import
settings
from
pipeline.storage
import
storage
from
pipeline.storage
import
default_
storage
from
pipeline.utils
import
to_class
...
...
@@ -22,10 +25,10 @@ class Compiler(object):
new_path
=
self
.
output_path
(
path
,
compiler
.
output_extension
)
content
=
self
.
read_file
(
path
)
try
:
compiled_content
=
compiler
.
compile_file
(
content
,
storage
.
path
(
path
))
compiled_content
=
compiler
.
compile_file
(
content
,
default_
storage
.
path
(
path
))
self
.
save_file
(
new_path
,
compiled_content
)
except
CompilerError
:
if
not
storage
.
exists
(
new_path
)
or
not
settings
.
PIPELINE
:
if
not
default_
storage
.
exists
(
new_path
)
or
not
settings
.
PIPELINE
:
raise
paths
[
index
]
=
new_path
return
paths
...
...
@@ -35,15 +38,13 @@ class Compiler(object):
return
'.'
.
join
((
path
[
0
],
extension
))
def
read_file
(
self
,
path
):
file
=
storage
.
open
(
path
,
'rb'
)
file
=
default_
storage
.
open
(
path
,
'rb'
)
content
=
file
.
read
()
file
.
close
()
return
content
def
save_file
(
self
,
path
,
content
):
file
=
storage
.
open
(
path
,
'wb'
)
file
.
write
(
content
)
file
.
close
()
return
default_storage
.
save
(
path
,
ContentFile
(
smart_str
(
content
)))
class
CompilerBase
(
object
):
...
...
@@ -57,10 +58,7 @@ class CompilerBase(object):
raise
NotImplementedError
def
save_file
(
self
,
path
,
content
):
file
=
storage
.
open
(
path
,
'wb'
)
file
.
write
(
content
)
file
.
close
()
return
path
return
default_storage
.
save
(
path
,
ContentFile
(
smart_str
(
content
)))
class
CompilerError
(
Exception
):
...
...
pipeline/compressors/__init__.py
View file @
930bbc4d
...
...
@@ -6,8 +6,8 @@ import subprocess
from
itertools
import
takewhile
from
pipeline.conf
import
settings
from
pipeline.storage
import
storage
from
pipeline.utils
import
filepath_to_uri
,
to_class
,
relpath
from
pipeline.storage
import
default_
storage
from
pipeline.utils
import
to_class
,
relpath
MAX_IMAGE_SIZE
=
32700
...
...
@@ -159,7 +159,7 @@ class Compressor(object):
font
=
ext
in
FONT_EXTS
if
not
variant
:
return
False
if
not
(
re
.
search
(
EMBEDDABLE
,
path
)
and
storage
.
exists
(
path
)):
if
not
(
re
.
search
(
EMBEDDABLE
,
path
)
and
default_
storage
.
exists
(
path
)):
return
False
if
not
ext
in
EMBED_EXTS
:
return
False
...
...
@@ -217,19 +217,19 @@ class Compressor(object):
given the path of the stylesheet that contains it.
"""
if
os
.
path
.
isabs
(
path
):
path
=
os
.
path
.
join
(
storage
.
location
,
path
)
path
=
os
.
path
.
join
(
default_
storage
.
location
,
path
)
else
:
path
=
os
.
path
.
join
(
start
,
path
)
return
os
.
path
.
normpath
(
path
)
def
relative_path
(
self
,
absolute_path
):
"""Rewrite paths relative to the output stylesheet path"""
absolute_path
=
self
.
absolute_path
(
absolute_path
,
storage
.
location
)
return
os
.
path
.
join
(
os
.
sep
,
relpath
(
absolute_path
,
storage
.
location
))
absolute_path
=
self
.
absolute_path
(
absolute_path
,
default_
storage
.
location
)
return
os
.
path
.
join
(
os
.
sep
,
relpath
(
absolute_path
,
default_
storage
.
location
))
def
read_file
(
self
,
path
):
"""Read file content in binary mode"""
file
=
storage
.
open
(
path
,
'rb'
)
file
=
default_
storage
.
open
(
path
,
'rb'
)
content
=
file
.
read
()
file
.
close
()
return
content
...
...
pipeline/glob.py
View file @
930bbc4d
...
...
@@ -2,7 +2,7 @@ import os
import
re
import
fnmatch
from
pipeline.storage
import
storage
from
pipeline.storage
import
default_
storage
__all__
=
[
"glob"
,
"iglob"
]
...
...
@@ -49,7 +49,7 @@ def iglob(pathname):
def
glob1
(
dirname
,
pattern
):
try
:
directories
,
files
=
storage
.
listdir
(
dirname
)
directories
,
files
=
default_
storage
.
listdir
(
dirname
)
names
=
directories
+
files
except
NotImplementedError
:
return
[]
...
...
@@ -59,7 +59,7 @@ def glob1(dirname, pattern):
def
glob0
(
dirname
,
basename
):
if
storage
.
exists
(
os
.
path
.
join
(
dirname
,
basename
)):
if
default_
storage
.
exists
(
os
.
path
.
join
(
dirname
,
basename
)):
return
[
basename
]
return
[]
...
...
pipeline/packager.py
View file @
930bbc4d
...
...
@@ -6,7 +6,7 @@ from pipeline.compilers import Compiler
from
pipeline.compressors
import
Compressor
from
pipeline.glob
import
glob
from
pipeline.signals
import
css_compressed
,
js_compressed
from
pipeline.storage
import
storage
from
pipeline.storage
import
default_
storage
class
Package
(
object
):
...
...
@@ -85,7 +85,7 @@ class Packager(object):
)
def
individual_url
(
self
,
filename
):
return
storage
.
url
(
filename
)
return
default_
storage
.
url
(
filename
)
def
pack_stylesheets
(
self
,
package
,
**
kwargs
):
return
self
.
pack
(
package
,
self
.
compressor
.
compress_css
,
css_compressed
,
...
...
@@ -113,7 +113,7 @@ class Packager(object):
return
self
.
compressor
.
compile_templates
(
package
.
templates
)
def
save_file
(
self
,
path
,
content
):
return
storage
.
save
(
path
,
ContentFile
(
smart_str
(
content
)))
return
default_
storage
.
save
(
path
,
ContentFile
(
smart_str
(
content
)))
def
create_packages
(
self
,
config
):
packages
=
{}
...
...
pipeline/storage.py
View file @
930bbc4d
import
os
try
:
from
staticfiles
import
finders
from
staticfiles.storage
import
CachedStaticFilesStorage
,
StaticFilesStorage
...
...
@@ -65,6 +67,20 @@ class BaseFinderStorage(PipelineStorage):
exists
=
super
(
BaseFinderStorage
,
self
)
.
exists
(
name
)
return
exists
def
listdir
(
self
,
path
):
for
finder
in
finders
.
get_finders
():
for
storage
in
finder
.
storages
.
values
():
try
:
return
storage
.
listdir
(
path
)
except
OSError
:
pass
def
_save
(
self
,
name
,
content
):
for
finder
in
finders
.
get_finders
():
for
path
,
storage
in
finder
.
list
([]):
if
os
.
path
.
dirname
(
name
)
in
path
:
return
storage
.
_save
(
name
,
content
)
class
PipelineFinderStorage
(
BaseFinderStorage
):
finders
=
finders
...
...
@@ -75,4 +91,4 @@ class DefaultStorage(LazyObject):
self
.
_wrapped
=
get_storage_class
(
settings
.
PIPELINE_STORAGE
)()
storage
=
DefaultStorage
()
default_
storage
=
DefaultStorage
()
tests/tests/compressor.py
View file @
930bbc4d
...
...
@@ -7,7 +7,7 @@ from django.test import TestCase
from
pipeline.compressors
import
Compressor
,
TEMPLATE_FUNC
from
pipeline.compressors.yui
import
YUICompressor
from
pipeline.storage
import
storage
from
pipeline.storage
import
default_storage
as
storage
class
CompressorTest
(
TestCase
):
...
...
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