2012年11月30日 星期五

[Android] 在userdebug之下push檔案到read only

在user mode,system等權限為read only,無法push檔案
在userdebug mode及eng mode,權限是打開的
若顯示read only,須先remout後,就可以繼續push

$ adb root
$ adb remount
$ adb push [filename] /system/lib

2012年11月13日 星期二

[Android] 在codebase中build APP

需要放到Android codebase底下build的app

放在package/app或是vendor/3rdparty底下
這樣就會build了
build出來的路徑是out/target/common/obj/APPS

若要build在image中
在device/nvidia/ventana/ventana.mk
增加PRODUCT_PACKAGES += [product name]

2012年11月12日 星期一

[Android] 查看Android device key:app sign key

查看sign什麼key
$ adb shell getprop ro.build.fingerprint

若是Android default的key會顯示test key
但Android要出貨,需過CTS,其中一項會檢測key需用自己創造的key
則會顯示release key

android的app若是需要用到系統權限
則需要用同一把key sign此app
此app才能夠獲得系統權限

sign app for system permission)
$ java -Xmx2048m -jar utils/linux-x86/framework/signapk.jar -w keys/platform.x509.pem keys/platform.pk8 unsigned_app.apk signed_app.apk

2012年11月9日 星期五

[git] clone裸版本庫;下載git server

下載一份git server的形式 (裸版本庫)
非codebase

git server的形式如下
/branches
/hooks
/logs
/objects
/refs
config
description
HEAD

下載:
$ git clone --bare ssh://[git server ip]

2012年11月6日 星期二

[linux][git] 架設Git Server及GitWeb

架設Git Server及GitWeb

1). 安裝ssh server、git-core、apache2、gitweb
$ sudo apt-get install ssh git-core apache2 gitweb

2). 創建放git server資料的使用者帳戶
$ sudo useradd -m -s /bin/bash [account]
$ sudo passwd [account]

※ useradd參數
-m:強制有家目錄
-s:設定shell,預設是/bin/sh


3). 啟動ssh
$ sudo sudo /etc/init.d/ssh restart

4). 創建git project
$ sudo su - [account]
$ mkdir TestProject.git
$ cd TestProject.git
$ git init --bare

5). 修改Gitweb連結路徑
$ cd /var/cache/
$ sudo rmdir git
$ sudo ln -sf [放git project的目錄路徑] git
ex: sudo ln -sf /home/git git

2012年10月29日 星期一

[python] 編碼錯誤解決(UnicodeDecodeError)

錯誤訊息:

Traceback (most recent call last):
  File "./check_notice.py", line 243, in <module>
    file.save('Check_Legal_Notice_Report.xls')
  File "/usr/local/lib/python2.7/dist-packages/xlwt/Workbook.py", line 643, in save
    doc.save(filename, self.get_biff_data())
  File "/usr/local/lib/python2.7/dist-packages/xlwt/Workbook.py", line 618, in get_biff_data
    shared_str_table   = self.__sst_rec()
  File "/usr/local/lib/python2.7/dist-packages/xlwt/Workbook.py", line 580, in __sst_rec
    return self.__sst.get_biff_record()
  File "/usr/local/lib/python2.7/dist-packages/xlwt/BIFFRecords.py", line 77, in get_biff_record
    self._add_to_sst(s)
  File "/usr/local/lib/python2.7/dist-packages/xlwt/BIFFRecords.py", line 92, in _add_to_sst
    u_str = upack2(s, self.encoding)
  File "/usr/local/lib/python2.7/dist-packages/xlwt/UnicodeUtils.py", line 50, in upack2
    us = unicode(s, encoding)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 40: ordinal not in range(128)

--

此為編碼錯誤(UnicodeDecodeError)

Python內部使用unicode編碼
在做編碼轉換時,需先將其他解碼(decode)成unicode
再從unicode編碼(encode)成另一種編碼

Ex1:
print a.encode('utf-8')

Ex2:
sheet.write(row,col,data.encode('utf-8'))

2012年10月26日 星期五

[python] list與dictionary的結合

dictionary能儲存資料以及索引
對整理資料能夠有比較好的架構
但資料卻不是有序的序列
於是可藉由list來幫忙做排序

這篇介紹list中包dictionary,及dictionary中包list的方法

1). list中包dictionary
dict1={key:a}
dict2={key:b}
list=[dict1,dict2]
or
list=[]
list.append(dict1)

2). dictionary中包list
dict={}
dict[key]=list()
dict[key].append(value)

2.1). 新增資料前先檢查有沒有key
if key not in dict:
    dict[key] = list()
dict[key].append(value)



※ref:http://lucaswei.blogspot.tw/2012/05/pythondictxlist.html

[python] 外部指令

python需引用外部指令時,可用以下程式碼

import commands

command_git='cd %s; git log' %(codebase)
log=commands.getoutput(command_git)

[python] iterator與enumerate

enumerate(iterable, start=0)
回傳以 iterable 與連續整數配對的 enumerate 物件, start 為整數的起始值,預設為 0

Ex1:
d = ['Spring', 'Summer', 'Fall', 'Winter']
for i, j in enumerate(d, 1):
    print(i, j)

[output]
1 Spring
2 Summer
3 Fall
4 Winter

Ex2:
for i, n in enumerate([1, 3, 5]):
    print i, n

[output]
0 1
1 3
2 5