X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=utils.py;h=81454d4435cbb188386499c2bb8bd2a23a165313;hb=f22f57084bb5a6c4b30cd2dfcd138c9976db7fbf;hp=96c61dbfc95d9e94476f6707d123fcb56614dbcb;hpb=c279afcedf5878810de6280d3cb45c62e04c416d;p=dak.git diff --git a/utils.py b/utils.py index 96c61dbf..81454d44 100644 --- a/utils.py +++ b/utils.py @@ -1,6 +1,6 @@ # Utility functions -# Copyright (C) 2000, 2001 James Troup -# $Id: utils.py,v 1.40 2002-03-14 14:12:04 ajt Exp $ +# Copyright (C) 2000, 2001, 2002 James Troup +# $Id: utils.py,v 1.42 2002-05-08 11:13:44 troup Exp $ # 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 @@ -57,10 +57,6 @@ def open_file(filename, mode='r'): raise cant_open_exc, filename return f -def touch_file(filename): - fd = os.open(filename, os.O_RDONLY | os.O_CREAT); - os.close(fd); - ###################################################################################### def our_raw_input(prompt=""): @@ -383,10 +379,13 @@ def regex_safe (s): ###################################################################################### # Perform a substition of template -def TemplateSubst(Map,Template): - for x in Map.keys(): - Template = string.replace(Template,x,Map[x]); - return Template; +def TemplateSubst(map,filename): + file = open_file(filename); + template = file.read(); + for x in map.keys(): + template = string.replace(template,x,map[x]); + file.close(); + return template; ###################################################################################### @@ -494,11 +493,18 @@ def result_join (original, sep = '\t'): list.append(original[i]); return string.join(list, sep); -def plural (x): - if x > 1: - return "s"; - else: - return ""; +################################################################################ + +def prefix_multi_line_string(str, prefix): + out = ""; + for line in string.split(str, '\n'): + line = string.strip(line); + if line: + out = out + "%s%s\n" % (prefix, line); + # Strip trailing new line + if out: + out = out[:-1]; + return out; ################################################################################