convert source code files to pdf format in python
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的更多相关文章
- 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 ...
- source code analyzer 功能强大的C/C++源代码分析软件 Celerity CRACK 破解版
特色 迅捷是一个功能强大的C/C++源代码分析软件.可以处理数百万行的源程序代码.支持标准及K&R风格的C/C++.对每一个打开的源代码工程,通过建立一个包含丰富交叉引用关系的数据库,显示其所 ...
- Visual Studio 2012,创建工程Build Driver,基于纯Source Code.
拿到一堆纯代码,怎么去Create Project,设置Include路径,lib路径,要不要Pre-compile技术,配置Project之间的依赖关系. SourcesConverter Bas ...
- Sound (audio file) player in java - working source code example
转载自:http://ganeshtiwaridotcomdotnp.blogspot.com/2011/12/sound-audio-file-player-in-java-working.html ...
- 编程等宽字体Source Code Pro(转)
Source Code Pro - 最佳的免费编程字体之一!来自 Adobe 公司的开源等宽字体下载 每一位程序员都有一套自己喜爱的代码编辑器与编程字体,譬如我们之前就推荐过一款"神 ...
- 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 ...
- How to build windows azure PowerShell Source Code
Download any version source code of Windows Azure Powershell from https://github.com/Azure/azure-sdk ...
- 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 ...
- Classic Source Code Collected
收藏一些经典的源码,持续更新!!! 1.深度学习框架(Deep Learning Framework). A:Caffe (Convolutional Architecture for Fast Fe ...
随机推荐
- pymongo 例子
import pymongo class dbUtil(object): def __init__(self, tablename='functional_testing'): con = pymon ...
- Sina App Engine(SAE)入门教程(4)- SaeVCode(验证码服务)使用
参考资料 SaeVCode api 文档 使用教程 所有的验证码原理都是生成一个vcode字符串,存到session中,和用户的输入进行比较判断,以下是一个使用验证码服务的完整实例: 首页index. ...
- Android:布局单位换算
一.px 像素,是屏幕上显示数据的最基本的点. 二.dpi dpi(Dots Per Inch):每英寸点数,也可称为像素密度,即屏幕对角线像素值÷英寸值 比如480x800分辨率4.0英寸的手机计算 ...
- 坑爹的Mysql
本想尝试下如何使用Spring来管理Hibernate的事务,当配置好Spring的配置文件后,进行插入数据,结果报错了,错误是: Mysql Field * doesn't have a defau ...
- Tomcat目录介绍以及运行时寻找class的顺序
来自:http://blog.csdn.net/lihai211/article/details/6651977 Tomcat下的文件目录 /bin:存放启动和关闭tomcat的脚本文件: /conf ...
- c# 使用 静态类+xml序列化 保存配置文件
namespace TVCorrectionDataProcess{ [XmlRoot(ElementName = "Config")] public class Co ...
- 撤销 git reset --hard HEAD~1
方法一: 1.先通过git reflog找到上一次的历史提交记录id,git如果没有特意设置,是会保存记录一段时间的(a few days or a month) 2.git reset --hard ...
- BZOJ 3142 数列(组合)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=3142 题意:给出n,K,m,p.求有多少长度为K的序列A,满足:(1)首项为正整数:(2 ...
- 12 Useful “df” Commands to Check Disk Space in Linux
On the internet you will find plenty of tools for checking disk space utilization in Linux. However, ...
- android中给TextView或者Button的文字添加阴影效果
1在代码中添加文字阴影 TextView 有一个方法 /** * Gives the text a shadow of the specified radius and color, the ...