Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gyuricska Milán
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f3fa489d
authored
Oct 01, 2014
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
circle: create a watch command
usage: ./manage.py watch
parent
8d8e851e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
36 deletions
+53
-36
circle/common/management/__init__.py
+0
-0
circle/common/management/commands/__init__.py
+0
-0
circle/common/management/commands/watch.py
+53
-36
No files found.
circle/common/management/__init__.py
0 → 100644
View file @
f3fa489d
circle/common/management/commands/__init__.py
0 → 100644
View file @
f3fa489d
circle/watch.py
→
circle/
common/management/commands/
watch.py
View file @
f3fa489d
import
subprocess
import
subprocess
import
os
import
os
import
pyinotify
import
pyinotify
from
django.core.management.base
import
BaseCommand
from
django.conf
import
settings
from
django.conf
import
settings
STATIC_FILES
=
u'--include-path={}'
.
format
(
':'
.
join
(
settings
.
STATICFILES_DIRS
))
STATIC_FILES
=
u'--include-path={}'
.
format
(
':'
.
join
(
settings
.
STATICFILES_DIRS
))
...
@@ -26,40 +28,55 @@ class LessUtils(object):
...
@@ -26,40 +28,55 @@ class LessUtils(object):
print
(
"Successfully compiled:
\n
%
s
\n
->
\n
%
s"
%
(
print
(
"Successfully compiled:
\n
%
s
\n
->
\n
%
s"
%
(
less_pathname
,
css_pathname
))
less_pathname
,
css_pathname
))
@staticmethod
def
initial_compile
():
""" Walks through the project looking for LESS files
and compiles them into CSS.
"""
for
root
,
dirs
,
files
in
os
.
walk
(
settings
.
SITE_ROOT
):
for
f
in
files
:
if
not
f
.
endswith
(
".less"
):
continue
relpath
=
os
.
path
.
relpath
(
root
,
settings
.
SITE_ROOT
)
if
relpath
.
startswith
((
"static_collected"
,
"bower_components"
)):
continue
less_pathname
=
"
%
s/
%
s"
%
(
root
,
f
)
css_pathname
=
LessUtils
.
less_path_to_css_path
(
less_pathname
)
LessUtils
.
compile_less
(
less_pathname
,
css_pathname
)
if
__name__
==
"__main__"
:
@staticmethod
# for first run compile everything
def
start_watch
():
print
(
"Initial LESS compiles"
)
""" Watches for changes in LESS files recursively from the
current_dir
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
project's root and compiles the files
"""
for
root
,
dirs
,
files
in
os
.
walk
(
"/home/cloud/circle/circle"
):
wm
=
pyinotify
.
WatchManager
()
for
f
in
files
:
if
not
f
.
endswith
(
".less"
):
class
EventHandler
(
pyinotify
.
ProcessEvent
):
continue
def
process_IN_MODIFY
(
self
,
event
):
if
not
event
.
name
.
endswith
(
".less"
):
relpath
=
os
.
path
.
relpath
(
root
,
current_dir
)
return
if
relpath
.
startswith
((
"static_collected"
,
"bower_components"
)):
continue
css_pathname
=
LessUtils
.
less_path_to_css_path
(
event
.
pathname
)
LessUtils
.
compile_less
(
event
.
pathname
,
css_pathname
)
less_pathname
=
"
%
s/
%
s"
%
(
root
,
f
)
css_pathname
=
LessUtils
.
less_path_to_css_path
(
less_pathname
)
handler
=
EventHandler
()
LessUtils
.
compile_less
(
less_pathname
,
css_pathname
)
notifier
=
pyinotify
.
Notifier
(
wm
,
handler
)
wm
.
add_watch
(
settings
.
SITE_ROOT
,
pyinotify
.
IN_MODIFY
,
rec
=
True
)
print
(
"
\n
%
s
\n
"
%
(
"="
*
30
))
notifier
.
loop
()
print
(
"End of initial LESS compiles
\n
"
)
# after first run watch less files
class
Command
(
BaseCommand
):
wm
=
pyinotify
.
WatchManager
()
help
=
"Compiles all LESS files then watches for changes."
class
EventHandler
(
pyinotify
.
ProcessEvent
):
def
handle
(
self
,
*
args
,
**
kwargs
):
def
process_IN_MODIFY
(
self
,
event
):
# for first run compile everything
if
not
event
.
name
.
endswith
(
".less"
):
print
(
"Initial LESS compiles"
)
return
LessUtils
.
initial_compile
()
print
(
"
\n
%
s
\n
"
%
(
"="
*
30
))
css_pathname
=
LessUtils
.
less_path_to_css_path
(
event
.
pathname
)
print
(
"End of initial LESS compiles
\n
"
)
LessUtils
.
compile_less
(
event
.
pathname
,
css_pathname
)
# after first run watch less files
handler
=
EventHandler
()
LessUtils
.
start_watch
()
notifier
=
pyinotify
.
Notifier
(
wm
,
handler
)
wm
.
add_watch
(
current_dir
,
pyinotify
.
IN_MODIFY
,
rec
=
True
)
notifier
.
loop
()
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