Reading Java property file in Python

Accessing  a java property file in a python code is an easy task. For this we need to install, a python module called pyjavaproperties. (There are many other ways in which we can do this. I prefer this module)

For installing this, please run the following command :

sudo pip install http://pypi.python.org/packages/source/p/pyjavaproperties/pyjavaproperties-0.6.tar.gz

How to use it 

we have a property file named  config.properties and which is as follows,

config.properties
user=Crunchify
company1=Google
company2=eBay
company3=Yahoo
Now open a python ide and add the following lines
from pyjavaproperties import Properties
p = Properties()
p.load(open('test2.properties'))
p.list()     #will all the properties and its valuesprint                                               print p['user']   #prints Cruchify
Ref :                                                                                                   https://pypi.python.org/pypi/pyjavaproperties                                                           https://www.versioneye.com/python/pyjavaproperties/0.6
Advertisements

How to Change Root password in Ubuntu Virtual Machine

In order to access the grub menu on a virtual machine, you need to hold the shift key down for a while. You must let your virtual machine to capture your mouse before holding the shift key. Follow the steps to change your password:

1. Let your virtual Machine to capture your mouse.
2. Hold the shift key down to get the grub menu.
3. Select the recovery mode option.
4. Select drop to root shell prompt.

After immediately selecting ‘Drop into root shell prompt’ I found the filesystem was mounted read only, which prevents resetting the password and got some error like

passwd: Authentication token manipulation error
  passwd: password unchanged

To fix this I had to run following command

  mount -rw -o remount /

Now you can change the root password using the command  :

passwd root

This would ask for new password and on entering it it would succefully chage the same too.

reference :

https://mithunme.wordpress.com/2011/11/10/how-to-reset-rootsingle_user-password-in-ubuntu-on-a-virtual-machine/

apt-get update Errors -5 – No address associated with hostname

When I tried to run sudo apt-get update, I came across something like this.

Ign http://in.archive.ubuntu.com precise InRelease
Err https://archive.cloudera.com precise-cm5.5.1/contrib amd64 Packages
Couldn’t resolve host ‘archive.cloudera.com’
Err http://archive.cloudera.com precise-cm5/contrib Sources
Something wicked happened resolving ‘archive.cloudera.com:http’ (-5 – No address associated with hostname).                    Ign http://in.archive.ubuntu.com precise-updates InRelease
Err http://archive.cloudera.com precise-cm5/contrib amd64 Packages
Something wicked happened resolving ‘archive.cloudera.com:http’ (-5 – No address associated with hostname)
Ign http://in.archive.ubuntu.com precise-backports InRelease
Err http://archive.cloudera.com precise-cm5/contrib Translation-en_IN
Something wicked happened resolving ‘archive.cloudera.com:http’ (-5 – No address associated with hostname)

 

This was a bit scary for me as it was for the first time I was facing something like this. And I even tried adding hostname of ubuntu server and  its ip address directly in my /etc/hosts file. and further to my frustration it did not work.  But The actual fix that worked for me is as follows:

 

echo “nameserver 8.8.8.8” | sudo tee /etc/resolv.conf > /dev/null                                                                                        sudo apt-get update

Then apt-get update worked perfectly.