Merge lp:~dholbach/help-app/1430336 into lp:~ubuntu-touch-coreapps-drivers/help-app/trunk

Proposed by Daniel Holbach
Status: Merged
Merged at revision: 93
Proposed branch: lp:~dholbach/help-app/1430336
Merge into: lp:~ubuntu-touch-coreapps-drivers/help-app/trunk
Diff against target: 133 lines (+63/-7)
4 files modified
HACKING (+2/-1)
debian/control (+2/-0)
edit-here/tests/test_files.py (+6/-0)
edit-here/translations.py (+53/-6)
To merge this branch: bzr merge lp:~dholbach/help-app/1430336
Reviewer Review Type Date Requested Status
Nicholas Skaggs (community) Approve
Review via email: mp+252566@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'HACKING'
2--- HACKING 2015-03-10 13:53:09 +0000
3+++ HACKING 2015-03-11 11:58:24 +0000
4@@ -78,7 +78,8 @@
5 Before you get started, run:
6
7 sudo apt install python-pelican po4a make bzr \
8- ubuntu-html5-ui-toolkit python3-polib
9+ ubuntu-html5-ui-toolkit python3-polib python3-magic \
10+ python3-markdown
11
12 This will install the necessary files, so you can build the app or web build
13 locally and check if your changes actually make sense and look and work well.
14
15=== modified file 'debian/control'
16--- debian/control 2015-03-09 12:01:16 +0000
17+++ debian/control 2015-03-11 11:58:24 +0000
18@@ -6,6 +6,8 @@
19 debhelper (>= 9),
20 po4a,
21 python-pelican (>= 3.5.0~),
22+ python3-magic,
23+ python3-markdown,
24 python3-polib,
25 # ubuntu-html5-ui-toolkit
26 Standards-Version: 3.9.6
27
28=== modified file 'edit-here/tests/test_files.py'
29--- edit-here/tests/test_files.py 2015-03-06 15:26:07 +0000
30+++ edit-here/tests/test_files.py 2015-03-11 11:58:24 +0000
31@@ -18,3 +18,9 @@
32 sizes = [os.stat(fn).st_size
33 for fn in self.translations.po.langs]
34 self.assertNotIn(0, sizes)
35+
36+ def test_markdown_files(self):
37+ fns = self.translations.documents.find_docs()
38+ checked_fns = [translations.verify_markdown_file(fn)
39+ for fn in fns]
40+ self.assertEqual(len(fns), checked_fns.count(True))
41
42=== modified file 'edit-here/translations.py'
43--- edit-here/translations.py 2015-03-10 17:16:10 +0000
44+++ edit-here/translations.py 2015-03-11 11:58:24 +0000
45@@ -6,6 +6,7 @@
46 import shutil
47 import subprocess
48 import sys
49+import tempfile
50
51
52 def require(package):
53@@ -18,7 +19,17 @@
54 except ImportError:
55 require('python3-polib')
56
57-from pelicanconf import PATH
58+try:
59+ import magic
60+except:
61+ require('python3-magic')
62+
63+try:
64+ import markdown
65+except:
66+ require('python3-markdown')
67+
68+from pelicanconf import PATH, MD_EXTENSIONS
69
70 # This defines how complete we expect translations to be before we
71 # generate HTML from them. Needs to be string.
72@@ -31,6 +42,38 @@
73
74 META_TAGS = ['[TOC]']
75
76+MD_MAGIC_FILE_TYPES = [
77+ 'ASCII text',
78+ 'UTF-8 Unicode text',
79+ 'UTF-8 Unicode text, with very long lines',
80+ ]
81+
82+
83+def _temp_write_markdown(fn):
84+ (ret, tmp) = tempfile.mkstemp()
85+ length = 0
86+ ret = True
87+ try:
88+ markdown.markdownFromFile(fn, extensions=MD_EXTENSIONS, output=tmp)
89+ except:
90+ print('Could not convert "%s" into Markdown.' % fn)
91+ ret = False
92+ if ret:
93+ length = len(open(tmp, 'r').read())
94+ os.remove(tmp)
95+ return (ret, length)
96+
97+
98+def verify_markdown_file(fn):
99+ ms = magic.open(magic.MAGIC_NONE)
100+ ms.load()
101+ if ms.file(fn) not in MD_MAGIC_FILE_TYPES:
102+ return False
103+ (ret, length) = _temp_write_markdown(fn)
104+ if not length:
105+ return False
106+ return ret
107+
108
109 def find_bcp47_code(gettext_code):
110 if gettext_code not in [c[0] for c in BCP47_OVERRIDES]:
111@@ -239,13 +282,17 @@
112
113 class Documents(object):
114 def __init__(self):
115- self.docs = []
116+ self.docs = [fn for fn in self.find_docs()
117+ if verify_markdown_file(fn)]
118+
119+ def find_docs(self):
120+ docs = []
121 for dirpath, dirnames, fns in os.walk(PATH):
122- for fn in [fn for fn in fns
123- if fn.endswith('.md')]:
124- fn = os.path.relpath(os.path.join(dirpath, fn),
125+ docs += [os.path.relpath(os.path.join(dirpath, fn),
126 os.path.join(PATH, '..'))
127- self.docs += [fn]
128+ for fn in fns
129+ if fn.endswith('.md')]
130+ return docs
131
132 def translated_doc_fn(self, fn, bcp47_code):
133 match = [doc for doc in self.docs

Subscribers

People subscribed via source and target branches