-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.py
More file actions
80 lines (69 loc) · 2.12 KB
/
Copy pathconfig.py
File metadata and controls
80 lines (69 loc) · 2.12 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
try:
import configparser as cp
except:
import ConfigParser as cp # python 2.x
class Repo(object):
"""object to store relevant information about a repo"""
def __init__(self,name,id,repos,path=None):
self.name = name
self.id = id
self.repos = repos
self.path = path
def load_config(file):
c = cp.ConfigParser()
c.readfp(open(file))
remotes = dict(c.items('remotes'))
del remotes['uname']
sections = c.sections()
sections.remove('remotes')
repos = {}
for s in sections:
p = dict(c.items(s)) # p=properties
try:
remote = [(r,remotes[r]. \
replace("{repo}",s.lower()). \
replace("{REPO}",s.upper()). \
replace("{Repo}",s))
for r in p['repos'].split(',')]
except KeyError:
remote = []
try:
path = p['path']
except KeyError:
path = None
repos[p['id']] = Repo(s,p['id'],remote,path)
return repos,remotes
def create_config(file):
defaults = {'uname':'mysername'}
c = cp.ConfigParser(defaults)
c.add_section("remotes")
with open(file, 'w') as f:
c.write(f)
def ammend_property_config(file,section,data):
c = cp.ConfigParser()
c.read(file)
c.set(section,data[0],data[1])
with open(file, 'w') as f:
c.write(f)
def remove_property_config(file,section,data):
c = cp.ConfigParser()
c.read(file)
if not c.remove_option(section,data):
raise CmdFailed('remove_property',"property not found in config file")
with open(file, 'w') as f:
c.write(f)
def ammend_section_config(file,section,data):
c = cp.ConfigParser()
c.read(file)
c.add_section(section)
for d in data:
c.set(section,d[0],d[1])
with open(file, 'w') as f:
c.write(f)
def remove_section_config(file,section):
c = cp.ConfigParser()
c.read(file)
if not c.remove_section(section):
raise CmdFailed('remove_section',"section not found in config file")
with open(file, 'w') as f:
c.write(f)