.py files made PEP8 compliant
This commit is contained in:
parent
1dea4daeb2
commit
60fee52680
|
@ -1,7 +1,5 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
#
|
||||
|
||||
import os
|
||||
import sys
|
||||
import xml.sax
|
||||
|
@ -14,8 +12,8 @@ SRC = 'src/gnome-shell'
|
|||
|
||||
inkscape_process = None
|
||||
|
||||
def main(SRC):
|
||||
|
||||
def main(SRC):
|
||||
def optimize_png(png_file):
|
||||
if os.path.exists(OPTIPNG):
|
||||
process = subprocess.Popen([OPTIPNG, '-quiet', '-o7', png_file])
|
||||
|
@ -37,7 +35,10 @@ def main(SRC):
|
|||
output = output[1:]
|
||||
|
||||
def start_inkscape():
|
||||
process = subprocess.Popen([INKSCAPE, '--shell'], bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||
process = subprocess.Popen(
|
||||
[INKSCAPE, '--shell'], bufsize=0,
|
||||
stdin=subprocess.PIPE, stdout=subprocess.PIPE
|
||||
)
|
||||
wait_for_prompt(process)
|
||||
return process
|
||||
|
||||
|
@ -45,7 +46,9 @@ def main(SRC):
|
|||
global inkscape_process
|
||||
if inkscape_process is None:
|
||||
inkscape_process = start_inkscape()
|
||||
wait_for_prompt(inkscape_process, '%s -i %s -e %s' % (icon_file, rect, output_file))
|
||||
wait_for_prompt(inkscape_process,
|
||||
'%s -i %s -e %s' % (icon_file, rect, output_file)
|
||||
)
|
||||
optimize_png(output_file)
|
||||
|
||||
class ContentHandler(xml.sax.ContentHandler):
|
||||
|
@ -54,6 +57,7 @@ def main(SRC):
|
|||
LAYER = 2
|
||||
OTHER = 3
|
||||
TEXT = 4
|
||||
|
||||
def __init__(self, path, force=False, filter=None):
|
||||
self.stack = [self.ROOT]
|
||||
self.inside = [self.ROOT]
|
||||
|
@ -86,13 +90,13 @@ def main(SRC):
|
|||
if name == "text" and ('inkscape:label' in attrs) and attrs['inkscape:label'] == 'context':
|
||||
self.stack.append(self.TEXT)
|
||||
self.inside.append(self.TEXT)
|
||||
self.text='context'
|
||||
self.text = 'context'
|
||||
self.chars = ""
|
||||
return
|
||||
elif name == "text" and ('inkscape:label' in attrs) and attrs['inkscape:label'] == 'icon-name':
|
||||
self.stack.append(self.TEXT)
|
||||
self.inside.append(self.TEXT)
|
||||
self.text='icon-name'
|
||||
self.text = 'icon-name'
|
||||
self.chars = ""
|
||||
return
|
||||
elif name == "rect":
|
||||
|
@ -100,7 +104,6 @@ def main(SRC):
|
|||
|
||||
self.stack.append(self.OTHER)
|
||||
|
||||
|
||||
def endElement(self, name):
|
||||
stacked = self.stack.pop()
|
||||
if self.inside[-1] == stacked:
|
||||
|
@ -174,4 +177,4 @@ def main(SRC):
|
|||
print ("Error: No such file", file)
|
||||
sys.exit(1)
|
||||
|
||||
main(SRC)
|
||||
main(SRC)
|
|
@ -11,11 +11,13 @@ SRC = os.path.join('.', 'src/gtk3')
|
|||
|
||||
inkscape_process = None
|
||||
|
||||
|
||||
def optimize_png(png_file):
|
||||
if os.path.exists(OPTIPNG):
|
||||
process = subprocess.Popen([OPTIPNG, '-quiet', '-o7', png_file])
|
||||
process.wait()
|
||||
|
||||
|
||||
def wait_for_prompt(process, command=None):
|
||||
if command is not None:
|
||||
process.stdin.write((command+'\n').encode('utf-8'))
|
||||
|
@ -31,24 +33,33 @@ def wait_for_prompt(process, command=None):
|
|||
output += process.stdout.read(1)
|
||||
output = output[1:]
|
||||
|
||||
|
||||
def start_inkscape():
|
||||
process = subprocess.Popen([INKSCAPE, '--shell'], bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||
process = subprocess.Popen(
|
||||
[INKSCAPE, '--shell'],
|
||||
bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE
|
||||
)
|
||||
wait_for_prompt(process)
|
||||
return process
|
||||
|
||||
|
||||
def inkscape_render_rect(icon_file, rect, output_file):
|
||||
global inkscape_process
|
||||
if inkscape_process is None:
|
||||
inkscape_process = start_inkscape()
|
||||
wait_for_prompt(inkscape_process, '%s -i %s -e %s' % (icon_file, rect, output_file))
|
||||
wait_for_prompt(inkscape_process,
|
||||
'%s -i %s -e %s' %
|
||||
(icon_file, rect, output_file))
|
||||
optimize_png(output_file)
|
||||
|
||||
|
||||
class ContentHandler(xml.sax.ContentHandler):
|
||||
ROOT = 0
|
||||
SVG = 1
|
||||
LAYER = 2
|
||||
OTHER = 3
|
||||
TEXT = 4
|
||||
|
||||
def __init__(self, path, force=False, filter=None):
|
||||
self.stack = [self.ROOT]
|
||||
self.inside = [self.ROOT]
|
||||
|
@ -81,13 +92,13 @@ class ContentHandler(xml.sax.ContentHandler):
|
|||
if name == "text" and ('inkscape:label' in attrs) and attrs['inkscape:label'] == 'context':
|
||||
self.stack.append(self.TEXT)
|
||||
self.inside.append(self.TEXT)
|
||||
self.text='context'
|
||||
self.text = 'context'
|
||||
self.chars = ""
|
||||
return
|
||||
elif name == "text" and ('inkscape:label' in attrs) and attrs['inkscape:label'] == 'icon-name':
|
||||
self.stack.append(self.TEXT)
|
||||
self.inside.append(self.TEXT)
|
||||
self.text='icon-name'
|
||||
self.text = 'icon-name'
|
||||
self.chars = ""
|
||||
return
|
||||
elif name == "rect":
|
||||
|
@ -95,7 +106,6 @@ class ContentHandler(xml.sax.ContentHandler):
|
|||
|
||||
self.stack.append(self.OTHER)
|
||||
|
||||
|
||||
def endElement(self, name):
|
||||
stacked = self.stack.pop()
|
||||
if self.inside[-1] == stacked:
|
||||
|
@ -165,5 +175,3 @@ else:
|
|||
else:
|
||||
print ("Error: No such file", file)
|
||||
sys.exit(1)
|
||||
|
||||
|
|
@ -11,11 +11,13 @@ SRC = os.path.join('.', 'src/gtk3')
|
|||
|
||||
inkscape_process = None
|
||||
|
||||
|
||||
def optimize_png(png_file):
|
||||
if os.path.exists(OPTIPNG):
|
||||
process = subprocess.Popen([OPTIPNG, '-quiet', '-o7', png_file])
|
||||
process.wait()
|
||||
|
||||
|
||||
def wait_for_prompt(process, command=None):
|
||||
if command is not None:
|
||||
process.stdin.write((command+'\n').encode('utf-8'))
|
||||
|
@ -31,24 +33,34 @@ def wait_for_prompt(process, command=None):
|
|||
output += process.stdout.read(1)
|
||||
output = output[1:]
|
||||
|
||||
|
||||
def start_inkscape():
|
||||
process = subprocess.Popen([INKSCAPE, '--shell'], bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||
process = subprocess.Popen(
|
||||
[INKSCAPE, '--shell'], bufsize=0,
|
||||
stdin=subprocess.PIPE, stdout=subprocess.PIPE
|
||||
)
|
||||
wait_for_prompt(process)
|
||||
return process
|
||||
|
||||
|
||||
def inkscape_render_rect(icon_file, rect, output_file):
|
||||
global inkscape_process
|
||||
if inkscape_process is None:
|
||||
inkscape_process = start_inkscape()
|
||||
wait_for_prompt(inkscape_process, '--export-dpi=180 %s -i %s -e %s' % (icon_file, rect, output_file))
|
||||
wait_for_prompt(inkscape_process,
|
||||
'--export-dpi=180 %s -i %s -e %s'
|
||||
% (icon_file, rect, output_file)
|
||||
)
|
||||
optimize_png(output_file)
|
||||
|
||||
|
||||
class ContentHandler(xml.sax.ContentHandler):
|
||||
ROOT = 0
|
||||
SVG = 1
|
||||
LAYER = 2
|
||||
OTHER = 3
|
||||
TEXT = 4
|
||||
|
||||
def __init__(self, path, force=False, filter=None):
|
||||
self.stack = [self.ROOT]
|
||||
self.inside = [self.ROOT]
|
||||
|
@ -81,13 +93,13 @@ class ContentHandler(xml.sax.ContentHandler):
|
|||
if name == "text" and ('inkscape:label' in attrs) and attrs['inkscape:label'] == 'context':
|
||||
self.stack.append(self.TEXT)
|
||||
self.inside.append(self.TEXT)
|
||||
self.text='context'
|
||||
self.text = 'context'
|
||||
self.chars = ""
|
||||
return
|
||||
elif name == "text" and ('inkscape:label' in attrs) and attrs['inkscape:label'] == 'icon-name':
|
||||
self.stack.append(self.TEXT)
|
||||
self.inside.append(self.TEXT)
|
||||
self.text='icon-name'
|
||||
self.text = 'icon-name'
|
||||
self.chars = ""
|
||||
return
|
||||
elif name == "rect":
|
||||
|
@ -95,7 +107,6 @@ class ContentHandler(xml.sax.ContentHandler):
|
|||
|
||||
self.stack.append(self.OTHER)
|
||||
|
||||
|
||||
def endElement(self, name):
|
||||
stacked = self.stack.pop()
|
||||
if self.inside[-1] == stacked:
|
||||
|
@ -165,5 +176,3 @@ else:
|
|||
else:
|
||||
print ("Error: No such file", file)
|
||||
sys.exit(1)
|
||||
|
||||
|
|
@ -5,17 +5,20 @@ import sys
|
|||
import xml.sax
|
||||
import subprocess
|
||||
|
||||
|
||||
INKSCAPE = '/usr/bin/inkscape'
|
||||
OPTIPNG = '/usr/bin/optipng'
|
||||
SRC = os.path.join('.', 'src/metacity')
|
||||
|
||||
inkscape_process = None
|
||||
|
||||
|
||||
def optimize_png(png_file):
|
||||
if os.path.exists(OPTIPNG):
|
||||
process = subprocess.Popen([OPTIPNG, '-quiet', '-o7', png_file])
|
||||
process.wait()
|
||||
|
||||
|
||||
def wait_for_prompt(process, command=None):
|
||||
if command is not None:
|
||||
process.stdin.write((command+'\n').encode('utf-8'))
|
||||
|
@ -31,24 +34,33 @@ def wait_for_prompt(process, command=None):
|
|||
output += process.stdout.read(1)
|
||||
output = output[1:]
|
||||
|
||||
|
||||
def start_inkscape():
|
||||
process = subprocess.Popen([INKSCAPE, '--shell'], bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||
process = subprocess.Popen(
|
||||
[INKSCAPE, '--shell'],
|
||||
bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE
|
||||
)
|
||||
wait_for_prompt(process)
|
||||
return process
|
||||
|
||||
|
||||
def inkscape_render_rect(icon_file, rect, output_file):
|
||||
global inkscape_process
|
||||
if inkscape_process is None:
|
||||
inkscape_process = start_inkscape()
|
||||
wait_for_prompt(inkscape_process, '%s -i %s -e %s' % (icon_file, rect, output_file))
|
||||
wait_for_prompt(inkscape_process,
|
||||
'%s -i %s -e %s' % (icon_file, rect, output_file)
|
||||
)
|
||||
optimize_png(output_file)
|
||||
|
||||
|
||||
class ContentHandler(xml.sax.ContentHandler):
|
||||
ROOT = 0
|
||||
SVG = 1
|
||||
LAYER = 2
|
||||
OTHER = 3
|
||||
TEXT = 4
|
||||
|
||||
def __init__(self, path, force=False, filter=None):
|
||||
self.stack = [self.ROOT]
|
||||
self.inside = [self.ROOT]
|
||||
|
@ -87,7 +99,7 @@ class ContentHandler(xml.sax.ContentHandler):
|
|||
elif name == "text" and ('inkscape:label' in attrs) and attrs['inkscape:label'] == 'icon-name':
|
||||
self.stack.append(self.TEXT)
|
||||
self.inside.append(self.TEXT)
|
||||
self.text='icon-name'
|
||||
self.text = 'icon-name'
|
||||
self.chars = ""
|
||||
return
|
||||
elif name == "rect":
|
||||
|
@ -95,7 +107,6 @@ class ContentHandler(xml.sax.ContentHandler):
|
|||
|
||||
self.stack.append(self.OTHER)
|
||||
|
||||
|
||||
def endElement(self, name):
|
||||
stacked = self.stack.pop()
|
||||
if self.inside[-1] == stacked:
|
||||
|
@ -165,5 +176,3 @@ else:
|
|||
else:
|
||||
print ("Error: No such file", file)
|
||||
sys.exit(1)
|
||||
|
||||
|
|
@ -11,11 +11,13 @@ SRC = os.path.join('.', 'src/unity')
|
|||
|
||||
inkscape_process = None
|
||||
|
||||
|
||||
def optimize_png(png_file):
|
||||
if os.path.exists(OPTIPNG):
|
||||
process = subprocess.Popen([OPTIPNG, '-quiet', '-o7', png_file])
|
||||
process.wait()
|
||||
|
||||
|
||||
def wait_for_prompt(process, command=None):
|
||||
if command is not None:
|
||||
process.stdin.write((command+'\n').encode('utf-8'))
|
||||
|
@ -31,24 +33,33 @@ def wait_for_prompt(process, command=None):
|
|||
output += process.stdout.read(1)
|
||||
output = output[1:]
|
||||
|
||||
|
||||
def start_inkscape():
|
||||
process = subprocess.Popen([INKSCAPE, '--shell'], bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||
process = subprocess.Popen(
|
||||
[INKSCAPE, '--shell'],
|
||||
bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE
|
||||
)
|
||||
wait_for_prompt(process)
|
||||
return process
|
||||
|
||||
|
||||
def inkscape_render_rect(icon_file, rect, output_file):
|
||||
global inkscape_process
|
||||
if inkscape_process is None:
|
||||
inkscape_process = start_inkscape()
|
||||
wait_for_prompt(inkscape_process, '%s -i %s -e %s' % (icon_file, rect, output_file))
|
||||
wait_for_prompt(inkscape_process,
|
||||
'%s -i %s -e %s' % (icon_file, rect, output_file)
|
||||
)
|
||||
optimize_png(output_file)
|
||||
|
||||
|
||||
class ContentHandler(xml.sax.ContentHandler):
|
||||
ROOT = 0
|
||||
SVG = 1
|
||||
LAYER = 2
|
||||
OTHER = 3
|
||||
TEXT = 4
|
||||
|
||||
def __init__(self, path, force=False, filter=None):
|
||||
self.stack = [self.ROOT]
|
||||
self.inside = [self.ROOT]
|
||||
|
@ -81,13 +92,13 @@ class ContentHandler(xml.sax.ContentHandler):
|
|||
if name == "text" and ('inkscape:label' in attrs) and attrs['inkscape:label'] == 'context':
|
||||
self.stack.append(self.TEXT)
|
||||
self.inside.append(self.TEXT)
|
||||
self.text='context'
|
||||
self.text = 'context'
|
||||
self.chars = ""
|
||||
return
|
||||
elif name == "text" and ('inkscape:label' in attrs) and attrs['inkscape:label'] == 'icon-name':
|
||||
self.stack.append(self.TEXT)
|
||||
self.inside.append(self.TEXT)
|
||||
self.text='icon-name'
|
||||
self.text = 'icon-name'
|
||||
self.chars = ""
|
||||
return
|
||||
elif name == "rect":
|
||||
|
@ -95,7 +106,6 @@ class ContentHandler(xml.sax.ContentHandler):
|
|||
|
||||
self.stack.append(self.OTHER)
|
||||
|
||||
|
||||
def endElement(self, name):
|
||||
stacked = self.stack.pop()
|
||||
if self.inside[-1] == stacked:
|
||||
|
@ -165,5 +175,3 @@ else:
|
|||
else:
|
||||
print ("Error: No such file", file)
|
||||
sys.exit(1)
|
||||
|
||||
|
Loading…
Reference in New Issue