changeset 5208:fc44e2ec2b64

pytt: new package.
author Jan Nieuwenhuizen <janneke@gnu.org>
date Mon, 06 Apr 2009 16:27:20 +0200
parents 94aeca28b98e
children e4d443502bbb
files gub/specs/pytt.py sourcefiles/pytt.py
diffstat 2 files changed, 64 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gub/specs/pytt.py	Mon Apr 06 16:27:20 2009 +0200
@@ -0,0 +1,10 @@
+from gub import build
+from gub import misc
+
+class Pytt (build.NullBuild):
+    source = 'url://host/pytt-1.0.tar.gz'
+    def _get_build_dependencies (self):
+        return ['tools::python']
+    def install (self):
+        build.NullBuild.install (self)
+        misc.dump_python_script (self, '%(install_prefix)s/bin', 'pytt')
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sourcefiles/pytt.py	Mon Apr 06 16:27:20 2009 +0200
@@ -0,0 +1,54 @@
+#! @PYTHON@
+
+'''
+    Copyright (c) 2000--2009
+    Jan Nieuwenhuizen <janneke@gnu.org>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2, or (at your option)
+    any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+'''
+
+import os
+import re
+import stat
+import sys
+
+dry_run = False
+
+def pytt (from_re, to, file_name):
+    s = file (file_name).read ()
+    name = os.path.basename (file_name)
+    base, ext = os.path.splitext (name)
+    t = re.sub (from_re, to % locals (), s)
+    if s != t:
+        if dry_run:
+            sys.stdout.write (t)
+        else:
+            stat_info = os.stat (file_name)
+            mode = stat.S_IMODE (stat_info[stat.ST_MODE])
+            os.system ('mv --backup=t %(file_name)s %(file_name)s~' % locals ())
+            file (file_name, 'w').write (t)
+            os.chmod (file_name, mode)
+
+def main ():
+    from_re = re.compile (sys.argv[1], re.MULTILINE)
+    to = sys.argv[2]
+    if not sys.argv[3:] or sys.argv[3] == '-':
+        sys.stdout.write (re.sub (from_re, to, sys.stdin.read ()))
+    else:
+        for f in sys.argv[3:]:
+            pytt (from_re, to, f)
+    
+if __name__ == '__main__':
+    main ()