annotate wikked/scm/base.py @ 500:d3cd7d8d6b25 default tip

web: Breaking changes in flask-login API.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 07 Jun 2020 00:56:00 -0700
parents ab47d3cf5e1e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
182
7533ffec1b5a Display only the name of the committer, if possible.
Ludovic Chabant <ludovic@chabant.com>
parents: 148
diff changeset
1 import re
7533ffec1b5a Display only the name of the committer, if possible.
Ludovic Chabant <ludovic@chabant.com>
parents: 148
diff changeset
2
131
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
3
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4 STATE_COMMITTED = 0
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
5 STATE_MODIFIED = 1
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
6 STATE_NEW = 2
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7 STATE_NAMES = ['committed', 'modified', 'new']
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
8
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
9 ACTION_ADD = 0
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
10 ACTION_DELETE = 1
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
11 ACTION_EDIT = 2
450
ab47d3cf5e1e scm: Slightly better object model for file/wiki history.
Ludovic Chabant <ludovic@chabant.com>
parents: 281
diff changeset
12 ACTION_OTHER = 3
ab47d3cf5e1e scm: Slightly better object model for file/wiki history.
Ludovic Chabant <ludovic@chabant.com>
parents: 281
diff changeset
13 ACTION_NAMES = ['add', 'delete', 'edit', 'other']
131
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
14
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
15
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
16 class SourceControl(object):
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
17 def __init__(self):
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
18 pass
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
19
216
062d5e6ddb87 Refactoring for better SQL abstraction and performance (hopefully):
Ludovic Chabant <ludovic@chabant.com>
parents: 182
diff changeset
20 def start(self, wiki):
218
fba20c625fb3 Added `wk init` command to create a new wiki.
Ludovic Chabant <ludovic@chabant.com>
parents: 216
diff changeset
21 pass
fba20c625fb3 Added `wk init` command to create a new wiki.
Ludovic Chabant <ludovic@chabant.com>
parents: 216
diff changeset
22
fba20c625fb3 Added `wk init` command to create a new wiki.
Ludovic Chabant <ludovic@chabant.com>
parents: 216
diff changeset
23 def init(self, wiki):
fba20c625fb3 Added `wk init` command to create a new wiki.
Ludovic Chabant <ludovic@chabant.com>
parents: 216
diff changeset
24 pass
fba20c625fb3 Added `wk init` command to create a new wiki.
Ludovic Chabant <ludovic@chabant.com>
parents: 216
diff changeset
25
fba20c625fb3 Added `wk init` command to create a new wiki.
Ludovic Chabant <ludovic@chabant.com>
parents: 216
diff changeset
26 def postInit(self):
fba20c625fb3 Added `wk init` command to create a new wiki.
Ludovic Chabant <ludovic@chabant.com>
parents: 216
diff changeset
27 pass
131
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
28
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
29 def getSpecialFilenames(self):
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
30 raise NotImplementedError()
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
31
281
163ba52e7b84 Add simple pagination to the wiki history page and API endpoint.
Ludovic Chabant <ludovic@chabant.com>
parents: 225
diff changeset
32 def getHistory(self, path=None, limit=10, after_rev=None):
131
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
33 raise NotImplementedError()
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
34
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
35 def getState(self, path):
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
36 raise NotImplementedError()
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
37
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
38 def getRevision(self, path, rev):
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
39 raise NotImplementedError()
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
40
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
41 def diff(self, path, rev1, rev2):
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
42 raise NotImplementedError()
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
43
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
44 def commit(self, paths, op_meta):
225
ebb12ff21cb2 Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents: 218
diff changeset
45 pass
131
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
46
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
47 def revert(self, paths=None):
225
ebb12ff21cb2 Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents: 218
diff changeset
48 pass
131
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
49
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
50
182
7533ffec1b5a Display only the name of the committer, if possible.
Ludovic Chabant <ludovic@chabant.com>
parents: 148
diff changeset
51 class Author(object):
7533ffec1b5a Display only the name of the committer, if possible.
Ludovic Chabant <ludovic@chabant.com>
parents: 148
diff changeset
52 def __init__(self, name=None, email=None):
7533ffec1b5a Display only the name of the committer, if possible.
Ludovic Chabant <ludovic@chabant.com>
parents: 148
diff changeset
53 self.name = name
7533ffec1b5a Display only the name of the committer, if possible.
Ludovic Chabant <ludovic@chabant.com>
parents: 148
diff changeset
54 self.email = email
7533ffec1b5a Display only the name of the committer, if possible.
Ludovic Chabant <ludovic@chabant.com>
parents: 148
diff changeset
55 if name is not None and email is None:
7533ffec1b5a Display only the name of the committer, if possible.
Ludovic Chabant <ludovic@chabant.com>
parents: 148
diff changeset
56 m = re.match(r'(?P<name>.+)\s+\<(?P<email>.+@.+\.\w+)\>', name)
7533ffec1b5a Display only the name of the committer, if possible.
Ludovic Chabant <ludovic@chabant.com>
parents: 148
diff changeset
57 if m is not None:
7533ffec1b5a Display only the name of the committer, if possible.
Ludovic Chabant <ludovic@chabant.com>
parents: 148
diff changeset
58 self.name = str(m.group('name'))
7533ffec1b5a Display only the name of the committer, if possible.
Ludovic Chabant <ludovic@chabant.com>
parents: 148
diff changeset
59 self.email = str(m.group('email'))
7533ffec1b5a Display only the name of the committer, if possible.
Ludovic Chabant <ludovic@chabant.com>
parents: 148
diff changeset
60
7533ffec1b5a Display only the name of the committer, if possible.
Ludovic Chabant <ludovic@chabant.com>
parents: 148
diff changeset
61 def __str__(self):
7533ffec1b5a Display only the name of the committer, if possible.
Ludovic Chabant <ludovic@chabant.com>
parents: 148
diff changeset
62 return '%s <%s>' % (self.name, self.email)
7533ffec1b5a Display only the name of the committer, if possible.
Ludovic Chabant <ludovic@chabant.com>
parents: 148
diff changeset
63
7533ffec1b5a Display only the name of the committer, if possible.
Ludovic Chabant <ludovic@chabant.com>
parents: 148
diff changeset
64
450
ab47d3cf5e1e scm: Slightly better object model for file/wiki history.
Ludovic Chabant <ludovic@chabant.com>
parents: 281
diff changeset
65 class FileRevision:
ab47d3cf5e1e scm: Slightly better object model for file/wiki history.
Ludovic Chabant <ludovic@chabant.com>
parents: 281
diff changeset
66 def __init__(self, path=None, action=None):
ab47d3cf5e1e scm: Slightly better object model for file/wiki history.
Ludovic Chabant <ludovic@chabant.com>
parents: 281
diff changeset
67 self.path = path
ab47d3cf5e1e scm: Slightly better object model for file/wiki history.
Ludovic Chabant <ludovic@chabant.com>
parents: 281
diff changeset
68 self.action = action
ab47d3cf5e1e scm: Slightly better object model for file/wiki history.
Ludovic Chabant <ludovic@chabant.com>
parents: 281
diff changeset
69 if action is None:
ab47d3cf5e1e scm: Slightly better object model for file/wiki history.
Ludovic Chabant <ludovic@chabant.com>
parents: 281
diff changeset
70 self.action = ACTION_OTHER
ab47d3cf5e1e scm: Slightly better object model for file/wiki history.
Ludovic Chabant <ludovic@chabant.com>
parents: 281
diff changeset
71
ab47d3cf5e1e scm: Slightly better object model for file/wiki history.
Ludovic Chabant <ludovic@chabant.com>
parents: 281
diff changeset
72
131
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
73 class Revision(object):
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
74 def __init__(self, rev_id=-1):
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
75 self.rev_id = rev_id
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
76 self.rev_name = rev_id
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
77 self.author = None
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
78 self.timestamp = 0
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
79 self.description = None
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
80 self.files = []
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
81
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
82 @property
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
83 def is_local(self):
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
84 return self.rev_id == -1
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
85
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
86 @property
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
87 def is_committed(self):
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
88 return self.rev_id != -1
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
89
450
ab47d3cf5e1e scm: Slightly better object model for file/wiki history.
Ludovic Chabant <ludovic@chabant.com>
parents: 281
diff changeset
90 def addFile(self, path, action=None):
ab47d3cf5e1e scm: Slightly better object model for file/wiki history.
Ludovic Chabant <ludovic@chabant.com>
parents: 281
diff changeset
91 self.files.append(FileRevision(path, action))
ab47d3cf5e1e scm: Slightly better object model for file/wiki history.
Ludovic Chabant <ludovic@chabant.com>
parents: 281
diff changeset
92
131
9d22cf4d2412 Massive change that should have been several smaller ones, but whatever:
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
93
148
f02e049d6546 Vaguely better error reporting for when editing a page fails.
Ludovic Chabant <ludovic@chabant.com>
parents: 131
diff changeset
94 class SourceControlError(Exception):
f02e049d6546 Vaguely better error reporting for when editing a page fails.
Ludovic Chabant <ludovic@chabant.com>
parents: 131
diff changeset
95 def __init__(self, operation, message, command, output, *args):
f02e049d6546 Vaguely better error reporting for when editing a page fails.
Ludovic Chabant <ludovic@chabant.com>
parents: 131
diff changeset
96 Exception.__init__(self, *args)
f02e049d6546 Vaguely better error reporting for when editing a page fails.
Ludovic Chabant <ludovic@chabant.com>
parents: 131
diff changeset
97 self.operation = operation
f02e049d6546 Vaguely better error reporting for when editing a page fails.
Ludovic Chabant <ludovic@chabant.com>
parents: 131
diff changeset
98 self.message = message
f02e049d6546 Vaguely better error reporting for when editing a page fails.
Ludovic Chabant <ludovic@chabant.com>
parents: 131
diff changeset
99 self.command = command
f02e049d6546 Vaguely better error reporting for when editing a page fails.
Ludovic Chabant <ludovic@chabant.com>
parents: 131
diff changeset
100 self.output = output
f02e049d6546 Vaguely better error reporting for when editing a page fails.
Ludovic Chabant <ludovic@chabant.com>
parents: 131
diff changeset
101
f02e049d6546 Vaguely better error reporting for when editing a page fails.
Ludovic Chabant <ludovic@chabant.com>
parents: 131
diff changeset
102 def __str__(self):
f02e049d6546 Vaguely better error reporting for when editing a page fails.
Ludovic Chabant <ludovic@chabant.com>
parents: 131
diff changeset
103 return "Error running '%s': %s\nCommand: %s\nOutput: %s" % (
f02e049d6546 Vaguely better error reporting for when editing a page fails.
Ludovic Chabant <ludovic@chabant.com>
parents: 131
diff changeset
104 self.operation, self.message, self.command, self.output)