Skip to content
Browse files

Add automatic version bumping script

Makefile default rule now calls `autobump` and `index` targets. To
use this, call `make` after changing any of the colour schemes.

The way it works is versions.log contains the md5 sums of the
color scheme files. The autobump script checks the old sum from
versions.log against the current color scheme file and if any of
them changed, it opens the color scheme and increments the version
number in it and then stores the newly computed sum (after the bump)
back into versions.log. When the `index` rule is run in the Makefile,
it updates the `index.json` and `index.json.md5` files based on the
changes.
  • Loading branch information...
1 parent ef70c41 commit 8cc75499a53e46c3bdbdb7f4eba43d91ddc487bf @codebrainz committed Jun 18, 2013
Showing with 104 additions and 5 deletions.
  1. +7 −5 Makefile
  2. +74 −0 scripts/autobump.py
  3. +23 −0 scripts/versions.log
View
12 Makefile
@@ -10,9 +10,7 @@ MISMATCH_MESSAGE = Warning: Possible wrong version of Geany installed
ARCHIVE_NAME = geany-themes-$(THEMES_VERSION).tar.bz2
ARCHIVE_TEMP_DIR = geany-themes-$(THEMES_VERSION)
-# dummy rule to handle default case, doesn't do anything useful
-all:
- @echo "Nothing to do, use \`make help' for info."
+all: autobump index
install:
mkdir -p $(COLORSCHEME_DIR)
@@ -23,9 +21,12 @@ uninstall:
# safety in case there's other stuff in there.
rm -f $(UNINSTALL_THEMES)
-index:
+index: scripts/versions.log
make -C index
+autobump: $(THEMES)
+ python scripts/autobump.py
+
clean:
make -C index clean
@@ -59,6 +60,7 @@ help:
@echo " make install - Installs all color scheme .conf files"
@echo " make uninstall - Uninstall tracked color scheme files"
@echo " make index - Regenerate the index/index.json file"
+ @echo " make autobump - Update scheme versions on change"
@echo " make dist - Create a .tar.bz2 package for release"
@echo " make ChangeLog - Update the ChangeLog file from Git log"
@echo ""
@@ -70,4 +72,4 @@ help:
@echo "For more up to date information, visit:"
@echo " https://github.com/geany/geany-themes"
-.PHONY: all install uninstall dist ChangeLog index clean help
+.PHONY: all install uninstall dist ChangeLog index autobump clean help
View
74 scripts/autobump.py
@@ -0,0 +1,74 @@
+#!/usr/bin/env python
+
+"""
+Automatically updates a color scheme's version number when the file
+is modified. Run this before committing the change(s) to the repo.
+"""
+
+import os
+import sys
+import hashlib
+
+def gen_sum(fn):
+ return hashlib.md5(open(fn).read()).hexdigest()
+
+def read_log(log_file):
+ entries = []
+ try:
+ contents = open(log_file, 'r').read()
+ except IOError:
+ contents = ''
+ for line in [l.strip() for l in contents.split('\n') if l.strip()]:
+ m,n = line.split('\t')
+ entries.append((n,m))
+ return entries
+
+def write_log(log_file, entries):
+ new_lines = []
+ for ent in entries:
+ new_lines.append('\t'.join((ent[1], ent[0])))
+ open(log_file, 'w').write('\n'.join(new_lines) + '\n')
+
+def bump_version(fn):
+ contents = open(fn).read()
+ lines = contents.split('\n')
+ new_lines = []
+ for line in lines:
+ line = line.rstrip()
+ if line.strip().startswith('version'):
+ k,v = line.split('=')
+ v = int(v.strip())
+ v += 1
+ new_lines.append('version=%d' % v)
+ print("Bumped version of '%s' from %d to %d" % (os.path.basename(fn), v-1, v))
+ else:
+ new_lines.append(line)
+ open(fn, 'w').write('\n'.join(new_lines))
+
+def check_scheme(entries, scheme_fn):
+ for i, ent in enumerate(entries):
+ n,m = ent
+ if n == os.path.basename(scheme_fn):
+ msum = gen_sum(scheme_fn)
+ if m != msum:
+ bump_version(scheme_fn)
+ entries[i] = (n, gen_sum(scheme_fn))
+ break
+ else:
+ entries.append((os.path.basename(scheme_fn), gen_sum(scheme_fn)))
+ return entries
+
+def main(args):
+ cur_dir = os.path.abspath(os.path.dirname(__file__))
+ root_dir = os.path.abspath(os.path.dirname(cur_dir))
+ scheme_dir = os.path.join(root_dir, 'colorschemes')
+ log_file = os.path.join(cur_dir, 'versions.log')
+ entries = read_log(log_file)
+ for fname in os.listdir(scheme_dir):
+ if not fname.endswith(".conf"): continue
+ path = os.path.join(scheme_dir, fname)
+ entries = check_scheme(entries, path)
+ write_log(log_file, entries)
+ return 0
+
+if __name__ == "__main__": sys.exit(main(sys.argv))
View
23 scripts/versions.log
@@ -0,0 +1,23 @@
+e65f709e475ba5480ae32d2be5ae3826 zenburn.conf
+c5af64e0f2627ba8b3e1ec8f519f88d2 mc.conf
+c61ead84fb2fba8bf1d27fb787a8f059 fluffy.conf
+a7511319de69a819e7edd6c60d90a686 oblivion2.conf
+2196d395b7669d6aa81dfbba95f08701 black.conf
+66ff10140d6c99c7ad38ddf6dd7f07a4 tango-light.conf
+6f55f721882b7c08e71b197c57a1c3dc solarized-dark.conf
+aab9502b99ac01bc4f90f3d5b5a5b8d8 slushpoppies.conf
+f35499a8cd643bd4159138adf5c35add tango-dark.conf
+303ab2befb4568b1e677e7615d601e81 dark.conf
+f0d3b817ee91646c1c9ecfe978d51cf6 retro.conf
+99b7663c11177e55dac5d232855a99b5 inkpot.conf
+f8968e4bd09c5f5c52f7de5577154582 bespin.conf
+e7a55e5c551e1dc1ca8f08cc121f44ce gedit.conf
+29dff713647db9f288d87423f32f0990 solarized-light.conf
+67188ade2cf5f81345c9cee2843d5512 vibrant-ink.conf
+8bbdfe4b1f7e5187d95d760cde19321c pygments.conf
+8af93bd5bec0a89acbd77ee468b30cf3 github.conf
+e766a25ea4c4417d840d9680586a3b6f monokai.conf
+40fa84812b22c97989d241d63bc84ead railcasts2.conf
+d7a2916b9d773c9e65a9cc60f10c4bfc tinge.conf
+f26daf0e6d9ae56a583d33fed60068b7 kugel.conf
+942a5d5197b98dc656dd91944f4f71a0 dark-fruit-salad.conf

0 comments on commit 8cc7549

Please sign in to comment.
Something went wrong with that request. Please try again.