[geany/geany-themes] 8cc754: Add automatic version bumping script

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:      8cc75499a53e46c3bdbdb7f4eba43d91ddc487bf
             https://github.com/geany/geany-themes/commit/8cc75499a53e46c3bdbdb7f4eba43d91ddc487bf

Log Message:
-----------
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.


Modified Paths:
--------------
    Makefile
    scripts/autobump.py
    scripts/versions.log

Modified: Makefile
12 files changed, 7 insertions(+), 5 deletions(-)
===================================================================
@@ -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


Modified: scripts/autobump.py
74 files changed, 74 insertions(+), 0 deletions(-)
===================================================================
@@ -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))


Modified: scripts/versions.log
23 files changed, 23 insertions(+), 0 deletions(-)
===================================================================
@@ -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



--------------
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