convert source code to pdf in python

 1 import os
 2 import sys
 3
 4 def find_file(root_dir, type):
 5     dirs_pool = [root_dir]
 6     dest_pool = []
 7
 8     def scan_dir(directory):
 9         entries = os.walk(directory)
10         for root, dirs, files in entries:
11             dirs_pool.extend([os.path.join(root, dir_entry) for dir_entry in dirs])
12             for file_entry in files:
13                 if type in str(file_entry)[-len(type):]:
14                     dest_pool.append(‘‘.join(os.path.join(root, file_entry)))
15
16     while dirs_pool:
17         scan_dir(dirs_pool.pop())
18     return dest_pool
19
20 def gen_ps(root_dir, type):
21     vim_cmd = ‘vim -me -e -c ":hardcopy >%.ps" -c ":q" ‘
22     ps2pdf_cmd = ‘ps2pdf {filename}.ps {filename}.pdf‘
23     dests = find_file(root_dir, type)
24     if not dests:
25         return
26     print ‘found these source code files:‘
27     for dest in dests:
28         print dest
29     print ‘begin generate ps files!‘
30     for dest in dests:
31         command = ‘‘.join([vim_cmd, dest])
32         print command
33         os.system(command)
34     for dest in dests:
35         command = ps2pdf_cmd.format(filename=dest)
36         print command
37         os.system(command)
38
39 if __name__ == ‘__main__‘:
40     if len(sys.argv) == 3:
41         gen_ps(sys.argv[1], sys.argv[2])
42     else:
43         print ‘usage: python code2pdf.py directory filetype\n‘ 44               ‘such as: python code2pdf.py /home/bruce/python .py‘
时间: 2024-12-16 14:33:22

convert source code to pdf in python的相关文章

python linecache source code

The source code of linecache.py from python 2.0 is here. from stat import * Get file information >>> filestat = os.stat('README.TXT') >>> filestat nt.stat_result(st_mode=33206, st_ino=0L, st_dev=0, st_nlink=0, st_uid=0, st_gid=0, st_size

Defining Python Source Code Encodings

Defining the Encoding Python will default to ASCII as standard encoding if no other encoding hints are given. To define a source code encoding, a magic comment must be placed into the source files either as first or second line in the file, such as:

Source Code Structure - Python 源码结构

Source Code Structure - Python 源码结构 Include 目录包含了 Python 提供的所有头文件, 如果用户需要用 C 或 C++ 编写自定义模块扩展 Python, 那么就需要用到这里提供的头文件. Lib 目录包含了 Python 自带的所有标准库, 其中的库都是用 Python 写的. Moudles 目录包含了所有用 C 语言写的模块, 是那些对速度要求非常严格的模块, 如 random, cStringIO 等. 然而一些对速度要求不高的模块,如 os

Classic Source Code Collected

收藏一些经典的源码,持续更新!!! 1.深度学习框架(Deep Learning Framework). A:Caffe (Convolutional Architecture for Fast Feature Embedding)Convolutional 由伯克利大学Yangqing Jia Ph.D开发的开源深度学习的代码. Homepage:http://caffe.berkeleyvision.org/ Paper:Caffe: Convolutional Architecture f

12 Source Code Profilers for C & C++

Source :http://open-tube.com/12-source-code-profilers-for-cc/ Code Profilers are very distinct from traditional debuggers. They are able to catch the trivial and non fatal coding errors which are often hard for humans to catch. These trivial bugs lat

CRC32 Source Code

/* The Quest Operating System * Copyright (C) 2005-2010 Richard West, Boston University * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Softwar

【开源】海看源代码统计工具 Haikan Source Code Counter

Haikan Source Code Counter 海看源代码统计工具 BY 杭州海看网络科技有限公司 ------------------- github上的地址: https://github.com/haikanwhf/HaikanSourceCodeCounter ------------------ 海看源代码统计工具V1.7.rar

Tips for newbie to read source code

作者:ll kid链接:https://zhuanlan.zhihu.com/p/23796485来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. This post is first posted on my WeChat public account: GeekArtT Reading source code is always one big part for software engineers. Just like the writers to learn

About building ant & install ant on centos7 {ant source code 1.94}

? ? ? ? ? ? ? hamcrest-junit-2.0.0.0.jar java-hamcrest-2.0.0.0.jar ? copy to ant-sourceCodeDir/lib/optimal ? ? ? ? About building ant & install ant on centos7 {ant source code 1.94}