Custom Search

Friday, December 28, 2012

how to rar unrar files ubuntu 12.10

how to install rar unrar in ubuntu 12.10
 
 1)
download file
http://www.rarlab.com/rar/rarlinux-x64-4.2.0.tar.gz

2)
Extract file
tar -xzf rarlinux-x64-4.2.0.tar.gz

3)
Copy files to /bin
sudo cp rar unrar /bin

Thursday, December 20, 2012

python decorator to wait method get executed

def wait_x_seconds_decorator(wait_time_sec=100):
    """
        Method "func" should return True or False
    """
    def func_wrap(func):
        """
        """
        def inner_wrap(*args, **kwargs):
            wait_time = kwargs.get("wait_time_sec")
            if not wait_time:
                wait_time = wait_time_sec
            st = time.time()
            status = None
            while True:
                status = func(*args, **kwargs)
                if status:
                    return True
                tt = time.time() - st
                if tt >= wait_time:
                    raise Exception("Timeout Error")
        return inner_wrap
    return func_wrap





Usage
=====

@wait_x_seconds_decorator()
def test_method(name, wait_time_sec=10):
   """
   """
   ##Do some thing
   If done:
      return True
   return False