2014年10月30日 星期四
Pack DEB package by using Python
1. sudo apt-get install python-stdeb devscripts python-all-dev
2. sudo pip install -U stdeb
3. python setup.py --command-packages=stdeb.command bdist_deb
4. The *.deb , *.tar.gz , *.dsc will be generated under deb_dist/ directory.
PS. If I have my own debian/*.postinst , debian/*.postrm , ...etc.
I need to add the file into MANIFEST.in in the same level directory with setup.py .
Such as:
$ echo "include debian/*" >> MANIFEST.in
Reference:
https://wiki.debian.org/Python/Packaging
2014年9月14日 星期日
Using Exiftool to shift datetime
1. Download the command line tool: exiftool
( http://www.sno.phy.queensu.ca/~phil/exiftool/ )
2. Change all datetime tags in exif to add 1 year 2 month 3 day 4 hour 5 min 6 sec, and also overwite the original file
>> exif tool "-AllDates+=1:2:3 4:5:6" -overwrite_original DIR_PATH
3. Finish
( http://www.sno.phy.queensu.ca/~phil/exiftool/ )
2. Change all datetime tags in exif to add 1 year 2 month 3 day 4 hour 5 min 6 sec, and also overwite the original file
>> exif tool "-AllDates+=1:2:3 4:5:6" -overwrite_original DIR_PATH
3. Finish
2014年9月10日 星期三
Python, Parse key, value pair without section
import StringIO
import ConfigParser
ini_path = "key_value_file_name"
ini_str = '[fakesection]\n' + open(ini_path).read()
ini_fp = StringIO.StringIO(ini_str)
config = ConfigParser.RawConfigParser()
config.readfp(ini_fp)
print config.items('fakesection')
import ConfigParser
ini_path = "key_value_file_name"
ini_str = '[fakesection]\n' + open(ini_path).read()
ini_fp = StringIO.StringIO(ini_str)
config = ConfigParser.RawConfigParser()
config.readfp(ini_fp)
print config.items('fakesection')
2014年9月9日 星期二
Use Services For UNIX to Install NFS Server in Windows
1. Download "Windows Services for UNIX" Version 3.5
(SFU35EL_EN.exe)
2. Execute SFU35EL_EN.exe to unzip the file.
3. Execute the unzipped "Setup.exe" to install the NFS Server.
4. Use "Custom Install" selection
5. Only select "Server for NFS" and "Server for NFS Authentication"
(It will also install "User Name Mapping)
6. After installation, it will start the service "Server for NFS".
If not, goto services to start it.
7. Setting the "User Name Mapping", select "Use Password and Group files" item.
And then select the path of "passwd" and "group"
This two file's sample can be show as:
passwd:
root:x:0:0:root:/root:/bin/bash
group:
root:x:0:
8. After setting need to press "Apply" button.
9. Open "File Manager" to the share folder, press right button to setting "NFS Sharing".
Select "Share this folder".
10. In Linux platform, use "mount" command with NFS version 3 option to mount it.
>> sudo mount -v -t nfs -o nfsvers=3 IP:/folder/path /mount/path
11. After using the NFS data, want to un-mount the folder
>> sudo umount /mount/path
(SFU35EL_EN.exe)
2. Execute SFU35EL_EN.exe to unzip the file.
3. Execute the unzipped "Setup.exe" to install the NFS Server.
4. Use "Custom Install" selection
5. Only select "Server for NFS" and "Server for NFS Authentication"
(It will also install "User Name Mapping)
6. After installation, it will start the service "Server for NFS".
If not, goto services to start it.
7. Setting the "User Name Mapping", select "Use Password and Group files" item.
And then select the path of "passwd" and "group"
This two file's sample can be show as:
passwd:
root:x:0:0:root:/root:/bin/bash
group:
root:x:0:
8. After setting need to press "Apply" button.
9. Open "File Manager" to the share folder, press right button to setting "NFS Sharing".
Select "Share this folder".
10. In Linux platform, use "mount" command with NFS version 3 option to mount it.
>> sudo mount -v -t nfs -o nfsvers=3 IP:/folder/path /mount/path
11. After using the NFS data, want to un-mount the folder
>> sudo umount /mount/path
2014年8月27日 星期三
Set child folder's default permission the same as parenet folder's permission
Use ACL module and set sgid
1. sudo apt-get install acl
2. Modify /etc/fstab set the option "acl" to the mounted file system
ex. /dev/sda1 / ext4 errors=remount-ro,acl 0 1
3. Remount the mount point
>> sudo mount -o remount /
4. Set the ACL for the folder
>> setfacl -dm u::rwx,g::rwx,o::r /home/folder/path
5. Set sgid for the folder
>> chmod g+s /home/folder/path
6. It's OK
1. sudo apt-get install acl
2. Modify /etc/fstab set the option "acl" to the mounted file system
ex. /dev/sda1 / ext4 errors=remount-ro,acl 0 1
3. Remount the mount point
>> sudo mount -o remount /
4. Set the ACL for the folder
>> setfacl -dm u::rwx,g::rwx,o::r /home/folder/path
5. Set sgid for the folder
>> chmod g+s /home/folder/path
6. It's OK
2014年5月28日 星期三
Calculate CRC32 in Python
Use binascii library with crc32 function to calculate CRC32.
import binascii
def computeFileCRC(filename):
try:
blocksize = 1024 * 64
f = open(filename, "rb")
str = f.read(blocksize)
crc = 0
while len(str) != 0:
crc = binascii.crc32(str,crc) & 0xffffffff
str = f.read(blocksize)
f.close()
except:
print "compute file crc failed!"
return 0
return crc
訂閱:
意見 (Atom)