convert source code files to pdf format in python
2015-03-11 20:45
465 查看
import os import sys def find_file(root_dir, type): dirs_pool = [root_dir] dest_pool = [] def scan_dir(directory): entries = os.walk(directory) for root, dirs, files in entries: dirs_pool.extend([os.path.join(root, dir_entry) for dir_entry in dirs]) for file_entry in files: if type in str(file_entry)[-len(type):]: dest_pool.append(''.join(os.path.join(root, file_entry))) while dirs_pool: scan_dir(dirs_pool.pop()) return dest_pool def gen_ps(root_dir, type): vim_cmd = 'vim -me -e -c ":hardcopy >%.ps" -c ":q" ' ps2pdf_cmd = 'ps2pdf {filename}.ps {filename}.pdf' dests = find_file(root_dir, type) if not dests: return print 'found these source code files:' for dest in dests: print dest print 'begin generate ps files!' for dest in dests: command = ''.join([vim_cmd, dest]) print command os.system(command) for dest in dests: command = ps2pdf_cmd.format(filename=dest) print command os.system(command) if __name__ == '__main__': if len(sys.argv) == 3: gen_ps(sys.argv[1], sys.argv[2]) else: print 'usage: python code2pdf.py directory filetype\n' \ 'such as: python code2pdf.py /home/bruce/python .py'
相关文章推荐
- error C4335: Mac file format detected: please convert the source file to either DOS or UNIX format
- Android: How to download the latest zip Android Source Code easily and using it in Intellij
- How to compile and debug VLC player source code in eclipse IDE on Ubuntu 10.04 (lucid)
- how to compile source code of "Data Structures & Algorithm Analysis in Java" writen by Mark Allen Weiss
- 解决错误提示unable to invoke code completion due to errors in source cord.
- Convert video files from one format to another
- To use MuPDF source code in Android
- convert doc with images in to wiki format can only be on linux
- How to use "vi" edit the docs or source code files
- Convert source code to HTML
- Write a function to convert an IPv4 Address in string format to an unsigned integer
- Ctrl+Shift+F to format code in Eclipse
- Convert HTML Table to an Array in Python
- convert ps pcl emf wmf to pdf files using ghostscript
- From APK to readable java source code in 3 easy steps
- No source code is available for type javax.validation.ConstraintViolation<T>; did you forget to inh
- Convert SVG to PDF by using iText in Java(ZT)
- Only export to PDF format from ReportViewer add-in
- How to convert `ctime` to `datetime` in Python? - Stack Overflow
- Simple trick to convert Date format with timezone in Java!