Merge lp://staging/~bjornt/editmoin/factor-out-edit-function into lp://staging/editmoin

Proposed by Björn Tillenius
Status: Merged
Merge reported by: Gustavo Niemeyer
Merged at revision: not available
Proposed branch: lp://staging/~bjornt/editmoin/factor-out-edit-function
Merge into: lp://staging/editmoin
Diff against target: None lines
To merge this branch: bzr merge lp://staging/~bjornt/editmoin/factor-out-edit-function
Reviewer Review Type Date Requested Status
Gustavo Niemeyer Approve
Review via email: mp+4769@code.staging.launchpad.net
To post a comment you must log in.
Revision history for this message
Björn Tillenius (bjornt) wrote :

This branch factors out the functionality that actually edits the page at a shortcut URL into a separate function. This allows me to use editmoin functionality from with in a script. (Of course, having an editmoin.py that could be installed in the PYTHONPATH would be even better, but for now I can rename the editmoin file manually).

I wasn't sure whether to name to function editshortcut() or edit_shortcut(), but I went with the former to be consistent with editfile().

Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

Sorry for the delay Bjorn. I've splitted out the editing function using "edit" as a name. I had to redo the change because since you branched out quite a few things were introduced into this logic.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'editmoin'
2--- editmoin 2008-03-05 12:24:15 +0000
3+++ editmoin 2009-03-23 08:42:07 +0000
4@@ -376,6 +376,31 @@
5 else:
6 print message
7
8+
9+def editshortcut(shortcut, template=None, editfile_func=editfile):
10+ """Edit a Moin page at a shortcut path.
11+
12+ By default the editfile() function is used to actually edit the
13+ page, but a custom one can be passed in as the editfile_func
14+ parameter.
15+
16+ Return True if the page as edited, otherwise False.
17+ """
18+ url = translate_shortcut(shortcut)
19+ id = get_id(url)
20+ urlopener = get_urlopener(url, id)
21+ moinfile = fetchfile(urlopener, url, id, template)
22+ try:
23+ page_edited = editfile_func(moinfile)
24+ if page_edited:
25+ sendfile(urlopener, url, moinfile)
26+ else:
27+ sendcancel(urlopener, url, moinfile)
28+ finally:
29+ os.unlink(moinfile.filename)
30+ return page_edited
31+
32+
33 def main():
34 argv = sys.argv[1:]
35 template = None
36@@ -386,17 +411,7 @@
37 sys.stderr.write(USAGE)
38 sys.exit(1)
39 try:
40- url = translate_shortcut(argv[0])
41- id = get_id(url)
42- urlopener = get_urlopener(url, id)
43- moinfile = fetchfile(urlopener, url, id, template)
44- try:
45- if editfile(moinfile):
46- sendfile(urlopener, url, moinfile)
47- else:
48- sendcancel(urlopener, url, moinfile)
49- finally:
50- os.unlink(moinfile.filename)
51+ editshortcut(argv[0], template)
52 except (IOError, OSError, Error), e:
53 sys.stderr.write("error: %s\n" % str(e))
54 sys.exit(1)

Subscribers

People subscribed via source and target branches

to all changes: