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 ...
随机推荐
- s.charAt()
public class ish{public static void main(String[]args){ String s="call me ishmae";System.o ...
- Could not connect to SMTP host: smtp.***.com, port: 465, response: -1
背景 在使用javamail进行邮件发送的时候,报错: Could not connect to SMTP host: smtp.***.com, port: 465, response: -1 原因 ...
- 59. Spiral Matrix II
题目: Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. ...
- Android UI开发第三十篇——使用Fragment构建灵活的桌面
http://www.lupaworld.com/article-222973-1.html 当我们设计应用程序时,希望能够尽最大限度的适配各种设备,包括4寸屏.7寸屏. 10寸屏等等,Android ...
- cmd修改系统时间
time 11:15:00 修改时间 date 2015/11/25 修改日期
- Java开发之单例设计模式
设计模式之单例模式: 一.单例模式实现特点:①单例类在整个应用程序中只能有一个实例(通过私有无参构造器实现):②单例类必须自己创建这个实例并且可供其他对象访问(通过静态公开的访问权限修饰的getIns ...
- 自己动手实现STL 02:构造析构的基本工具construct()和destroy()(stl_construct.h)
一.前言 上一篇,我先完成了对内存配置器的实现.然而后面在内存上的算法还依赖于两个全局函数,construct()和destroy(),前者负责在指定的内存上调用对象的构造函数,在内存上构造出对象.后 ...
- org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml at org.hibernate ...
- BZOJ_1025_[SHOI2009]_游戏_(素数表+最小公倍数+DP)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1025 分析 对于\(n\),转一圈回来之后其实是好几个环各转了整数圈.这些环中的数为\(1,2 ...
- Ajax、Comet与Websocket
从 http 协议说起 1996年IETF HTTP工作组发布了HTTP协议的1.0版本 ,到现在普遍使用的版本1.1,HTTP协议经历了17 年的发展.这种分布式.无状态.基于TCP的请求/响应式 ...