ubuntu 在 R40e 上 還有 Debian 在 Sempron 2600 上

顯示具有 Python 標籤的文章。 顯示所有文章
顯示具有 Python 標籤的文章。 顯示所有文章

2015年8月18日 星期二

另一個python script: check not git(ize) folders

上一篇: http://r40eubuntu.blogspot.tw/2011/03/python-check-git-no-git-folder.html

在更新過 python 版本後,好像沒辦法在 for loop 中更改 loop list 內容。
所以要改一下,



所以檢查 android source 與 repo, git 是否完整的 python script 就是:


他會先找出是否有哪個folder 還沒有 git 管轄
然後從 manifest.xml 找出所有的 project path。
檢查是不是所有 git folder 都有在 manifest.xml 中
檢查是不是所有 manifest.xml 的 project 都實際存在。

放在: https://github.com/checko/python_repo

python : 找出沒有在 git control 下的 folder

因為 vendor 給的 android source 沒有包含 git, repo 資訊,
所以只好採用 .. repo sync 一個相近的 source, 覆蓋後 commit

所以覆蓋後,要檢查是不是有沒被 versio control 的 folder:
用 python 寫:
import os

i=0
for root, dirlist, filelist in os.walk("./"):
        toremove=[]

        for ss in ['.repo','out']:
                if ss in dirlist:
                        toremove.append(ss)

        for ss in dirlist:
                gpath = os.path.join(root,ss,'.git')
                if os.path.isdir(gpath):
                        toremove.append(ss)

        for ss in toremove:
                dirlist.remove(ss)

        if (len(dirlist)==0) and (len(toremove)==0):
                print i, root
                i=i+1
因為 os.walk 會依照top down 的方式,到 dirlist 中搜尋。
所以就用修改 dirlist 的方式來作:
  • 先排除 .repo, out 目錄
  • 排除含有 .git 的次目錄
最後就可以印出來。

但是這個結果會把所有沒有 git control 的 folder, subfolder 都印出來,(因為他沒辦法判斷要從哪裡算起,是一個 project)
這部份要自己作。


這個動態刪除 dirlist 的作法在更換 python 版本的時候出了問題。
原來是在判斷包含 .git 後直接作 dirlist.remove(ss)
但是卻發現這樣會影像到下一個 ss (in dirlist) 的判斷。
所以只好先放在 toremove[] 中,最後再一次修改全部

放在: https://github.com/checko/python_repo

2015年5月7日 星期四

twitter client in console mode : rainbowstream

http://www.rainbowstream.org/

是用 python 寫的。
就 follow doc 說明。用virtualenv 建立一個工作環境,在用 pip 裝。以後就可以在這個工作還行 run.

要注意的是,有關 proxy.
他會吃環境變數 http_proxy, 但是又不會動。然後 --proxy command 又會受影響。

所以要先把 http_proxy unset, 再用 --proxy option 來 run.

第一次run 會叫出 browser login twitter, 給 rainbowstream 授權。


source venv/bin/activate
unset http_proxy
unset https_proxy
rainbowstream -ph 192.168.0.1 -pp 3128 -pt HTTP



大概說明一下...
virtualenv 是 python 的一個 tool, 會幫你建立一個虛擬環境,在這個環境裡,你可以安裝軟體,設定環境變數..etc
都不會動到主系統。
而且退出後就消失。 virtualenv venv 的命令就是:建立一個 virtualenv 環境,名稱叫 venv.
之後,在home 目錄下就會有 venv 這個目錄。

要進入venv 這個環境,只要:
source venv/bin/activate
就可以。

2013年5月23日 星期四

python script : follow repo/manifest.xml 做出 repo mirror 的結構.

是希望由工作的 source 做出 repo --mirror 的目錄結構:


這樣做完後,還要到 platform 目錄下 單獨 clone .repo/manifests.git 出來,這樣還有修改,吃 argument 作 source path:


但是很奇怪的是,這樣做出來的 folder (假設是 uuu),用 repo init clone 下來後,folder structure 竟然也是 mirror 的結構...
$mkdir uuuclone && cd uuuclone $repo init -u ~/uuu/platform/manifests.git -b cv3000 $repo sync

