From 60fee5268036c2f2deff681e75ff189b86650508 Mon Sep 17 00:00:00 2001 From: Seanmavley Date: Fri, 19 Dec 2014 14:29:22 +0000 Subject: [PATCH] .py files made PEP8 compliant --- ...-assets.py => render_gnome_shell_assets.py | 21 +++++++++-------- ...er-gtk3-assets.py => render_gtk3_assets.py | 22 ++++++++++++------ ...ts-hidpi.py => render_gtk3_assets_hidpi.py | 23 +++++++++++++------ ...ity-assets.py => render_metacity_assets.py | 21 ++++++++++++----- ...-unity-assets.py => render_unity_assets.py | 22 ++++++++++++------ 5 files changed, 73 insertions(+), 36 deletions(-) rename render-gnome-shell-assets.py => render_gnome_shell_assets.py (93%) rename render-gtk3-assets.py => render_gtk3_assets.py (93%) rename render-gtk3-assets-hidpi.py => render_gtk3_assets_hidpi.py (93%) rename render-metacity-assets.py => render_metacity_assets.py (94%) rename render-unity-assets.py => render_unity_assets.py (93%) diff --git a/render-gnome-shell-assets.py b/render_gnome_shell_assets.py similarity index 93% rename from render-gnome-shell-assets.py rename to render_gnome_shell_assets.py index 65dc3a0..4634968 100755 --- a/render-gnome-shell-assets.py +++ b/render_gnome_shell_assets.py @@ -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) \ No newline at end of file +main(SRC) diff --git a/render-gtk3-assets.py b/render_gtk3_assets.py similarity index 93% rename from render-gtk3-assets.py rename to render_gtk3_assets.py index 233932b..ef30c40 100755 --- a/render-gtk3-assets.py +++ b/render_gtk3_assets.py @@ -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) - - diff --git a/render-gtk3-assets-hidpi.py b/render_gtk3_assets_hidpi.py similarity index 93% rename from render-gtk3-assets-hidpi.py rename to render_gtk3_assets_hidpi.py index 0b573d3..e019e45 100755 --- a/render-gtk3-assets-hidpi.py +++ b/render_gtk3_assets_hidpi.py @@ -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) - - diff --git a/render-metacity-assets.py b/render_metacity_assets.py similarity index 94% rename from render-metacity-assets.py rename to render_metacity_assets.py index e37b2c6..fba0230 100755 --- a/render-metacity-assets.py +++ b/render_metacity_assets.py @@ -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) - - diff --git a/render-unity-assets.py b/render_unity_assets.py similarity index 93% rename from render-unity-assets.py rename to render_unity_assets.py index 0d2ddb8..d787875 100755 --- a/render-unity-assets.py +++ b/render_unity_assets.py @@ -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) - -