Useful to search through various directories without duplicating the code.
Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
from stgit.commands.common import *
from stgit.utils import *
-from stgit import stack, git, basedir
+from stgit import stack, git, templates
help = 'exports a series of patches to <dir> (or patches)'
# get the template
if options.template:
- patch_tmpl_list = [options.template]
+ tmpl = file(options.template).read()
else:
- patch_tmpl_list = []
-
- patch_tmpl_list += [os.path.join(basedir.get(), 'patchexport.tmpl'),
- os.path.join(os.path.expanduser('~'), '.stgit', 'templates',
- 'patchexport.tmpl'),
- os.path.join(sys.prefix,
- 'share', 'stgit', 'templates', 'patchexport.tmpl')]
- tmpl = ''
- for patch_tmpl in patch_tmpl_list:
- if os.path.isfile(patch_tmpl):
- tmpl = file(patch_tmpl).read()
- break
+ tmpl = templates.get_template('patchexport.tmpl')
+ if not tmpl:
+ tmpl = ''
# note the base commit for this series
if not options.stdout:
from stgit.commands.common import *
from stgit.utils import *
-from stgit import stack, git, basedir, version
+from stgit import stack, git, version, templates
from stgit.config import config
if options.cover or options.edit:
# find the template file
if options.cover:
- tfile_list = [options.cover]
+ tmpl = file(options.template).read()
else:
- tfile_list = [os.path.join(basedir.get(), 'covermail.tmpl'),
- os.path.join(os.path.expanduser('~'), '.stgit', 'templates',
- 'covermail.tmpl'),
- os.path.join(sys.prefix,
- 'share', 'stgit', 'templates', 'covermail.tmpl')]
-
- tmpl = None
- for tfile in tfile_list:
- if os.path.isfile(tfile):
- tmpl = file(tfile).read()
- break
- if not tmpl:
- raise CmdException, 'No cover message template file found'
+ tmpl = templates.get_template('covermail.tmpl')
+ if not tmpl:
+ raise CmdException, 'No cover message template file found'
msg_id = email.Utils.make_msgid('stgit')
msg = __build_cover(tmpl, total_nr, msg_id, options)
# send the patches
if options.template:
- tfile_list = [options.template]
+ tmpl = file(options.template).read()
else:
- tfile_list = [os.path.join(basedir.get(), 'patchmail.tmpl'),
- os.path.join(os.path.expanduser('~'), '.stgit', 'templates',
- 'patchmail.tmpl'),
- os.path.join(sys.prefix,
- 'share', 'stgit', 'templates', 'patchmail.tmpl')]
- tmpl = None
- for tfile in tfile_list:
- if os.path.isfile(tfile):
- tmpl = file(tfile).read()
- break
- if not tmpl:
- raise CmdException, 'No e-mail template file found'
+ tmpl = templates.get_template('patchmail.tmpl')
+ if not tmpl:
+ raise CmdException, 'No e-mail template file found'
for (p, patch_nr) in zip(patches, range(1, len(patches) + 1)):
msg_id = email.Utils.make_msgid('stgit')
Create a new, empty patch and make it the topmost one. If the
'--message' option is not passed, an editor is invoked with the
-.git/patchdescr.tmpl file used a as template, together with generated
-lines. By default, the local changes in the working tree are not included
-in the patch. A 'refresh' command is needed for this."""
+.git/patchdescr.tmpl, ~/.stgit/templates/patchdescr.tmpl or
+/usr/share/stgit/templates/patchdescr.tmpl file used a as template,
+together with generated lines. By default, the local changes in the
+working tree are not included in the patch. A 'refresh' command is
+needed for this."""
options = [make_option('-m', '--message',
help = 'use MESSAGE as the patch description'),
import sys, os
from stgit.utils import *
-from stgit import git, basedir
+from stgit import git, basedir, templates
from stgit.config import config
def edit_file(series, line, comment, show_patch = True):
fname = '.stgit.msg'
- tmpl = os.path.join(basedir.get(), 'patchdescr.tmpl')
+ tmpl = templates.get_template('patchdescr.tmpl')
f = file(fname, 'w+')
if line:
print >> f, line
- elif os.path.isfile(tmpl):
- print >> f, file(tmpl).read().rstrip()
+ elif tmpl:
+ print >> f, tmpl,
else:
print >> f
print >> f, __comment_prefix, comment
--- /dev/null
+"""Template files look-up
+"""
+
+__copyright__ = """
+Copyright (C) 2006, Catalin Marinas <catalin.marinas@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License version 2 as
+published by the Free Software Foundation.
+
+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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+"""
+
+import sys, os
+
+from stgit import basedir
+
+
+def get_template(tfile):
+ """Return the string in the template file passed as argument or
+ None if the file wasn't found.
+ """
+ tmpl_list = [ os.path.join(basedir.get(), tfile),
+ os.path.join(os.path.expanduser('~'), '.stgit', 'templates',
+ tfile),
+ os.path.join(sys.prefix, 'share', 'stgit', 'templates',
+ tfile) ]
+
+ tmpl = None
+ for t in tmpl_list:
+ if os.path.isfile(t):
+ tmpl = file(t).read()
+ break
+
+ return tmpl