6 Mar 2010

Stupid

Just updated my gentoo box and some features get problem. All should be solved by running "revdep-rebuild" to re-install some missing library. But there's an interesting bug (?) of wicd after update :). You cannot start wicd daemon with error
g3n2 ~ # /etc/init.d/wicd restart
/etc/init.d/wicd: line 12: syntax error: unexpected end of file
 * ERROR:  /etc/init.d/wicd has syntax errors in it; aborting ...
Take a look at wicd init script, someone who made update for wicd did make a mistake:
#!/sbin/runscript
 2 # Copyright 1999-2006 Gentoo Foundation
 3 # Distributed under the terms of the GNU General Public License v2
 4 
 5 opts="start stop restart"
 6 
 7 WICD_DAEMON=/usr/sbin/wicd
 8 WICD_PIDFILE=/var/run/wicd/wicd.pid
 9 
10 depend() {

11                   need dbus
Function depend() has no close parenthesis, and where is start() and stop() function? I don't know.I solved it by adding some line like bellow:
1 #!/sbin/runscript
 2 # Copyright 1999-2006 Gentoo Foundation
 3 # Distributed under the terms of the GNU General Public License v2
 4 
 5 opts="start stop restart"
 6 
 7 WICD_DAEMON=/usr/sbin/wicd
 8 WICD_PIDFILE=/var/run/wicd/wicd.pid
 9 
10 depend() {
11     need dbus
12     }
13 start() {
14             ebegin "Starting wicd daemon"
15                     "${WICD_DAEMON}" >/dev/null 2>&1
16                             eend $?
17 }
18 
19 stop() {
20             ebegin "Stopping wicd daemon"
21                     start-stop-daemon --stop --pidfile "${WICD_PIDFILE}"
22                             eend $?
23 }
Who works for the maintenance of wicd on gentoo? wtf

4 Mar 2010

portage-2.1.8 has new --rebuilt-binaries option

In portage-2.1.8 there's a new emerge --rebuilt-binaries
option that is very useful for people who build binary packages and
install them on multiple computers (using PORTAGE_BINHOST or shared
PKGDIR). The option causes packages to be automatically reinstalled in
cases when rebuilt binary packages are available (due to revdep-rebuild
or similar cases).
Rebuilds are detected by comparison of BUILD_TIME package metadata.
This option is enabled automatically when using binary packages
(--usepkgonly or --getbinpkgonly) together with --update and --deep.


http://blogs.gentoo.org/zmedico/2010/03/03/rebuilt_binaries_portage_2_1-8

12 Feb 2010

Love songs

#!/usr/bin/env python
# python script to download love songs from mp3.zing.vn
# hungnv
# license: Public Domain
from urllib2 import urlopen
from urllib import urlretrieve
from os import mkdir
from os.path import join, isdir
import sys
mp3_dir = "/home/hungnv/Music/"
html_source = "http://mp3.zing.vn/mp3/nghe-album/album-hot/love-song.html"
if not isdir(mp3_dir):
    try:
        mkdir(mp3_dir)
    except:
        print "cannot create directory %s" %mp3_dir
        sys.exit(1) 
def getlink():
    try:
        response = urlopen(html_source)
    except:
        print "connection error"
    response = urlopen(html_source)
    content = response.readlines()
    response.close()
    for line in content:
        a = line.find('http://dl.mp3.kapsule.info')
        b = line.find('?')
        if a <> -1 and b <> -1:
            link = line[a:b]
            c = line.find('filename') + 9
            d = line.find('alt') - 2
            filename = line[c:d]
            print "Song named %s will be downloaded at url %s" % (filename,link)
            print "Downloading.....\n"
            abs_path = join(mp3_dir,filename)
            urlretrieve(link,abs_path)
        else:
            continue
if __name__ == '__main__': 
    getlink()
exit()

27 Jan 2010

Indispensable job

I have an account named hungnv on my server - vndev.net which's running Fedora 8. If I want to remote copy, modify, delete... some files on this server , which way is faster:
1. sftp ( known as an extension of secure shell protocol - SSH ) 
hungnv@g3n2 ~ $ sftp vndev.net
Connecting to vndev.net...
sftp>
Browse local file: lls, move to local directory lcd
upload put
download get

2. sshfs (not an ssh extension, we must install fuse-sshfs to use it)
hungnv@g3n2 ~ $ eix sshfs
[I] sys-fs/sshfs-fuse
     Available versions:  1.9 ~2.1 2.2
     Installed versions:  2.2(08:46:14 AM 01/27/2010)
     Homepage:            http://fuse.sourceforge.net/sshfs.html
     Description:         Fuse-filesystem utilizing the sftp service.
hungnv@g3n2 ~ $ sudo emerge -av sys-fs/sshfs-fuse
hungnv@g3n2 ~ $ sshfs vndev.net:/ /vndev
to mount. We browse, cp, edit, delete....like local file and directory.
I didn't use sshfs until yesterday, with me, ssh and sftp are enough. But I should know sshfs and I did not know, so I fail.
We must learn what we never use =.=

22 Jan 2010

Phân hóa thu nhập từ nhiều góc nhìn

Trong một phát biểu của Trần Trọng Thức ở Tuần Việt Nam
Trong khi có những người giàu lên không bằng năng lực cũng chẳng nhờ vào thời cơ, mà nhờ vào các mối quan hệ. Hầu hết các nước kém phát triển, khi quyền lực liên kết với tư bản trong làm ăn thì phân hóa giàu nghèo càng khó giải quyết. Về mặt lý thuyết thì quyền lực chính trị là khả năng quyết định ai sẽ nhận được "cái gì" để làm ra được "cái gì" và cho ai được hưởng.
Thực tế đơn giản là thực tế :-D.

21 Jan 2010

Học python

Sửa lại chút cái shell script hồi xưa Dreammedia , viết lại bằng python.
Bạn nào dùng thì nhớ nếu tên ban nhạc hoặc album có khoảng trắng, thì thêm vào thành "band name" hoặc "album name" :).

#! /usr/bin/env python
# Script to download Music from Dreammedia.ru
# Try to find your favorite Band and Album, then use this script
# hungnv coded 
import os
import urllib2
import sys
def usage():
        print "Usage:",sys.argv[0], "\"bandname\" \"albumname\""    
        
def st_replace(string):
        new = string.replace(' ','%20')
        return new
            
def download(url,pl,band,album):
        band1 = st_replace(band)
        album1 = st_replace(album)
        temp = (url + pl[:8] + '/' + band1 + '/' + album1 + '/' + pl)
        try:
                response = urllib2.urlopen(temp)
        except:
                print 'Connection error'
        response = urllib2.urlopen(temp)
        content = response.readlines()
        for line in content:
                a = line.find('music/')
                b = line.find('.mp3')
                if a <> -1 and b <> -1:
                        path = line[a:b+4]
                        semi = (url + '%s') %path
                        final = st_replace(semi)
                        os.system('wget '+final)
                else:
                        continue
                        
if __name__ == '__main__':
        band = sys.argv[1]
        album = sys.argv[2]
        url = "http://dreammedia.ru/"
        pl = 'playlist.xml'
        if len(sys.argv) <> 3:
                usage()
                exit()
        else:
                download(url,pl,band,album)
exit()


Disqus