1 |
commit: d53882c162487c202140580c4e6f700bdd208ab9 |
2 |
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org> |
3 |
AuthorDate: Thu Aug 2 22:56:00 2012 +0000 |
4 |
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua> |
5 |
CommitDate: Thu Aug 2 22:56:00 2012 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=d53882c1 |
7 |
|
8 |
Add docstrings to changelog_highlight.py |
9 |
|
10 |
--- |
11 |
.../generic_metadata/changelog_highlight.py | 19 +++++++++++++++++++ |
12 |
1 files changed, 19 insertions(+), 0 deletions(-) |
13 |
|
14 |
diff --git a/gpackages/libs/package_info/generic_metadata/changelog_highlight.py b/gpackages/libs/package_info/generic_metadata/changelog_highlight.py |
15 |
index 5ccbd5c..5b2b503 100644 |
16 |
--- a/gpackages/libs/package_info/generic_metadata/changelog_highlight.py |
17 |
+++ b/gpackages/libs/package_info/generic_metadata/changelog_highlight.py |
18 |
@@ -37,6 +37,8 @@ Bug = String |
19 |
Link = Keyword |
20 |
|
21 |
class ChangelogLexer(RegexLexer): |
22 |
+ "Pygments changelog lexer" |
23 |
+ |
24 |
name = 'Changelog' |
25 |
aliases = ['changelog'] |
26 |
filenames = ['Changelog'] |
27 |
@@ -96,6 +98,8 @@ class ChangelogLexer(RegexLexer): |
28 |
} |
29 |
|
30 |
class ChangelogHtmlFormater(HtmlFormatter): |
31 |
+ "Pygments html changelog formater" |
32 |
+ |
33 |
def _format_lines(self, tokensource): |
34 |
""" |
35 |
Copyed from pygments source litle modified. |
36 |
@@ -167,6 +171,8 @@ class ChangelogHtmlFormater(HtmlFormatter): |
37 |
return value |
38 |
|
39 |
class ChangelogStyle(Style): |
40 |
+ "Pygments style for gentoo changelog" |
41 |
+ |
42 |
default_style = "" |
43 |
styles = { |
44 |
Comment: 'italic #888', |
45 |
@@ -182,18 +188,29 @@ class ChangelogStyle(Style): |
46 |
} |
47 |
|
48 |
def changelog_highlight(text): |
49 |
+ "Shortcut for generating highlighted changelog html output" |
50 |
return highlight(text, ChangelogLexer(), |
51 |
ChangelogHtmlFormater(style = ChangelogStyle)) |
52 |
|
53 |
def changelog_termial_highlight(text): |
54 |
+ """Shortcut for generating highlighted terminal changelog output |
55 |
+ Used for debuging lexer """ |
56 |
return highlight(text, ChangelogLexer(), |
57 |
Terminal256Formatter(style = ChangelogStyle)) |
58 |
|
59 |
def changelog_style_css(): |
60 |
+ "Shortcut for generating css style for pygments `ChangelogStyle`" |
61 |
f = ChangelogHtmlFormater(style = ChangelogStyle) |
62 |
return f.get_style_defs() |
63 |
|
64 |
def group_tokens(text): |
65 |
+ """Combine tokens to groups |
66 |
+ Args: |
67 |
+ text -- changelog text |
68 |
+ Yields: |
69 |
+ (group_type, group), where group_type are: `None`, `'version'` or \ |
70 |
+ `'message'` |
71 |
+ group are array of tuples (toke, value)""" |
72 |
c = ChangelogLexer() |
73 |
queue = deque() |
74 |
group_type = None |
75 |
@@ -247,9 +264,11 @@ def tokens_to_text(lex): |
76 |
return mystr |
77 |
|
78 |
def latest_message(text): |
79 |
+ "Return latest message text" |
80 |
return tokens_to_text(latest_message_group(text)) |
81 |
|
82 |
def latest_group_messages(text): |
83 |
+ "Returns latest messages like it done on packages.gentoo.org" |
84 |
groups = latest_group_messages_group(text) |
85 |
return tokens_to_text(tokensgroup_to_toknes(groups)) |