Skip to content

Commit cb114ff

Browse files
author
Jason Ward
committed
refs #62: Small refactor, only one entry point now.
1 parent c73fa08 commit cb114ff

File tree

4 files changed

+24
-35
lines changed

4 files changed

+24
-35
lines changed

pydocx/__init__.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
from .parsers import Docx2Html, Docx2Markdown
23

34

@@ -9,3 +10,25 @@ def docx2markdown(path):
910
return Docx2Markdown(path).parsed
1011

1112
VERSION = '0.3.11'
13+
14+
15+
def main():
16+
try:
17+
parser_to_use = sys.argv[1]
18+
path_to_docx = sys.argv[2]
19+
path_to_html = sys.argv[3]
20+
except IndexError:
21+
print 'Must specify which parser as well as the file to convert and the name of the resulting file.' # noqa
22+
sys.exit()
23+
if parser_to_use == '--html':
24+
html = Docx2Html(path_to_docx).parsed
25+
elif parser_to_use == '--markdown':
26+
html = Docx2Markdown(path_to_docx).parsed
27+
else:
28+
print 'Only valid parsers are --html and --markdown'
29+
sys.exit()
30+
with open(path_to_html, 'w') as f:
31+
f.write(html)
32+
33+
if __name__ == '__main__':
34+
main()

pydocx/parsers/Docx2Html.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import base64
2-
import sys
32
import xml.sax.saxutils
43

54
from pydocx.DocxParser import DocxParser
@@ -204,18 +203,3 @@ def indent(self, text, just='', firstLine='', left='', right=''):
204203

205204
def break_tag(self):
206205
return '<br />'
207-
208-
209-
def main():
210-
try:
211-
path_to_docx = sys.argv[1]
212-
path_to_html = sys.argv[2]
213-
except IndexError:
214-
print 'Must specific the file to convert and the name of the resulting file.' # noqa
215-
sys.exit()
216-
html = Docx2Html(path_to_docx).parsed
217-
with open(path_to_html, 'w') as f:
218-
f.write(html)
219-
220-
if __name__ == '__main__':
221-
main()

pydocx/parsers/Docx2Markdown.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import sys
2-
31
from pydocx.DocxParser import DocxParser
42

53

@@ -26,18 +24,3 @@ def italics(self, text):
2624

2725
def underline(self, text):
2826
return '***' + text + '***'
29-
30-
31-
def main():
32-
try:
33-
path_to_docx = sys.argv[1]
34-
path_to_html = sys.argv[2]
35-
except IndexError:
36-
print 'Must specific the file to convert and the name of the resulting file.' # noqa
37-
sys.exit()
38-
html = Docx2Markdown(path_to_docx).parsed
39-
with open(path_to_html, 'w') as f:
40-
f.write(html)
41-
42-
if __name__ == '__main__':
43-
main()

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ def get_description():
5656
long_description=get_description(),
5757
entry_points={
5858
'console_scripts': [
59-
'pydocx.docx2html = pydocx.parsers.Docx2Html:main',
60-
'pydocx.docx2markdown = pydocx.parsers.Docx2Markdown:main',
59+
'pydocx = pydocx.__init__:main',
6160
],
6261
},
6362
)

0 commit comments

Comments
 (0)