~pyneighborhood/pyneighborhood/0.5

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python

# gets a list of samba shares on the selected host

import os
import string
from os import system, environ, path, getenv, mkdir, getcwd

def readconfig():
    # check if ~/.pyNeighborhood exists. If not, create it
    if not path.exists(getenv("HOME")+"/.pyNeighborhood"): 
        mkdir(getenv("HOME")+"/.pyNeighborhood")

    if path.exists(getenv("HOME")+"/.pyNeighborhood"): 
        home = getenv("HOME")
        hostslocation = string.join([home, "/.pyNeighborhood"], '')
        os.chdir(hostslocation)
        #print os.getcwd()

        #check if file containing a list of favourite hosts	exists. If not, create it
        hostfile = open('hosts', 'a')
        hostfile.close()

        #read hosts from file and create a standart list of them		
        hostfile = open("hosts", 'r')
        hostfile.seek(0)
        list = hostfile.readlines()
        #print list
        hostlist = []
        i = 0
        for number in list:
            line = list[i]
            hostline = line.split("\n")
            hostlist.append(hostline[0])
            i = i + 1
		
        hostfile.close()
        return hostlist