Swaroop C H 12 éve
commit
dac2a13026
6 módosított fájl, 92 hozzáadás és 0 törlés
  1. 1 0
      .gitignore
  2. 5 0
      01-frontpage.md
  3. 5 0
      02-table-of-contents.md
  4. 19 0
      README.md
  5. 61 0
      fabfile.py
  6. 1 0
      requirements.txt

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+*.pyc

+ 5 - 0
01-frontpage.md

@@ -0,0 +1,5 @@
+# Python
+
+Choose your Python version:
+
+blah blah

+ 5 - 0
02-table-of-contents.md

@@ -0,0 +1,5 @@
+## Table of Contents
+
+1. Translations
+2. Preface
+3. Introduction

+ 19 - 0
README.md

@@ -0,0 +1,19 @@
+
+## Installation
+
+Install Pandoc from <http://johnmacfarlane.net/pandoc/installing.html>
+
+
+Install `pip` if not present already:
+    
+    sudo sh -c "curl -k -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py && python get-pip.py && rm get-pip.py"
+
+
+Install Python libraries needed:
+
+    sudo pip install -r requirements.txt
+
+
+Convert the source files into HTML files:
+
+    fab html

+ 61 - 0
fabfile.py

@@ -0,0 +1,61 @@
+#!/usr/bin/env python
+
+import os
+import glob
+import subprocess
+from fabric.api import local
+
+
+# The keys are the file names of the Pandoc source files.
+# e.g. '01-frontpage.md'
+# The values are the slugs of the WordPress pages
+# e.g. http://www.swaroopch.com/notes/Python_en-Table_of_Contents
+MARKDOWN_FILES = {
+    '01-frontpage.md' : 'Python',
+    '02-table-of-contents.md' : 'Python_en-Table_of_Contents',
+}
+
+
+def _markdown_to_html(source_text):
+    from_format = 'markdown'
+    to_format = 'html'
+
+    args = ['pandoc',
+            '-f', from_format,
+            '-t', to_format,
+            '-S']
+    p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+    output = p.communicate(source_text)[0]
+
+    # TODO Replace image URLs with uploaded AWS S3 public URLs
+
+    return output
+
+
+def html():
+    for m in MARKDOWN_FILES.keys():
+        converted_text = _markdown_to_html(open(m).read())
+        output_file_name = MARKDOWN_FILES[m] + ".html"
+        with open(output_file_name, 'w') as output:
+            output.write(converted_text)
+        local("open {}".format(output_file_name))
+
+
+def cleanup():
+    for m in MARKDOWN_FILES.keys():
+        output_file_name = MARKDOWN_FILES[m] + ".html"
+        if os.path.exists(output_file_name):
+            os.remove(output_file_name)
+
+
+def epub():
+    from_format = 'markdown'
+    to_format = 'epub'
+    output_file_name = 'byte_of_python.epub'
+
+    args = ['pandoc',
+            '-f', from_format,
+            '-t', to_format,
+            '-o', output_file_name,
+            '-S'] + MARKDOWN_FILES.keys()
+    local(' '.join(args))

+ 1 - 0
requirements.txt

@@ -0,0 +1 @@
+Fabric >= 1.4.3