Sphinx 是利用rst 文件 去產生 html、latex、pdf 等等的文件產生工具,
現行產生pdf 會碰到 中文字無處理的問題,解決方案:
1. rst 轉 Latex ,Latex 再轉 pdf
a. 找出 sphinx-quickstart 產生的project folder
b.在 project-folder/source 找出 conf.py
c.edit conf.py 找到以下並修改為:
latex_preamble = '''\usepackage{CJKutf8}\n\AtBeginDocument{\\begin{CJK}{UTF8}{bsmi}}\n\AtEndDocument{\end{CJK}}'''
source_encoding = 'utf-8'
d.再利用產出的 latex 文件去轉成 pdf
e.如何安裝 latex 與 CJK (Chineses/Japan/Korea) 字型 請參考:
在Windows 下使用LaTeX
2010年1月29日 星期五
Python 文件產生方法 - 工具篇
1.Code highlighter:
Pygments -http://pygments.org/
2.rStructure text 轉 PDF
rst2pdf -http://code.google.com/p/rst2pdf/
3.Docutils:Documentation Utilities
http://docutils.sourceforge.net/
4.Sphinx-Python document generator (會包含 docutils 的套件)
http://sphinx.pocoo.org/index.html
5.xhtml2pdf
http://www.xhtml2pdf.com/
6.ReportLab's Open Source Libraries
http://www.reportlab.com/software/opensource/
7.html5lib
Library for working with HTML documents
現行作法:
1. 用reStructureText 寫文件
2. rst2html.py 產生 html 檔 ------- 已完成.
3. html 檔用 pdfCreator 產生 PDF 檔 -- 已完成.
4. rst2pdf 產生 PDF 檔-已完成. 但需加入 styles 檔
5.xhtml2pdf.exe 產出的pdf 中文字碼為黑塊.
6.Sphinx 掛rst2pdf 的 pdfBuilder ,產生PDF 檔中文字碼為黑塊.
Pygments -http://pygments.org/
2.rStructure text 轉 PDF
rst2pdf -http://code.google.com/p/rst2pdf/
3.Docutils:Documentation Utilities
http://docutils.sourceforge.net/
4.Sphinx-Python document generator (會包含 docutils 的套件)
http://sphinx.pocoo.org/index.html
5.xhtml2pdf
http://www.xhtml2pdf.com/
6.ReportLab's Open Source Libraries
http://www.reportlab.com/software/opensource/
7.html5lib
Library for working with HTML documents
現行作法:
1. 用reStructureText 寫文件
2. rst2html.py 產生 html 檔 ------- 已完成.
3. html 檔用 pdfCreator 產生 PDF 檔 -- 已完成.
4. rst2pdf 產生 PDF 檔-已完成. 但需加入 styles 檔
5.xhtml2pdf.exe 產出的pdf 中文字碼為黑塊.
6.Sphinx 掛rst2pdf 的 pdfBuilder ,產生PDF 檔中文字碼為黑塊.
2010年1月27日 星期三
Python 文件產生方法 - rst2pdf 中文解法
目的: 使用讓 rst2pdf 去產生中文的 PDF 文件,rst2pdf 的功能是將 reStructureText 文件轉換成 PDF 檔
這份文件是說明如何讓它輸出 有中文的 PDF 檔
1.Q:如何安裝 rst2pdf:
A: easy_install rst2pdf
2.產生方式
解法1: 讓 rst2pdf 去讀外部的style 檔
rst2pdf -help 看到 -s 的作法
-s STYLESHEETS, --stylesheets=STYLESHEETS
A comma-separated list of custom stylesheets.Default=""
指令: rst2pdf -s xxx.style source.txt -o output.pdf
說明:
1.kaiu 應該是標楷體
2.source.txt 是 reStructureText 且需存成 utf-8 編碼的文件檔
3.xxx.style 的內容:
{
"embeddedFonts" : [["kaiu.ttf","kaiu.ttf","kaiu.ttf","kaiu.ttf"]],
"fontsAlias" : {
"stdFont": "kaiu",
"stdBold": "kaiu",
"stdItalic": "kaiu",
"stdBoldItalic": "kaiu",
"stdMono": "kaiu"
}
}
解法2: 修改 style.json
如: D:\Python26\Lib\site-packages\rst2pdf-0.12.3-py2.6.egg\rst2pdf\styles\styles.json
修改後內容:
"embeddedFonts" : [ ["kaiu.ttf","kaiu.ttf","kaiu.ttf","kaiu.ttf"]],
"stdFont": "kaiu",
"stdBold": "kaiu",
"stdItalic": "kaiu",
"stdBoldItalic": "kaiu",
"stdSans": "kaiu",
"stdSansBold": "kaiu",
"stdSansItalic": "kaiu",
"stdSansBoldItalic": "kaiu",
"stdMono": "kaiu",
"stdMonoItalic": "kaiu",
"stdMonoBold": "kaiu",
"stdMonoBoldItalic": "kaiu",
"stdSerif": "kaiu"
修改前內容:
"embeddedFonts" : [ ],
"stdFont": "Helvetica",
"stdBold": "Helvetica-Bold",
"stdItalic": "Helvetica-Oblique",
"stdBoldItalic": "Helvetica-BoldOblique",
"stdSans": "Helvetica",
"stdSansBold": "Helvetica-Bold",
"stdSansItalic": "Helvetica-Oblique",
"stdSansBoldItalic": "Helvetica-BoldOblique",
"stdMono": "Courier",
"stdMonoItalic": "Courier-Oblique",
"stdMonoBold": "Courier-Bold",
"stdMonoBoldItalic": "Courier-BoldOblique",
"stdSerif": "Times-Roman"
3.結論:
a.建議使用 解法 1 產生pdf檔,因為尚未解決 Sphinx 如何產生中文的PDF 檔
這份文件是說明如何讓它輸出 有中文的 PDF 檔
1.Q:如何安裝 rst2pdf:
A: easy_install rst2pdf
2.產生方式
解法1: 讓 rst2pdf 去讀外部的style 檔
rst2pdf -help 看到 -s 的作法
-s STYLESHEETS, --stylesheets=STYLESHEETS
A comma-separated list of custom stylesheets.Default=""
指令: rst2pdf -s xxx.style source.txt -o output.pdf
說明:
1.kaiu 應該是標楷體
2.source.txt 是 reStructureText 且需存成 utf-8 編碼的文件檔
3.xxx.style 的內容:
{
"embeddedFonts" : [["kaiu.ttf","kaiu.ttf","kaiu.ttf","kaiu.ttf"]],
"fontsAlias" : {
"stdFont": "kaiu",
"stdBold": "kaiu",
"stdItalic": "kaiu",
"stdBoldItalic": "kaiu",
"stdMono": "kaiu"
}
}
解法2: 修改 style.json
如: D:\Python26\Lib\site-packages\rst2pdf-0.12.3-py2.6.egg\rst2pdf\styles\styles.json
修改後內容:
"embeddedFonts" : [ ["kaiu.ttf","kaiu.ttf","kaiu.ttf","kaiu.ttf"]],
"stdFont": "kaiu",
"stdBold": "kaiu",
"stdItalic": "kaiu",
"stdBoldItalic": "kaiu",
"stdSans": "kaiu",
"stdSansBold": "kaiu",
"stdSansItalic": "kaiu",
"stdSansBoldItalic": "kaiu",
"stdMono": "kaiu",
"stdMonoItalic": "kaiu",
"stdMonoBold": "kaiu",
"stdMonoBoldItalic": "kaiu",
"stdSerif": "kaiu"
修改前內容:
"embeddedFonts" : [ ],
"stdFont": "Helvetica",
"stdBold": "Helvetica-Bold",
"stdItalic": "Helvetica-Oblique",
"stdBoldItalic": "Helvetica-BoldOblique",
"stdSans": "Helvetica",
"stdSansBold": "Helvetica-Bold",
"stdSansItalic": "Helvetica-Oblique",
"stdSansBoldItalic": "Helvetica-BoldOblique",
"stdMono": "Courier",
"stdMonoItalic": "Courier-Oblique",
"stdMonoBold": "Courier-Bold",
"stdMonoBoldItalic": "Courier-BoldOblique",
"stdSerif": "Times-Roman"
3.結論:
a.建議使用 解法 1 產生pdf檔,因為尚未解決 Sphinx 如何產生中文的PDF 檔
2010年1月14日 星期四
程式版本控管與管理流程之靠腰
很多IT 部門的軟體變更管理,會有資料管制人員負責去協助變更管理,其目的是避免程式開發人員自行變更而造成混亂,說明一下變更流程大概如下:
1.提出變更申請目的
2.AP 頭頭同意
3.附上變更軟體資料、測試報告等等。交付資料管制人員處理。
4.資料管制人員,檢查申請人所付資料是否符合?
要進入正式區軟體庫中的檔案是否與申請項目相同
要討論的是如何確認申請人所附檔案是正確的(第 4 點):
1.申請人比對正式區軟體庫內容並產生差異檔 - DiffData1
2.資料管制人員依申請人申請,比對正式區軟體庫內容並產生差異檔 -DiffData2
3.比對DiffData1 與DiffData2 內容是否一致
問題來了,Source Code 是可以這麼做,但若是非Source Code (如COM/DLL) 要如何管理呢?
subversion 的diff 檔比不出來呀,解法是產生檔案的checksum 去證明是兩者一致,
如你去網路Download 檔案,也都是會看到檔案提供者在網站公告chksum ,讓你知道你下載的檔案是正確未被篡改過,要產生Checksum 有很多種方法,普遍是用MD5,那只要可以利用Subversion 找出差異檔並產生每個檔案的MD5 並產生報表,申請人與資料管制人員都利用這種方式進行變更管裡,問題就解決了。
口說無憑,程式碼如下
1.提出變更申請目的
2.AP 頭頭同意
3.附上變更軟體資料、測試報告等等。交付資料管制人員處理。
4.資料管制人員,檢查申請人所付資料是否符合?
要進入正式區軟體庫中的檔案是否與申請項目相同
要討論的是如何確認申請人所附檔案是正確的(第 4 點):
1.申請人比對正式區軟體庫內容並產生差異檔 - DiffData1
2.資料管制人員依申請人申請,比對正式區軟體庫內容並產生差異檔 -DiffData2
3.比對DiffData1 與DiffData2 內容是否一致
問題來了,Source Code 是可以這麼做,但若是非Source Code (如COM/DLL) 要如何管理呢?
subversion 的diff 檔比不出來呀,解法是產生檔案的checksum 去證明是兩者一致,
如你去網路Download 檔案,也都是會看到檔案提供者在網站公告chksum ,讓你知道你下載的檔案是正確未被篡改過,要產生Checksum 有很多種方法,普遍是用MD5,那只要可以利用Subversion 找出差異檔並產生每個檔案的MD5 並產生報表,申請人與資料管制人員都利用這種方式進行變更管裡,問題就解決了。
口說無憑,程式碼如下
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
SVNMD5.EXE.
Used to compare working copy and Repository ,genereate compare report.
It's 100 % Python :)
I use Python 2.6.4 , py2exe,pysvn 1.7.2 to create SVNMD5.EXE
Diff report format : Unified diff format
"""
__author__ = ' Ray Yeh <yeh_ray@hotmail.com>'
__version__ = '1.0'
__licence__ = 'GPL V3'
import sys
import os
import re
from datetime import datetime
import pysvn
import codecs
import hashlib
def Usage():
print """Usage: """ + sys.argv[0] + """ PATH >> Report_file
Usage sample1 : SVNMD5.exe d:\project >> d:\svnreport.txt --> Output report at d:\svnreport.txt
Usage sample 2: SVNMD5.exe d:\project --> Output at screen
Batch compare working copy with repository and generate report to PATH
by Ray Yeh version 1.0
"""
sys.exit(1)
#------------------------------- Process the options -------------------------
if len(sys.argv)==2 :
workingdir=sys.argv[1]
else:
Usage()
try:
os.chdir(workingdir)
except OSError:
print "Cannot change dir to " + workingdir
Usage()
#------------------------------- Find out what has changed -------------------
client = pysvn.Client()
changes = client.status(workingdir)
#print 'files to be added:'
addedlist =[f.path for f in changes if f.text_status == pysvn.wc_status_kind.added]
#print 'files to be removed:'
deletedlist=[f.path for f in changes if f.text_status == pysvn.wc_status_kind.deleted]
#print 'files that have changed:'
modifiedlist=[f.path for f in changes if f.text_status == pysvn.wc_status_kind.modified]
#print 'files with merge conflicts:'
conflictedlist=[f.path for f in changes if f.text_status == pysvn.wc_status_kind.conflicted]
#print 'unversioned files:'
unversionedlist=[f.path for f in changes if f.text_status == pysvn.wc_status_kind.unversioned]
#print 'missing files:'
missinglist=[f.path for f in changes if f.text_status == pysvn.wc_status_kind.missing]
dt=datetime.now()
print "SVN compare run at:"+ dt.strftime("%A, %d. %B %Y %I:%M%p")
print "Compare Woking directory:"+workingdir + "\n"
str_1 =u"================== 產生 Compare 資料開始 ================="
str_2 =u"================== 產生 Compare 資料結束 ================="
print str_1.encode('big5_tw')
# Added files
for item in addedlist:
buff =""
file=open(item, 'rb')
buff=file.read()
file.close()
m=hashlib.md5()
m.update(buff)
print item+ " =>MD5 Chksum:" + m.hexdigest()
#Modified files
for item in modifiedlist:
buff =""
file=open(item, 'rb')
buff=file.read()
file.close()
m=hashlib.md5()
m.update(buff)
print item+ " =>MD5 Chksum:" + m.hexdigest()
print str_2.encode('big5_tw')
#Unversionedl files
for item in unversionedlist:
buff =""
file=open(item, 'rb')
buff=file.read()
file.close()
m=hashlib.md5()
m.update(buff)
print item+ " =>MD5 Chksum:" + m.hexdigest()
deletedcount=0
modifiedcount=0
missingcount=0
addedcount=0
unversionedcount=0
i=0
for i in addedlist:
addedcount +=1
i=0
for i in modifiedlist:
modifiedcount +=1
i=0
for i in missinglist:
missingcount+=1
i=0
for i in unversionedlist:
unversionedcount +=1
str_3=u'比對目錄路徑:'
str_4=u'比對檔案清單:'
str_5=u'新增 '
str_6=u'差異 '
str_7=u'刪除 '
str_8=u'未納版'
print str_3.encode('big5_tw')
print str_4.encode('big5_tw')
print str_5.encode('big5_tw')+'%d folders/files:\n%s' %(addedcount, addedlist)
print str_6.encode('big5_tw')+'%d folders/files:\n%s' %(modifiedcount, modifiedlist)
print str_7.encode('big5_tw')+'%d folders/files:\n%s' %(missingcount, missinglist)
print str_8.encode('big5_tw')+'%d folders/files:\n%s' %(unversionedcount,unversionedlist)
print "=========================================================="
2010年1月12日 星期二
使用svn 去產生 Working copy 與 repository 的比對報表
目的: 使用svn 去產生 Working copy 與 repository 的比對報表
解決方案:
1.Ad hoc 方法:
a.安裝支援 CLI(Command Line Interface) 的 svn 軟體,利用Command Line 去產生比對報表
2.利用 程式產生,並使用svn command line :
a. 利用DiffUtils 去產生 Context format ,如果不想看Context format 就用 svn 原始的diff 去產生 unified format 。
b.GNU32 -DiffUtils 2.8.7 (show differences between files)
http://gnuwin32.sourceforge.net/
c.SVN- Setup-Subversion-1.6.6.msi
http://subversion.tigris.org/
3.利用程式產生,不使用svn command line ,
a.pysvn -http://pysvn.tigris.org/
b.python 2.6.4
4. 安裝 Pysvn WorkBench Subversion
解決方案:
1.Ad hoc 方法:
a.安裝支援 CLI(Command Line Interface) 的 svn 軟體,利用Command Line 去產生比對報表
2.利用 程式產生,並使用svn command line :
a. 利用DiffUtils 去產生 Context format ,如果不想看Context format 就用 svn 原始的diff 去產生 unified format 。
b.GNU32 -DiffUtils 2.8.7 (show differences between files)
http://gnuwin32.sourceforge.net/
c.SVN- Setup-Subversion-1.6.6.msi
http://subversion.tigris.org/
#!/usr/bin/env python
# Python version of the bash shell "svnreport"
"""
SVNREPORT1.EXE.
Used to compare working copy and Repository ,genereate compare report.
It's 100 % Python :)
I use Python 2.6.4 , py2exe to create SVNREPORT1.EXE
Diff report format : Unified diff format
"""
__author__ = ' Ray Yeh <yeh_ray@hotmail.com>'
__version__ = '1.0'
__licence__ = 'GPL V3'
import sys
import os
import re
from datetime import datetime
def Usage():
print """Usage: """ + sys.argv[0] + """ PATH >> Report_file
Usage sample1 : svnreport1.exe d:\project >> d:\svnreport1.txt --> Output report at d:\svnreport.txt
Usage sample 2: svnreport1.exe d:\project --> Output at screen
Batch compare working copy with repository and generate report to PATH
by Ray Yeh version 1.0
"""
sys.exit(1)
#------------------------------- Process the options -------------------------
if len(sys.argv)==2 :
workingdir=sys.argv[1]
else:
Usage()
try:
os.chdir(workingdir)
except OSError:
print "Cannot change dir to " + workingdir
Usage()
#------------------------------- Find out what has changed -------------------
svnstatus=os.popen("svn status").readlines()
added=""
deleted=""
modified=""
commit_message=""
#print svnstatus
for line in svnstatus:
matchObject=re.match(r"^\?\s*(.*)\n",line)
if matchObject:
added = added + "\"" + matchObject.group(1) + "\" "
#print matchObject.group(1)
commit_message += "added file " + matchObject.group(1) + "\n"
matchObject=re.match(r"^\!\s*(.*)\n",line)
if matchObject:
deleted = deleted + "\"" + matchObject.group(1) + "\" "
commit_message += "deleted file " + matchObject.group(1) + "\n"
matchObject=re.match(r"^\M\s*(.*)\n",line)
if matchObject:
modified = modified + "\"" + matchObject.group(1) + "\" "
commit_message += "modified file " + matchObject.group(1) + "\n"
'''if added:
#os.system("svn diff "+added)
if deleted:
print "deleted-"+deleted
#os.system("svn diff "+deleted) '''
if modified:
os.system('svn diff ' +modified )
if not added:
commit_message += "no added files\n"
if not deleted:
commit_message += "no deleted files\n"
if not modified:
commit_message += "no modified files\n"
modifiedcount =0
addedcount = 0
deletedcount=0
addedlist=added.split()
modifiedlist=modified.split()
deletedlist=deleted.split()
i=0
for i in addedlist:
addedcount +=1
i=0
for i in modifiedlist:
modifiedcount +=1
i=0
for i in deletedlist:
deletedcount +=1
dt=datetime.now()
print "======================================================="
print "SVN compare run at:"+ dt.strftime("%A, %d. %B %Y %I:%M%p")
print "Compare Woking directory:"+workingdir
print "Add %d folders/files:\n%s" %(addedcount, added)
print "Modified %d folders/files:\n%s" %(modifiedcount, modified)
print "Deleted %d folders/files:\n%s" %(deletedcount, deleted)
print "======================================================="
3.利用程式產生,不使用svn command line ,
a.pysvn -http://pysvn.tigris.org/
b.python 2.6.4
### -*- coding: utf-8 -*-
#!/usr/bin/env python
"""
PYSVNRPT.EXE.
Used to compare working copy and Repository ,genereate compare report.
It's 100 % Python :)
I use Python 2.6.4 , py2exe,pysvn 1.7.2 to create PYSVNRPT.EXE
Diff report format : Unified diff format
"""
__author__ = ' Ray Yeh <yeh_ray@hotmail.com>'
__version__ = '1.0'
__licence__ = 'GPL V3'
import sys
import os
import re
from datetime import datetime
import pysvn
def Usage():
print """Usage: """ + sys.argv[0] + """ PATH >> Report_file
Usage sample1 : PYSVNRPT.exe d:\project >> d:\svnreport.txt --> Output report at d:\svnreport.txt
Usage sample 2: PYSVNRPT.exe d:\project --> Output at screen
Batch compare working copy with repository and generate report to PATH
by Ray Yeh version 1.0
"""
sys.exit(1)
#------------------------------- Process the options -------------------------
if len(sys.argv)==2 :
workingdir=sys.argv[1]
else:
Usage()
try:
os.chdir(workingdir)
except OSError:
print "Cannot change dir to " + workingdir
Usage()
#------------------------------- Find out what has changed -------------------
client = pysvn.Client()
changes = client.status(workingdir)
#print 'files to be added:'
addedlist =[f.path for f in changes if f.text_status == pysvn.wc_status_kind.added]
#print 'files to be removed:'
deletedlist=[f.path for f in changes if f.text_status == pysvn.wc_status_kind.deleted]
#print 'files that have changed:'
modifiedlist=[f.path for f in changes if f.text_status == pysvn.wc_status_kind.modified]
#print 'files with merge conflicts:'
conflictedlist=[f.path for f in changes if f.text_status == pysvn.wc_status_kind.conflicted]
#print 'unversioned files:'
unversionedlist=[f.path for f in changes if f.text_status == pysvn.wc_status_kind.unversioned]
#print 'missing files:'
missinglist=[f.path for f in changes if f.text_status == pysvn.wc_status_kind.missing]
dt=datetime.now()
print "SVN compare run at:"+ dt.strftime("%A, %d. %B %Y %I:%M%p")
print "Compare Woking directory:"+workingdir + "\n"
print "====================="+u" 產生 Compare 資料開始 "+"==================="
for item in modifiedlist:
difftext=client.diff('t:',item)
print difftext
print "====================="+u" 產生 Compare 資料結束 "+"==================="
deletedcount=0
modifiedcount=0
missingcount=0
addedcount=0
unversionedcount=0
i=0
for i in addedlist:
addedcount +=1
i=0
for i in modifiedlist:
modifiedcount +=1
i=0
for i in missinglist:
missingcount+=1
i=0
for i in unversionedlist:
unversionedcount +=1
print u"比對目錄路徑:"+workingdir
print u"比對檔案清單:"
print u"新增 %d folders/files:\n%s" %(addedcount, addedlist)
print u"差異 %d folders/files:\n%s" %(modifiedcount, modifiedlist)
print u"刪除 %d folders/files:\n%s" %(missingcount, missinglist)
print u"未納版 %d folders/files:\n%s" %(unversionedcount,unversionedlist)
print "=========================================================="
4. 安裝 Pysvn WorkBench Subversion
訂閱:
文章 (Atom)