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
9256848c
Commit
9256848c
authored
May 26, 2012
by
Timothée Peignier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use posixpath rather than os dependant os.path to deal with asset urls
parent
8ccc3204
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
53 deletions
+19
-53
pipeline/compressors/__init__.py
+11
-10
pipeline/utils.py
+8
-43
No files found.
pipeline/compressors/__init__.py
View file @
9256848c
import
base64
import
os
import
posixpath
import
re
import
subprocess
...
...
@@ -13,8 +14,8 @@ except ImportError:
from
django.contrib.staticfiles
import
finders
# noqa
from
pipeline.conf
import
settings
from
pipeline.utils
import
to_class
,
relpath
from
pipeline.storage
import
default_storage
from
pipeline.utils
import
to_class
,
relpath
URL_DETECTOR
=
r'url\([\'"]?([^\s)]+\.[a-z]+[\?\#\d\w]*)[\'"]?\)'
URL_REPLACER
=
r'url\(__EMBED__(.+?)(\?\d+)?\)'
...
...
@@ -144,16 +145,16 @@ class Compressor(object):
def
construct_asset_path
(
self
,
asset_path
,
css_path
,
output_filename
,
variant
=
None
):
"""Return a rewritten asset URL for a stylesheet"""
public_path
=
self
.
absolute_path
(
asset_path
,
os
.
path
.
dirname
(
css_path
))
public_path
=
self
.
absolute_path
(
asset_path
,
posix
path
.
dirname
(
css_path
))
if
self
.
embeddable
(
public_path
,
variant
):
return
"__EMBED__
%
s"
%
public_path
if
not
os
.
path
.
isabs
(
asset_path
):
if
not
posix
path
.
isabs
(
asset_path
):
asset_path
=
self
.
relative_path
(
public_path
,
output_filename
)
return
asset_path
def
embeddable
(
self
,
path
,
variant
):
"""Is the asset embeddable ?"""
name
,
ext
=
os
.
path
.
splitext
(
path
)
name
,
ext
=
posix
path
.
splitext
(
path
)
font
=
ext
in
FONT_EXTS
if
not
variant
:
return
False
...
...
@@ -191,16 +192,16 @@ class Compressor(object):
Return the absolute public path for an asset,
given the path of the stylesheet that contains it.
"""
if
os
.
path
.
isabs
(
path
):
path
=
os
.
path
.
join
(
default_storage
.
location
,
path
)
if
posix
path
.
isabs
(
path
):
path
=
posix
path
.
join
(
default_storage
.
location
,
path
)
else
:
path
=
os
.
path
.
join
(
start
,
path
)
return
os
.
path
.
normpath
(
path
)
path
=
posix
path
.
join
(
start
,
path
)
return
posix
path
.
normpath
(
path
)
def
relative_path
(
self
,
absolute_path
,
output_filename
):
"""Rewrite paths relative to the output stylesheet path"""
absolute_path
=
os
.
path
.
join
(
settings
.
PIPELINE_ROOT
,
absolute_path
)
output_path
=
os
.
path
.
join
(
settings
.
PIPELINE_ROOT
,
os
.
path
.
dirname
(
output_filename
))
absolute_path
=
posix
path
.
join
(
settings
.
PIPELINE_ROOT
,
absolute_path
)
output_path
=
posixpath
.
join
(
settings
.
PIPELINE_ROOT
,
posix
path
.
dirname
(
output_filename
))
return
relpath
(
absolute_path
,
output_path
)
def
read_file
(
self
,
path
):
...
...
pipeline/utils.py
View file @
9256848c
import
mimetypes
import
os
import
sys
import
posixpath
import
urllib
from
django.utils
import
importlib
...
...
@@ -34,52 +33,18 @@ def guess_type(path, default=None):
return
mimetype
def
_relpath_nt
(
path
,
start
=
os
.
path
.
curdir
):
"""Return a relative version of a path"""
if
not
path
:
raise
ValueError
(
"no path specified"
)
start_list
=
os
.
path
.
abspath
(
start
)
.
split
(
os
.
path
.
sep
)
path_list
=
os
.
path
.
abspath
(
path
)
.
split
(
os
.
path
.
sep
)
if
start_list
[
0
]
.
lower
()
!=
path_list
[
0
]
.
lower
():
unc_path
,
rest
=
os
.
path
.
splitunc
(
path
)
unc_start
,
rest
=
os
.
path
.
splitunc
(
start
)
if
bool
(
unc_path
)
^
bool
(
unc_start
):
raise
ValueError
(
"Cannot mix UNC and non-UNC paths (
%
s and
%
s)"
%
(
path
,
start
))
else
:
raise
ValueError
(
"path is on drive
%
s, start on drive
%
s"
%
(
path_list
[
0
],
start_list
[
0
]))
# Work out how much of the filepath is shared by start and path.
for
i
in
range
(
min
(
len
(
start_list
),
len
(
path_list
))):
if
start_list
[
i
]
.
lower
()
!=
path_list
[
i
]
.
lower
():
break
else
:
i
+=
1
rel_list
=
[
os
.
path
.
pardir
]
*
(
len
(
start_list
)
-
i
)
+
path_list
[
i
:]
if
not
rel_list
:
return
os
.
path
.
curdir
return
os
.
path
.
join
(
*
rel_list
)
def
_relpath_posix
(
path
,
start
=
os
.
path
.
curdir
):
def
relpath
(
path
,
start
=
posixpath
.
curdir
):
"""Return a relative version of a path"""
if
not
path
:
raise
ValueError
(
"no path specified"
)
start_list
=
os
.
path
.
abspath
(
start
)
.
split
(
os
.
path
.
sep
)
path_list
=
os
.
path
.
abspath
(
path
)
.
split
(
os
.
path
.
sep
)
start_list
=
posixpath
.
abspath
(
start
)
.
split
(
posix
path
.
sep
)
path_list
=
posixpath
.
abspath
(
path
)
.
split
(
posix
path
.
sep
)
# Work out how much of the filepath is shared by start and path.
i
=
len
(
os
.
path
.
commonprefix
([
start_list
,
path_list
]))
i
=
len
(
posix
path
.
commonprefix
([
start_list
,
path_list
]))
rel_list
=
[
os
.
path
.
pardir
]
*
(
len
(
start_list
)
-
i
)
+
path_list
[
i
:]
rel_list
=
[
posix
path
.
pardir
]
*
(
len
(
start_list
)
-
i
)
+
path_list
[
i
:]
if
not
rel_list
:
return
os
.
path
.
curdir
return
os
.
path
.
join
(
*
rel_list
)
if
os
.
path
is
sys
.
modules
.
get
(
'ntpath'
):
relpath
=
_relpath_nt
else
:
relpath
=
_relpath_posix
return
posixpath
.
curdir
return
posixpath
.
join
(
*
rel_list
)
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