~pyneighborhood/pyneighborhood/0.5

« back to all changes in this revision

Viewing changes to readconfig.py

  • Committer: definer
  • Date: 2006-09-16 18:34:46 UTC
  • Revision ID: svn-v3-trunk0:918a6f1d-dd1c-0410-8c33-97c2c1a26c01:trunk:6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
# gets a list of samba shares on the selected host
 
4
 
 
5
import os
 
6
import string
 
7
from os import system, environ, path, getenv, mkdir, getcwd
 
8
 
 
9
def readconfig():
 
10
    # check if ~/.pyNeighborhood exists. If not, create it
 
11
    if not path.exists(getenv("HOME")+"/.pyNeighborhood"): 
 
12
        mkdir(getenv("HOME")+"/.pyNeighborhood")
 
13
 
 
14
    if path.exists(getenv("HOME")+"/.pyNeighborhood"): 
 
15
        home = getenv("HOME")
 
16
        hostslocation = string.join([home, "/.pyNeighborhood"], '')
 
17
        os.chdir(hostslocation)
 
18
        #print os.getcwd()
 
19
 
 
20
        #check if file containing a list of favourite hosts     exists. If not, create it
 
21
        hostfile = open('hosts', 'a')
 
22
        hostfile.close()
 
23
 
 
24
        #read hosts from file and create a standart list of them                
 
25
        hostfile = open("hosts", 'r')
 
26
        hostfile.seek(0)
 
27
        list = hostfile.readlines()
 
28
        #print list
 
29
        hostlist = []
 
30
        i = 0
 
31
        for number in list:
 
32
            line = list[i]
 
33
            hostline = line.split("\n")
 
34
            hostlist.append(hostline[0])
 
35
            i = i + 1
 
36
                
 
37
        hostfile.close()
 
38
        return hostlist
 
39