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'

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. HTML5入门7---"session的会话缓存"和"localStorage的cookie"缓存数据

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  2. Hibernate逍遥游记-第15章处理并发问题-002悲观锁

    1. 2. hibernate.dialect=org.hibernate.dialect.MySQLDialect hibernate.connection.driver_class=com.mys ...

  3. java:异常处理

    异常:编译正常,但运行出错,会中断正常指令流 RuntimeException:运行时异常 分为:uncheck exception.和check exception(除了RuntimeExcepti ...

  4. 机器学习 —— 概率图模型(Homework: Exact Inference)

    在前三周的作业中,我构造了概率图模型并调用第三方的求解器对器进行了求解,最终获得了每个随机变量的分布(有向图),最大后验分布(双向图).本周作业的主要内容就是自行编写概率图模型的求解器.实际上,从根本 ...

  5. 卷积神经网络Convolutional Neural Networks

    Convolutional Neural Networks NOTE: This tutorial is intended for advanced users of TensorFlow and a ...

  6. IOS基础框架

    GameKit 为游戏提供网络功能:点对点互联和游戏中的语音交流 AddressBook 提供访问用户联系人信息的功能 AddressBookUI 提供一个用户界面,用于显示存储在地址簿中的联系人信息 ...

  7. JSTL、EL、ONGL、Struts标签的区别与使用

     一.JSTL 来源 我们使用JSP开发信息展现非常方便,也可嵌入java代码用来实现相关逻辑,但同样带来了很多问题: jsp维护难度增加 出事提示不明确,不容易提示 分工不明确等 解决上面的问题可以 ...

  8. Atheros AR9485 ubuntu 10.04 驱动安装及networking disable问题解决

    Laptop: ACER Aspire 5733-6629 Wireless:Lite-on HB125, CHIPS: Atheros AR9485 Ubuntu: 10.04LTS (2.6.32 ...

  9. UVA 11916 Emoogle Grid(同余模)

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  10. [Codeforces676B]Pyramid of Glasses(递推,DP)

    题目链接:http://codeforces.com/problemset/problem/676/B 递推,dp(i, j)表示第i层第j个杯子,从第一层开始向下倒,和数塔一样的题.每个杯子1个时间 ...