但是..再由 uuuclone clone 的話就 OK 了...@_@...
$mkdir uuucloneclone && cd uuucloneclone $repo init -u ~/uuuclone/platform/manifests.git -b cv3000 $repo sync

不知道為什麼會這樣,但是 uuuclone 已經可以用了,所以就把他放到 git server 的 git-daemon folder 裡..

2011年3月30日 星期三

check if every git projects are list in repo manifest

先試一下 是不是所有的 source code 都有在 git 控制下:

目標:

找出所有 git versionize 的 project (folder) 和沒有 git versionize 的 folder。

Rule:

該 folder 有 .git 目錄,則該 folder 為 project root
到 tree end (沒有任何 subfolder) 都沒有 .git 目錄,則該 folder 就沒有 versionize.

os.walk( ) 的搜尋有 top-down 和 buttom-up.

使用 top-down,在 path walk 中可以即時更改 dirlist..

找dirlist 中每個 item (folder),該 folder 下有 .git 目錄,就從 dirlist 中刪掉 (remove).

如果 是 end node ( len(dirlist) == 0 ) 就是 not versionize folder.

寫起來就是:
import os gitproj=[] emptyproj = [] if os.path.isdir(".git"): gitproj.append("./") else: for root, dirlist, filelist in os.walk("./"): for ingpath in ['.repo','out']: if ingpath in dirlist: dirlist.remove(ingpath) if len(dirlist) == 0 : emptyproj.append(root) else: foundpath=[] for dirname in dirlist: if os.path.isdir(os.path.join(root,dirname,'.git')): foundpath.append(dirname) for dirname in foundpath: dirlist.remove(dirname) gitproj.append(os.path.join(root,dirname)) print (emptyproj) print ('==============') print (len(gitproj))

但是很神奇的,check patch 後的 folder,, 每個 folder 都有被 git versionzie 耶!!!
.. 所以是我寫錯?


這個比較有趣的地方是 (作為一個初學者):
for.. in os.walk 的動作,在 top-down 模式,允許你修改 在 loop 中修改 dirlist 的內容,這樣他就不會 walk in 那些不在 dirlist 的 path.



接著,是不是所有的 git project 都有列在 repo 的 manifest 裡:

import os import sys import xml.dom.minidom # STEP 1 : get all project path in manifest.xml xmlroot = xml.dom.minidom.parse('./.repo/manifest.xml') manifestprojlist=[] for node in xmlroot.childNodes[0].childNodes: if node.nodeName == 'project': manifestprojlist.append(os.path.join('./',node.getAttribute('path'))) # STEP 2 : search all the source tree to get the .git project list emptylist = [] gitlist = [] for root, dirlist, filelist in os.walk('./'): for ingpath in ['.repo','out']: if ingpath in dirlist: dirlist.remove(ingpath) if len(dirlist) == 0: emptylist.append(root) else: foundpath=[] for dirname in dirlist: if os.path.isdir(os.path.join(root,dirname,'.git')): foundpath.append(dirname) gitlist.append(os.path.join(root,dirname)) # STEP 3 : compare and print result for projname in gitlist: if projname not in manifestprojlist: print projname
結果真的有...除了 kernel 和 bootloader 外,還有 10 個 git project

2008年12月14日 星期日

Python : open and read binary file

原來python 開啟檔案的模式會影響read() function 的動作。
>>>img=open("c:\\keroro.jpg","r")
>>>img.read(32)
...略...
>>>img.tell()
1612L   !!! <--- 怎麼會這樣! 
後來發現,原來 binary 檔就要指定用 binary 的方式開啟:
 img=open("c:\\keroro.jpg","rb")
這樣 read( )動作和 tell()就會正常了。
用 google 搜尋 "python read binary file",會有很好的 binary read/write 範例。

2008年9月29日 星期一

IDE for Python

畢竟是個懶人,所以還是選個 IDE 來用,因為不知道哪一個好,IDLE 又太陽春,所以就裝了 SPE 和 ERIC 試試..

標籤

網誌存檔