-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtasks.py
More file actions
132 lines (95 loc) · 2.88 KB
/
tasks.py
File metadata and controls
132 lines (95 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function
import os
from invoke import task
def norm_path(*parts):
return os.path.join(*parts).replace('\\', '/')
def rel_path(*parts):
return norm_path(*parts)
def rcc_cmd():
from Qt import _QtGui
qtdir = os.path.dirname(_QtGui.__file__)
potential_names = [
'pyrcc4', 'pyrcc4.exe', 'pyrcc4.bat', # PyQt4
'pyrcc5', 'pyrcc5.exe', 'pyrcc5.bat', # PyQt5
'pyside-rcc', 'pyside-rcc.exe', # PySide
'pyside2-rcc', 'pyside2-rcc.exe', # PySide
]
for name in potential_names:
potential_path = rel_path(qtdir, name)
if os.path.isfile(potential_path):
return potential_path
raise OSError('Could not find qt rcc...')
PYSIDE_PATH = os.path.expandvars('$VIRTUAL_ENV/lib/site-packages/PySide/')
SCSS_SRC = rel_path('construct_ui', 'resources', 'scss')
CSS_BLD = rel_path('construct_ui', 'resources', 'styles')
QTSASS_CMD = 'qtsass %s -o %s' % (SCSS_SRC, CSS_BLD)
QRC_SRC = rel_path('resources.qrc')
QRC_BLD = rel_path('construct_ui', '_resources.py')
QRC_CMD = (rcc_cmd() + ' %s -o %s') % (QRC_SRC, QRC_BLD)
QRC_TMPL = '''
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
{}
</qresource>
</RCC>
'''
QRC_FILE_TMPL = ' <file alias="{alias}">{path}</file>'
ICON_EXT = '.png'
ICONS_PATH = rel_path('construct_ui', 'resources', 'icons')
STYLE_EXT = '.css'
STYLES_PATH = rel_path('construct_ui', 'resources', 'styles')
def patch_qrcpy(resource):
'''Patch qrcpy file'''
import Qt
with open(resource, 'r') as f:
contents = f.read()
# Patch imports
contents = contents.replace(Qt.__binding__, 'Qt')
with open(resource, 'w') as f:
f.write(contents)
def generate_qrc():
'''Generate qrc file'''
lines = []
for file in os.listdir(ICONS_PATH):
name, ext = os.path.splitext(file)
if ext != ICON_EXT:
continue
line = QRC_FILE_TMPL.format(
alias=norm_path('icons', name),
path=norm_path(ICONS_PATH, file)
)
lines.append(line)
for file in os.listdir(STYLES_PATH):
name, ext = os.path.splitext(file)
if ext != STYLE_EXT:
continue
line = QRC_FILE_TMPL.format(
alias=norm_path('styles', name),
path=norm_path(STYLES_PATH, file)
)
lines.append(line)
return QRC_TMPL.format('\n'.join(lines))
@task
def build_css(ctx):
'''Build stylesheets'''
ctx.run(QTSASS_CMD)
@task
def build_qrc(ctx):
'''Build qresources'''
text = generate_qrc()
with open(QRC_SRC, 'w') as f:
f.write(text)
ctx.run(QRC_CMD)
patch_qrcpy(QRC_BLD)
os.remove(QRC_SRC)
@task
def build(ctx):
'''Build all resources'''
build_css(ctx)
build_qrc(ctx)
@task
def develop(ctx):
'''Build and watch resources'''
ctx.run(QTSASS_CMD + ' -w')