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'

convert source code files to pdf format in python的更多相关文章

  1. 3 Ways of JDK Source Code Attachment in Eclipse---reference

    You wanna look at a JVM class while you are coding and you cannot. Here is the solution. First of al ...

  2. source code analyzer 功能强大的C/C++源代码分析软件 Celerity CRACK 破解版

    特色 迅捷是一个功能强大的C/C++源代码分析软件.可以处理数百万行的源程序代码.支持标准及K&R风格的C/C++.对每一个打开的源代码工程,通过建立一个包含丰富交叉引用关系的数据库,显示其所 ...

  3. Visual Studio 2012,创建工程Build Driver,基于纯Source Code.

    拿到一堆纯代码,怎么去Create Project,设置Include路径,lib路径,要不要Pre-compile技术,配置Project之间的依赖关系. SourcesConverter  Bas ...

  4. Sound (audio file) player in java - working source code example

    转载自:http://ganeshtiwaridotcomdotnp.blogspot.com/2011/12/sound-audio-file-player-in-java-working.html ...

  5. 编程等宽字体Source Code Pro(转)

    Source Code Pro - 最佳的免费编程字体之一!来自 Adobe 公司的开源等宽字体下载     每一位程序员都有一套自己喜爱的代码编辑器与编程字体,譬如我们之前就推荐过一款"神 ...

  6. How to build the Robotics Library from source code on Windows

    The Robotics Library is an open source C++ library for robot kinematics, motion planning and control ...

  7. How to build windows azure PowerShell Source Code

    Download any version source code of Windows Azure Powershell from https://github.com/Azure/azure-sdk ...

  8. view class source code with JAD plugin in Eclipse

    The default class viewer doesn't decompile the class file so you cannot open and check the source co ...

  9. Classic Source Code Collected

    收藏一些经典的源码,持续更新!!! 1.深度学习框架(Deep Learning Framework). A:Caffe (Convolutional Architecture for Fast Fe ...

随机推荐

  1. python 利用pop3接收邮件并保存附件

    def SaveAttach():# login the pop3 server ,retrive the new mails ,and download the attachments dstdir ...

  2. 258. Add Digits

    题目: Given a non-negative integer num, repeatedly add all its digits until the result has only one di ...

  3. mysql shell

    mysql 查询10分钟以内的数据:select *from t_agent where int_last_login>=CURRENT_TIMESTAMP - INTERVAL 10 MINU ...

  4. 关于java.lang.NoClassDefFoundError: com/sun/mail/util/LineInputStream解决办法

    吉林的一个项目有个错误找了一天,有段报错是:   java.lang.NoClassDefFoundError: com/sun/mail/util/LineInputStream 1.遇到过两次,第 ...

  5. windows/ubuntu 文件共享之 Samba 配置

    很多时候需要在windows上和ubuntu 上共享文件,一直没怎么去找方法,得知Samba 可以实现在windows上访问linux的文件,这样一来要从windows文件放到linux中就方便了,听 ...

  6. 将Ftp添加到资源管理器中直接使用

    在资源管理器中,右键,添加网络位置. 然后输入ftp的url ftp://server2008 使用匿名方式登录

  7. webbrowser代理c#代码实现

    微软webbrowser控件也就是IE插件,他的所有功能就像IE类似,当然设置也是一样的,下面介绍下webbrowser如何设置代理,可不要用这个对抗广告联盟哦 You can change the ...

  8. 新浪实时股票数据接口http://hq.sinajs.cn/list=code

    股票数据的获取目前有如下两种方法可以获取:1. http/javascript接口取数据2. web-service接口 1.http/javascript接口取数据1.1Sina股票数据接口以大秦铁 ...

  9. uva 10453 - Make Palindrome(dp, 记录路径)

    题目 题意: 给一个字符串 ,判断最少插入多少个字符 使字符串成为回文串, 并输出回文串. 思路:先用dp判断需要个数, 再递归输出路径. #include <iostream> #inc ...

  10. iOS开发:告诉git不要跟踪UserInterfaceState.xcuserstate

    在xcode中使用git管理项目的技巧: 在多人协作开发的时候,每个开发者都会在项目中的某个目录生成一个 UserInterfaceState.xcuserstate 文件,这个文件大概每5s会刷新一 ...