Skip to content

Commit 9450b5d

Browse files
committed
implementation debug et config dans les templates
1 parent 6d45885 commit 9450b5d

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ ln -s $PWD/bin/ping.py $INSTALL/bin/ping.py 2>/dev/null
3434
ln -s $PWD/bin/resetpwd.py $INSTALL/bin/resetpwd.py 2>/dev/null
3535
ln -s $PWD/bin/delentity.py $INSTALL/bin/delentity.py 2>/dev/null
3636
ln -s $PWD/bin/upsertidentity.py $INSTALL/bin/upsertidentity.py 2>/dev/null
37-
ln -s $PWD/bin/activation.py $INSTALL/bin/activation.py 2>/dev/null
37+
ln -s $PWD/bin/activation.py $INSTALL/bin/activation.py 2>/dev/null
3838

3939
cp ./ps1_templates/* $INSTALL/ps1_templates
4040
chmod 600 $INSTALL/ps1_templates/*

src/etc/config.conf.exemple

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ branchForAdm=ou=Administratifs
66
branchForEsn=ou=Enseignants
77
branchAttr=supannEntiteAffectationPrincipale
88
backendFor=adm,etd,esn
9+
debug=0
10+
mycustomParameter=hello world

src/lib/ad_utils.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,22 +93,27 @@ def gen_script_from_template(entity,template):
9393
'base': u.config('base'),
9494
'dn' : compose_dn(entity),
9595
'path': dn_superior(compose_dn(entity)),
96-
'e': u.make_entry_array(entity)
96+
'e': u.make_entry_array(entity),
97+
'config': u.get_config()
9798
}
9899
environment = jinja2.Environment(loader=FileSystemLoader("../ps1_templates/"))
99100
template = environment.get_template(template)
100101
content=template.render(data)
101102
return content
102103

103104
def ad_exec_script(entity,template,params=""):
105+
if u.config('debug',0) == "1":
106+
__DEBUG__ = 1
107+
else:
108+
__DEBUG__ = 0
104109
content=gen_script_from_template(entity,template)
105110
client = open_ssh_conn()
106111
sshfile = client.open_sftp()
107112
pid=os.getpid()
108113
if __DEBUG__ == 0 :
109114
scriptName='sesame_script.' + str(pid) + '.ps1'
110115
else:
111-
scriptName='sesame_script.ps1'
116+
scriptName = os.path.splitext(os.path.basename(sys.argv[0]))[0] + ".ps1"
112117
with sshfile.open(scriptName, mode="w") as message:
113118
message.write(content)
114119
##execution du script
@@ -117,19 +122,21 @@ def ad_exec_script(entity,template,params=""):
117122
cmd=scriptName
118123
else:
119124
cmd=scriptName + " " + params
120-
chan.exec_command('powershell -ExecutionPolicy Bypass -NonInteractive -File ' + cmd)
121-
exitCode = chan.recv_exit_status()
122-
content = chan.recv(4096).decode('utf-8')
123-
error = chan.recv_stderr(4096).decode()
124-
if __DEBUG__ == 0:
125+
if __DEBUG__ == 0 :
126+
chan.exec_command('powershell -ExecutionPolicy Bypass -NonInteractive -File ' + cmd)
127+
exitCode = chan.recv_exit_status()
128+
content = chan.recv(4096).decode()
129+
error = chan.recv_stderr(4096).decode()
125130
chan = client.get_transport().open_session()
126131
##supression du script
127132
chan.exec_command('del ' + scriptName)
128-
del client
129-
if exitCode == 0:
130-
print(u.returncode(0,content.rstrip("\n")))
131-
exit(0)
133+
del client
134+
if exitCode == 0:
135+
print(u.returncode(0,content.rstrip("\n")))
136+
exit(0)
137+
else:
138+
print(u.returncode(1,content.rstrip("\n")))
139+
exit(1)
132140
else:
133-
print(u.returncode(1,content.rstrip("\n")))
134-
exit(1)
141+
print(u.returncode(0, "Backend in debug mode"))
135142

src/lib/backend_utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ def config(key,default=''):
1515
c=__CONFIG__['config']
1616
return c.get(key,default)
1717

18+
def get_config():
19+
items=__CONFIG__.items('config')
20+
data = {}
21+
for k, v in items:
22+
data[k] = v
23+
return data
1824

1925
def readjsoninput():
2026
input = stdin.read()

0 commit comments

Comments
 (0)