~darragh-ssa/d-cm/d-cm

« back to all changes in this revision

Viewing changes to basics.py

  • Committer: Darragh van Tichelen
  • Date: 2010-05-14 10:30:14 UTC
  • Revision ID: darragh.ssa@gmail.com-20100514103014-5ycjt6xh40ea6y8k
First Import under bazaar

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
def config_get(name,config):
 
3
    try:
 
4
        f = open(config, 'r')
 
5
    except:
 
6
        print("error: could not open" + config + " error generated in config_get")
 
7
    for line in f:
 
8
        if name.strip() == line.strip().split("=")[0]:
 
9
             strip = line.strip().split("=")[1]
 
10
    return strip
 
11
    f.close()
 
12
 
 
13
def config_set(name,new,config):
 
14
        last = config_get(name,config)
 
15
        last = name + "=" + last
 
16
        new = name + "=" + new
 
17
        try:
 
18
            s = open(config, 'r').read()
 
19
        except:
 
20
            print("error: could not open" + config + " error generated in config_set")
 
21
        s = s.replace(last, new)
 
22
        f = open(config, 'w')
 
23
        f.write(s)
 
24
        f.close()