[geany/geany-themes] fdbfea: Improve machine API to the themes
Matthew Brush
git-noreply at xxxxx
Tue Jun 18 10:31:17 UTC 2013
Branch: refs/heads/master
Author: Matthew Brush <mbrush at codebrainz.ca>
Committer: Matthew Brush <mbrush at codebrainz.ca>
Date: Tue, 18 Jun 2013 10:31:17 UTC
Commit: fdbfeaf20609b045a6387796f6824cc42846da1a
https://github.com/geany/geany-themes/commit/fdbfeaf20609b045a6387796f6824cc42846da1a
Log Message:
-----------
Improve machine API to the themes
* Improve index/index.json
* Add MD5 sum of that file into index/index.json.md5
* Remove experimental index.conf and index.xml files from the build
* Remove genindex script and related template files
* Add screenshot-missing.png icon to screenshots dir
- From elementary-xfce icon theme (status/64/image-missing.png)
* Update index/README.md detailing the format/fields of the JSON file.
Modified Paths:
--------------
Makefile
index/Makefile
index/README.md
index/index.conf
index/index.json
index/index.json.md5
index/index.xml
screenshots/screenshot-missing.png
scripts/Makefile
scripts/genindex
scripts/index.conf.in
scripts/index.json.in
scripts/index.xml.in
scripts/mkindex.py
Modified: Makefile
10 files changed, 5 insertions(+), 5 deletions(-)
===================================================================
@@ -27,8 +27,11 @@ uninstall:
# safety in case there's other stuff in there.
rm -f $(UNINSTALL_THEMES)
-indices:
- make -C scripts indices
+index:
+ make -C index
+
+clean:
+ make -C index clean
colorsnormal:
python scripts/colornorm.py $(THEMES)
@@ -36,9 +39,6 @@ colorsnormal:
usedefaults:
python scripts/defaultify.py $(THEMES)
-clean:
- make -C scripts clean
-
ChangeLog:
git --no-pager log --format="%ai %aN %n%n%x09* %s%n" > ChangeLog
Modified: index/Makefile
15 files changed, 15 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,15 @@
+scheme_files = $(wildcard ../colorschemes/*.conf)
+screen_files = $(wildcard ../screenshots/*.png)
+
+all: index.json index.json.md5
+
+index.json: $(scheme_files) $(screen_files)
+ python ../scripts/mkindex.py > $@
+
+index.json.md5: index.json
+ md5sum $< > $@
+
+clean:
+ rm -f index.json*
+
+.PHONY: all clean
Modified: index/README.md
101 files changed, 71 insertions(+), 30 deletions(-)
===================================================================
@@ -1,39 +1,80 @@
-Geany Themes Index Files README
-===============================
+Geany Themes Index File README
+==============================
-The files here are auto-generated using the `indices` rule to the main
-`Makefile`. Like `make indices` should result in these index files being
-regenerated (if needed).
+The `index.json` file is auto-generated using the `make index` command.
+The `index` rule of the Makefile runs the `scripts/mkindex.py` script
+which reads the colour schemes' info, generates screenshot and download
+URLs, base64 encoded 64x64 thumbnails and stores it all into a JSON
+formatted text file.
-Whenever a color scheme changes it's supposed to increment its `version`
-key in the `theme_info` group. This changing version number, output into
-the destination index files, will allow clients to detect newer versions
-of the color schemes.
+File Format
+-----------
-There are 3 output formats: [GKeyFile][gkf], [XML][xml] and [JSON][json].
-Looking at the generated files should make it obvious how to parse them. The
-canonical source if these files is:
+The JSON file consists of a top-level dictionary where the keys are
+the theme "identifiers" (ie. name used in filenames and code). The
+identifiers are not necessarily useful to humans.
-* [index.conf][gkfidx]
-* [index.xml][xmlidx]
-* [index.json][jsonidx]
+### Theme Info Fields
-Barring some Github outtage or them banning these links, they point to where
-clients can find the index files.
+#### author
-If you have updated one or more color scheme `.conf` files, change into the
-root Geany-Themes directory and run:
+The author field contains a name and usually an email address, although
+the value may be an empty string as well (ie. unknown author). This
+string is meant to be human-readable.
- $ make indices
+#### colorscheme
-The generated index files are checked into the Geany-Themes Git repository
-so there will be a bit of noise whenever updating color scheme files. It
-might be beneficial to make one commit for the real changes and one for
-updating the generated files.
+This is the download URL of the color scheme `.conf` file. If the file
+this URL points to is downloaded into the user's colour scheme directory,
+the colour scheme will be available in Geany for user once it's restarted.
+This field will never be empty.
-[gkf]: http://developer.gnome.org/glib/stable/glib-Key-value-file-parser.html
-[xml]: http://www.w3.org/XML
-[json]: http://www.json.org
-[gkfidx]: https://raw.github.com/codebrainz/geany-themes/master/index/index.conf
-[xmlidx]: https://raw.github.com/codebrainz/geany-themes/master/index/index.xml
-[jsonidx]: https://raw.github.com/codebrainz/geany-themes/master/index/index.json
+#### description
+
+A short description of the theme or an empty string. The string is meant
+to be displayed to human beings.
+
+#### md5hash
+
+An MD5 hash of the colour scheme `.conf` file from the last time it was
+changed. This value can be used to check if a local scheme needs updating
+and/or to verify the integrity of the file that could be downloaded using
+the `colorscheme` URL field. This field will never be empty.
+
+#### name
+
+A human-readable name of the colour scheme meant to be display for example
+in a GUI label/widget. This field will never be empty.
+
+#### screenshot
+
+This is the download URL for a preview image of the colour scheme. The
+image will always be in PNG format and the resolution, although not
+guaranteed, will be large enough to give an idea of what the colour
+scheme looks like. This may be an empty string if the color scheme
+doesn't have a screenshot or it may be a generic "screenshot missing"
+image.
+
+#### thumbnail
+
+This is a thumbnail image, 64 pixels wide and 64 pixels high, in PNG
+format, base64 encoded (for storing in text file). This is a small icon
+of the preview screenshot suitable for displaying for example in a GUI
+list of schemes. This maybe be an empty string if the colour scheme
+doesn't have a screenshot or it maybe be a generic "screenshit missing"
+icon that is 64 pixels wide and tall.
+
+#### version
+
+This field contains a whole number that is incremented each time the
+theme is changed. You can compare this against installed color scheme
+versions to see if an update is available.
+
+<s>The version number is a sequence of one or more digits, optionally
+separated by periods/decimal points. The string will always contain
+only 0-9 and optional decimal points in between any of the numbers,
+for example "1.2.3", "123", "12.3", but never "..2", ".2.", "....", etc.
+The result of splitting the string on the decimal point and converting
+each component into an integer will always succeed and the string will
+never be empty. One or more of the numbers in the string will move in
+the upward direction when the colour scheme is modified.</s>
Modified: index/index.conf
157 files changed, 0 insertions(+), 157 deletions(-)
===================================================================
@@ -1,157 +0,0 @@
-# This file is auto-generated from `index.conf.in`, do not edit!
-#
-# The special repositories group, for color schemes `repo_name` for
-# screenshots `repo_name_screens`. Both point to a URI that when having the
-# color schemes name and extension will resolve to a file. The basename is
-# each color scheme's group name here, ex. [bespin] is bespin.conf and
-# bespin.png for color schemes and screenshots, respectively.
-[repositories]
-default=https://raw.github.com/codebrainz/geany-themes/master/colorschemes
-default_screens=https://github.com/codebrainz/geany-themes/raw/master/screenshots
-
-# Each theme follows the pattern:
-# [theme_name]
-# name=The Theme Name
-# desc=The description of the theme.
-# repos=repo_name
-# vers=42
-[bespin]
-name=Bespin
-desc=A port of the Bespin theme.
-repos=default
-version=1.22.0
-
-[black]
-name=Black Scheme
-desc=Black background, other colours
-repos=default
-version=1.22.0
-
-[dark-fruit-salad]
-name=Dark Fruit Salad
-desc=Low contrast theme ported from the set_geany_colors utility
-repos=default
-version=1.22.0
-
-[dark]
-name=Dark
-desc=Dark syntax colouring theme
-repos=default
-version=1.22.0
-
-[fluffy]
-name=Fluffy
-desc=A soft and downy color scheme.
-repos=default
-version=1.22.0
-
-[gedit]
-name=Gedit
-desc=A port of Gedit's default theme.
-repos=default
-version=1.22.0
-
-[github]
-name=GitHub
-desc=Similar to GitHub.com's highlighting colors.
-repos=default
-version=1.22.0
-
-[inkpot]
-name=InkPot
-desc=Based on the vim theme of the same name.
-repos=default
-version=1.22.0
-
-[kugel]
-name=Kugel
-desc=A dark, but not too dark with focus to be comfortable to the eyes.
-repos=default
-version=1.22.0
-
-[mc]
-name=Ralesk's MC
-desc=Midnight Commander-like scheme
-repos=default
-version=1.22.1
-
-[monokai]
-name=Monokai
-desc=It's warm, colorful and pleasing to the eyes
-repos=default
-version=1.0
-
-[oblivion2]
-name=Oblivion 2
-desc=Based on the Gedit color scheme Oblivion and the Dark Color Scheme with rearranged colors.
-repos=default
-version=1.22.0
-
-[pygments]
-name=Pygments
-desc=Default Pygments theme for Geany
-repos=default
-version=1.22.0
-
-[railcasts2]
-name=Railcasts 2
-desc=A port of railscasts2 from gedit-themes.
-repos=default
-version=1.22.0
-
-[retro]
-name=Retro
-desc=Inspired by old green screen terminals.
-repos=default
-version=0.01
-
-[slushpoppies]
-name=Slush and Poppies
-desc=A port of Slush and Poppies from gedit-themes.
-repos=default
-version=1.22.0
-
-[solarized-dark]
-name=Solarized (dark)
-desc=Dark Solarized theme for Geany
-repos=default
-version=1.22.0
-
-[solarized-light]
-name=Solarized (light)
-desc=Light Solarized theme for Geany
-repos=default
-version=1.22.0
-
-[tango-dark]
-name=Tango
-desc=Loosely based on the Dark theme, but Tangofied.
-repos=default
-version=1.22.0
-
-[tango-light]
-name=Tango Light
-desc=A light theme using Tango colors.
-repos=default
-version=1.22.0
-
-[tinge]
-name=Tinge
-desc=A tinge more tanginess
-repos=default
-version=1.22.0
-
-[vibrant-ink]
-name=Vibrant
-desc=Vibrant Ink Theme for Geany
-repos=default
-version=1.22.0
-
-[zenburn]
-name=Zenburn
-desc=A port of Zenburn from gedit-themes.
-repos=default
-version=1.22.0
-
-
-
Modified: index/index.json
375 files changed, 229 insertions(+), 146 deletions(-)
===================================================================
No diff available, check online
Modified: index/index.json.md5
1 files changed, 1 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1 @@
+909a1c759ba0bc8ea2181dc856c4c269 index.json
Modified: index/index.xml
196 files changed, 0 insertions(+), 196 deletions(-)
===================================================================
@@ -1,196 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- This file is auto-generated, do not edit! -->
-<index>
- <repos>
- <repo name="default"
- href="https://raw.github.com/codebrainz/geany-themes/master/colorschemes"
- screens="https://github.com/codebrainz/geany-themes/raw/master/screenshots"/>
- </repos>
- <themes>
- <theme id="bespin">
- <name>Bespin</name>
- <desc>A port of the Bespin theme.</desc>
- <repos>
- <repo>default</repo>
- </repos>
- <version>1.22.0</version>
- </theme>
- <theme id="black">
- <name>Black Scheme</name>
- <desc>Black background, other colours</desc>
- <repos>
- <repo>default</repo>
- </repos>
- <version>1.22.0</version>
- </theme>
- <theme id="dark-fruit-salad">
- <name>Dark Fruit Salad</name>
- <desc>Low contrast theme ported from the set_geany_colors utility</desc>
- <repos>
- <repo>default</repo>
- </repos>
- <version>1.22.0</version>
- </theme>
- <theme id="dark">
- <name>Dark</name>
- <desc>Dark syntax colouring theme</desc>
- <repos>
- <repo>default</repo>
- </repos>
- <version>1.22.0</version>
- </theme>
- <theme id="fluffy">
- <name>Fluffy</name>
- <desc>A soft and downy color scheme.</desc>
- <repos>
- <repo>default</repo>
- </repos>
- <version>1.22.0</version>
- </theme>
- <theme id="gedit">
- <name>Gedit</name>
- <desc>A port of Gedit's default theme.</desc>
- <repos>
- <repo>default</repo>
- </repos>
- <version>1.22.0</version>
- </theme>
- <theme id="github">
- <name>GitHub</name>
- <desc>Similar to GitHub.com's highlighting colors.</desc>
- <repos>
- <repo>default</repo>
- </repos>
- <version>1.22.0</version>
- </theme>
- <theme id="inkpot">
- <name>InkPot</name>
- <desc>Based on the vim theme of the same name.</desc>
- <repos>
- <repo>default</repo>
- </repos>
- <version>1.22.0</version>
- </theme>
- <theme id="kugel">
- <name>Kugel</name>
- <desc>A dark, but not too dark with focus to be comfortable to the eyes.</desc>
- <repos>
- <repo>default</repo>
- </repos>
- <version>1.22.0</version>
- </theme>
- <theme id="mc">
- <name>Ralesk's MC</name>
- <desc>Midnight Commander-like scheme</desc>
- <repos>
- <repo>default</repo>
- </repos>
- <version>1.22.1</version>
- </theme>
- <theme id="monokai">
- <name>Monokai</name>
- <desc>It's warm, colorful and pleasing to the eyes</desc>
- <repos>
- <repo>default</repo>
- </repos>
- <version>1.0</version>
- </theme>
- <theme id="oblivion2">
- <name>Oblivion 2</name>
- <desc>Based on the Gedit color scheme Oblivion and the Dark Color Scheme with rearranged colors.</desc>
- <repos>
- <repo>default</repo>
- </repos>
- <version>1.22.0</version>
- </theme>
- <theme id="pygments">
- <name>Pygments</name>
- <desc>Default Pygments theme for Geany</desc>
- <repos>
- <repo>default</repo>
- </repos>
- <version>1.22.0</version>
- </theme>
- <theme id="railcasts2">
- <name>Railcasts 2</name>
- <desc>A port of railscasts2 from gedit-themes.</desc>
- <repos>
- <repo>default</repo>
- </repos>
- <version>1.22.0</version>
- </theme>
- <theme id="retro">
- <name>Retro</name>
- <desc>Inspired by old green screen terminals.</desc>
- <repos>
- <repo>default</repo>
- </repos>
- <version>0.01</version>
- </theme>
- <theme id="slushpoppies">
- <name>Slush and Poppies</name>
- <desc>A port of Slush and Poppies from gedit-themes.</desc>
- <repos>
- <repo>default</repo>
- </repos>
- <version>1.22.0</version>
- </theme>
- <theme id="solarized-dark">
- <name>Solarized (dark)</name>
- <desc>Dark Solarized theme for Geany</desc>
- <repos>
- <repo>default</repo>
- </repos>
- <version>1.22.0</version>
- </theme>
- <theme id="solarized-light">
- <name>Solarized (light)</name>
- <desc>Light Solarized theme for Geany</desc>
- <repos>
- <repo>default</repo>
- </repos>
- <version>1.22.0</version>
- </theme>
- <theme id="tango-dark">
- <name>Tango</name>
- <desc>Loosely based on the Dark theme, but Tangofied.</desc>
- <repos>
- <repo>default</repo>
- </repos>
- <version>1.22.0</version>
- </theme>
- <theme id="tango-light">
- <name>Tango Light</name>
- <desc>A light theme using Tango colors.</desc>
- <repos>
- <repo>default</repo>
- </repos>
- <version>1.22.0</version>
- </theme>
- <theme id="tinge">
- <name>Tinge</name>
- <desc>A tinge more tanginess</desc>
- <repos>
- <repo>default</repo>
- </repos>
- <version>1.22.0</version>
- </theme>
- <theme id="vibrant-ink">
- <name>Vibrant</name>
- <desc>Vibrant Ink Theme for Geany</desc>
- <repos>
- <repo>default</repo>
- </repos>
- <version>1.22.0</version>
- </theme>
- <theme id="zenburn">
- <name>Zenburn</name>
- <desc>A port of Zenburn from gedit-themes.</desc>
- <repos>
- <repo>default</repo>
- </repos>
- <version>1.22.0</version>
- </theme>
- </themes>
-</index>
-
Modified: screenshots/screenshot-missing.png
0 files changed, 0 insertions(+), 0 deletions(-)
===================================================================
No diff available, check online
Modified: scripts/Makefile
16 files changed, 0 insertions(+), 16 deletions(-)
===================================================================
@@ -1,16 +0,0 @@
-
-indices: ../index/index.conf ../index/index.xml ../index/index.json
-
-../index/index.conf: index.conf.in
- python genindex $< ../colorschemes/*.conf > $@
-
-../index/index.xml: index.xml.in
- python genindex $< ../colorschemes/*.conf > $@
-
-../index/index.json: index.json.in
- python genindex $< ../colorschemes/*.conf > $@
-
-clean:
- rm -f ../index/index.conf ../index/index.xml ../index/index.json
-
-.PHONY: indices clean
Modified: scripts/genindex
109 files changed, 0 insertions(+), 109 deletions(-)
===================================================================
@@ -1,109 +0,0 @@
-#!/usr/bin/env python
-
-"""
-Generates the index files in the `index` directory. Determines format based
-on the input file's extension:
- 'conf.in' -> ../index/index.conf
- 'xml.in' -> ../index/index.xml
- 'json.in' -> ../index/index.json
-
-Usage: genindex index.ext.in COLORSCHEME_FILES...
-"""
-
-import os
-import sys
-try:
- from configparser import SafeConfigParser
-except ImportError:
- from ConfigParser import SafeConfigParser
-
-def usage(f):
- f.write("Usage: %s TEMPLATE COLOR_SCHEMES...\n" % os.path.basename(__file__))
-
-def gen_conf_code(title, name, desc, repos, vers):
- code = '[%s]\n' % title
- code += 'name=%s\n' % name
- code += 'desc=%s\n' % desc
- code += 'repos=%s\n' % ';'.join(repos)
- code += 'version=%s\n\n' % vers
- return code
-
-def gen_xml_code(title, name, desc, repos, vers):
- code = '\n <theme id="%s">\n' % title
- code += ' <name>%s</name>\n' % name
- code += ' <desc>%s</desc>\n' % desc
- code += ' <repos>\n'
- for repo in repos:
- code += ' <repo>%s</repo>\n' % repo
- code += ' </repos>\n'
- code += ' <version>%s</version>\n' % vers
- code += ' </theme>'
- return code
-
-def gen_json_code(title, name, desc, repos, vers):
- code = ' "%s": {\n' % title
- code += ' "name": "%s",\n' % name
- code += ' "desc": "%s",\n' % desc
- code += ' "repos": [%s],\n' % ','.join(['"%s"'%r for r in repos])
- code += ' "version": "%s"\n' % vers
- code += ' },\n'
- return code
-
-CODE_MAP = {
- "conf": gen_conf_code,
- "xml": gen_xml_code,
- "json": gen_json_code,
-}
-
-def main(args):
- if len(args) < 2:
- sys.stderr.write("error: no template file specified\n")
- usage(sys.stderr)
- return 1
- mode = ''
- tmpl_file = args[1]
- if tmpl_file.endswith('.conf.in'):
- mode = 'conf'
- elif tmpl_file.endswith('.xml.in'):
- mode = 'xml'
- elif tmpl_file.endswith('.json.in'):
- mode = 'json'
- else:
- sys.stderr.write('error: unknown template format for "%s"' % tmpl_file)
- return 2
- if len(args) < 3:
- sys.stderr.write("error: no color scheme(s) specified\n")
- usage(sys.stderr)
- return 3
- code = ''
- cs_files = args[2:]
- for cs_file in cs_files:
- conf = SafeConfigParser()
- conf.read(cs_file)
- if conf.has_section('theme_info'):
- fn = os.path.basename(cs_file)
- title = fn
- if fn.endswith(".conf"):
- title = fn[:-5]
- if conf.has_option('theme_info', 'name'):
- name = conf.get('theme_info', 'name')
- else:
- name = title
- if conf.has_option('theme_info', 'description'):
- desc = conf.get('theme_info', 'description')
- else:
- desc = ''
- repos = ['default']
- if conf.has_option('theme_info', 'version'):
- vers = conf.get('theme_info', 'version')
- else:
- vers = str(int(os.stat(cs_file).st_mtime))
- code += CODE_MAP[mode](title, name, desc, repos, vers)
- if mode == 'json' and code.endswith(',\n'):
- code = code[:-2] + '\n'
- tmpl_text = open(tmpl_file).read()
- tmpl_text = tmpl_text.replace("##themes##", code)
- print(tmpl_text)
- return 0
-
-if __name__ == "__main__": sys.exit(main(sys.argv))
Modified: scripts/index.conf.in
18 files changed, 0 insertions(+), 18 deletions(-)
===================================================================
@@ -1,18 +0,0 @@
-# This file is auto-generated from `index.conf.in`, do not edit!
-#
-# The special repositories group, for color schemes `repo_name` for
-# screenshots `repo_name_screens`. Both point to a URI that when having the
-# color schemes name and extension will resolve to a file. The basename is
-# each color scheme's group name here, ex. [bespin] is bespin.conf and
-# bespin.png for color schemes and screenshots, respectively.
-[repositories]
-default=https://raw.github.com/codebrainz/geany-themes/master/colorschemes
-default_screens=https://github.com/codebrainz/geany-themes/raw/master/screenshots
-
-# Each theme follows the pattern:
-# [theme_name]
-# name=The Theme Name
-# desc=The description of the theme.
-# repos=repo_name
-# vers=42
-##themes##
Modified: scripts/index.json.in
10 files changed, 0 insertions(+), 10 deletions(-)
===================================================================
@@ -1,10 +0,0 @@
-{
- "repos": {
- "default": {
- "src": "https://raw.github.com/codebrainz/geany-themes/master/colorschemes",
- "screens": "https://github.com/codebrainz/geany-themes/raw/master/screenshots"
- }
- },
- "themes": {
-##themes## }
-}
Modified: scripts/index.xml.in
11 files changed, 0 insertions(+), 11 deletions(-)
===================================================================
@@ -1,11 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- This file is auto-generated, do not edit! -->
-<index>
- <repos>
- <repo name="default"
- href="https://raw.github.com/codebrainz/geany-themes/master/colorschemes"
- screens="https://github.com/codebrainz/geany-themes/raw/master/screenshots"/>
- </repos>
- <themes>##themes##
- </themes>
-</index>
Modified: scripts/mkindex.py
102 files changed, 102 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,102 @@
+#!/usr/bin/env python
+
+'''
+Creates a JSON index file listing information about all of the color schemes.
+Note: requires Python Imaging Library (PIL), ex. 'python-imaging' Debian package.
+'''
+
+import os
+import sys
+import json
+import ConfigParser
+import hashlib
+import base64
+import StringIO
+import Image, ImageDraw, ImageOps, ImageFilter
+
+SCREENSHOT_BASE = 'https://raw.github.com/geany/geany-themes/master/screenshots/'
+SCHEMES_BASE = 'https://raw.github.com/geany/geany-themes/master/colorschemes/'
+
+def get_option(cp, group, key, default=None):
+ try: return cp.get(group, key)
+ except ConfigParser.Error: return default
+
+def generate_thumbnail(conf_fn, screenshot_dir='screenshots'):
+ base = os.path.splitext(os.path.basename(conf_fn))[0]
+ png_file = os.path.join(screenshot_dir, '%s.png' % base)
+
+ if not os.path.exists(png_file):
+ png_file = os.path.join(screenshot_dir, 'screenshot-missing.png')
+ img = Image.open(png_file)
+ output = StringIO.StringIO()
+ img.save(output, "PNG", optimize=True)
+ data = base64.b64encode(output.getvalue())
+ output.close()
+ return data
+ else:
+ img = Image.open(png_file)
+ img = img.crop((2,2,img.size[1]-2,img.size[1]-2))
+ img.thumbnail((64,64), Image.ANTIALIAS)
+#-- set to True to save thumbs into screenshots/.thumbs
+ do_thumbs = False
+ if do_thumbs:
+ thumb_dir = os.path.join(screenshot_dir, '.thumbs')
+ try:
+ os.makedirs(thumb_dir)
+ except OSError as e:
+ if e.errno != 17: raise
+ thumb_fn = os.path.join(thumb_dir, base + '.png')
+ img.save(thumb_fn, "PNG", optimize=True)
+#--
+ output = StringIO.StringIO()
+ img.save(output, "PNG", optimize=True)
+ data = base64.b64encode(output.getvalue())
+ output.close()
+
+ return data
+
+def create_index(themes_dir, screenshot_dir='screenshots'):
+ data = {}
+
+ for conf_file in os.listdir(themes_dir):
+
+ if not conf_file.endswith('.conf'):
+ continue
+
+ conf_file = os.path.join(themes_dir, conf_file)
+ cp = ConfigParser.ConfigParser()
+ cp.read(conf_file)
+
+ if not cp.has_section('theme_info'):
+ continue
+
+ scheme_name = '.'.join(os.path.basename(conf_file).split('.')[:-1])
+
+ try:
+ version = get_option(cp, 'theme_info', 'version', '0.0.0').split('.')
+ version = list(version + (['0']*3))[0:3]
+ except IndexError, TypeError:
+ version = ['0']*3
+
+ data[scheme_name] = {
+ 'name': get_option(cp, 'theme_info', 'name', 'Untitled'),
+ 'description': get_option(cp, 'theme_info', 'description', ''),
+ 'version': '.'.join(version),
+ 'author': get_option(cp, 'theme_info', 'author', 'Unknown Author'),
+ 'screenshot': '%s%s.png' % (SCREENSHOT_BASE, scheme_name),
+ 'colorscheme': '%s%s.conf' % (SCHEMES_BASE, scheme_name),
+ 'md5hash': hashlib.md5(open(conf_file).read()).hexdigest(),
+ 'thumbnail': generate_thumbnail(conf_file, screenshot_dir),
+ }
+
+ # json.dumps() leaves trailing whitespace on some lines, strip it off
+ data = json.dumps(data, indent=2, sort_keys=True).rstrip()
+ return '\n'.join([l.rstrip() for l in data.split('\n')]) + '\n'
+
+if __name__ == "__main__":
+ cur_dir = os.path.abspath(os.path.dirname(__file__))
+ root_dir = os.path.abspath(os.path.dirname(cur_dir))
+ screen_dir = os.path.join(root_dir, 'screenshots')
+ scheme_dir = os.path.join(root_dir, 'colorschemes')
+ index = create_index(scheme_dir, screen_dir)
+ sys.stdout.write(index)
--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).
More information about the Commits
mailing list