2 Commits

Author SHA1 Message Date
  root db105c94fd @fixed nbgrader 3 years ago
  root 42b23b396b @fixed 3 years ago
1 changed files with 183 additions and 126 deletions
  1. 183
    126
      app.py

+ 183
- 126
app.py View File

@@ -1,3 +1,4 @@
1
+# coding: utf-8
1 2
 import os
2 3
 import json
3 4
 import requests
@@ -21,10 +22,14 @@ logging.basicConfig(format='%(asctime)s %(message)s')
21 22
 logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))
22 23
 
23 24
 
25
+def executeSudoCmd(myCmd):
26
+    myCmd = sudoCmd(myCmd)
27
+    executeCmd(myCmd)
28
+
24 29
 
25 30
 def sudoCmd(cmd):
26
-    cmd.replace("'","\'")
27
-    return 'sudo sh -c \'' + cmd + '\''
31
+    return sudoPath + cmd
32
+    #return sudoPath + ' /bin/sh -c \'' + cmd.replace('\'', "\\'") + '\''
28 33
 
29 34
 """
30 35
  print and save content
@@ -90,6 +95,70 @@ def getArgValue(name):
90 95
 
91 96
     return value
92 97
 
98
+def unlockSourceCmd(jupyterName):
99
+    return chattrPath + ' -i \'' +  buildPath(['home',jupyterName,'source']) + '\''
100
+
101
+def lockSourceCmd(jupyterName):
102
+    return chattrPath + ' +i \'' +  buildPath(['home',jupyterName,'source']) + '\''
103
+
104
+def rmCmd(path):
105
+    return rmPath + '-rf ' + path
106
+
107
+def chownCmd(path,user):
108
+    return chownPath + ' -R ' + user + ':' + user + ' \'' + path + '\''
109
+
110
+def chmodCmd(path,chmod):
111
+    return chmodPath + ' ' + chmod + ' \'' + path + '\''
112
+
113
+def mvCmd(pathFrom,pathTo,userTo):
114
+    return [
115
+        mvPath + ' \'' + pathFrom + '\' \'' + pathTo + '\'',
116
+        chownCmd(pathTo,userTo)
117
+    ]
118
+def mkdirCmd(path,user,chmod=770):
119
+    if type(chmod).__name__ == 'int' :
120
+        chmod = str(chmod)
121
+
122
+    result = [
123
+        mkdirPath + ' -p \'' + path + '\'',
124
+    ]
125
+    if user != None:
126
+        result.append(chownCmd(path,user))
127
+    if chmod != None:
128
+         result.append(chmodCmd(path,chmod))
129
+         
130
+    return result
131
+
132
+def executeSudoCmds(cmds):
133
+    end = []
134
+    for cmd in cmds:
135
+        if type(cmd).__name__ == 'list' :
136
+            for subCmd in cmd:
137
+                if subCmd.find('cd ') == -1:
138
+                    end.append(sudoCmd(subCmd))
139
+                else:
140
+                    end.append(subCmd)
141
+
142
+        else:
143
+            if cmd.find('cd ') == -1:
144
+                end.append(sudoCmd(cmd))
145
+            else:
146
+                end.append(cmd)
147
+
148
+    cmd = (' ' + cmdsSeparator +' ').join(end)
149
+    executeCmd(cmd)
150
+    #executeSudoCmd('; '.join(end))
151
+
152
+def executeCmd(cmd):
153
+    dump(cmd)
154
+    os.system(cmd)
155
+
156
+def copyCmd(pathFrom,pathTo,userTo):
157
+    return [
158
+        cpPath + ' -r \'' + pathFrom + '\' \'' + pathTo + '\'',
159
+        chownCmd(pathTo,userTo)
160
+    ]
161
+
93 162
 # configurations par défaut
94 163
 
95 164
 # hote par défaut: 0.0.0.0
@@ -111,7 +180,7 @@ sudoPath = '/usr/bin/sudo '
111 180
 chattrPath = '/usr/bin/chattr '
112 181
 chownPath = '/bin/chown '
113 182
 runuserPath = '/sbin/runuser '
114
-jupyterPath = '/usr/bin/jupyter '
183
+jupyterPath = 'jupyter '
115 184
 mvPath = '/bin/mv '
116 185
 cpPath = '/bin/cp '
117 186
 rmPath = '/bin/rm  '
@@ -122,6 +191,9 @@ chmodPath = '/bin/chmod '
122 191
 grepPath = '/bin/grep '
123 192
 mkdirPath = '/bin/mkdir '
124 193
 
194
+
195
+cmdsSeparator = '&&'
196
+
125 197
 # début configuration --
126 198
 """
127 199
 configurations
@@ -205,10 +277,10 @@ api = Api(app)
205 277
 currentUserName = os.popen('echo "$USER"').read().rstrip()
206 278
 
207 279
 def changeFolderRightForGroup(jupyterUsername):
208
-    return sudoPath + ' ' + usermodPath + ' -a -G ' + jupyterUsername + ' ' + currentUserName
280
+    return usermodPath + ' -a -G ' + jupyterUsername + ' ' + currentUserName
209 281
 
210 282
 def addCurrentUserToJupyterUserGroup(jupyterUsername):
211
-    return sudoPath + ' ' + chmodPath + ' 770 ' + buildPath(['home',jupyterUsername])
283
+    return chmodPath + ' 770 ' + buildPath(['home',jupyterUsername])
212 284
 
213 285
 
214 286
 
@@ -229,16 +301,13 @@ def onRunCallback():
229 301
     # ajoute l'utilisateur courant au groupe de l'utilisateur jupyter
230 302
     for jupyterUser in allJupyterUsers:
231 303
         cmds.append(changeFolderRightForGroup(jupyterUser))
232
-    separator = ' && '
233
-    dump(separator.join(cmds))
234
-    dump(os.popen(separator.join(cmds)).read())
304
+    executeSudoCmds(cmds)
235 305
 
236 306
     # change les droits des dossiers pour leur attribuer les groupes
237 307
     cmds = []
238 308
     for jupyterUser in allJupyterUsers:
239 309
         cmds.append(addCurrentUserToJupyterUserGroup(jupyterUser))
240
-    dump(separator.join(cmds))
241
-    os.system(separator.join(cmds))
310
+    executeSudoCmds(cmds)
242 311
 
243 312
 onRunCallback()
244 313
 
@@ -270,7 +339,7 @@ va dans le repertoire de l'utilisateur
270 339
 @param username
271 340
 """
272 341
 def goToUser(username):
273
-    return runAsUser(username,'cd /home/' + username)
342
+    return 'cd /home/' + username
274 343
 
275 344
 
276 345
 """
@@ -417,16 +486,16 @@ ecrit un fichier
417 486
 
418 487
 """
419 488
 def write(username,path,content):
489
+    # écrit le fichier temporaire
420 490
     tempPath = '/tmp/' + uuid.uuid4().hex
421 491
     f = open(tempPath, "w")
422 492
     f.write(content)
423 493
     f.close()
424 494
 
425
-    myCmd = sudoPath + ' ' + mvPath + ' \'' + tempPath + '\' \'' + path + '\''
426
-    myCmd += ' && ' + sudoPath + ' ' + chownPath + ' ' + username + ':' + username + ' \'' + path + '\''
427
-
428
-    dump(myCmd)
429
-    os.system(myCmd)
495
+    # déplace le fichier temporaire dans le bon dossier
496
+    myCmds = []
497
+    myCmds.append(mvCmd(tempPath,path,username))
498
+    executeSudoCmds(myCmds)
430 499
 
431 500
 """
432 501
 
@@ -577,7 +646,6 @@ def initUserSpace(jupyterUsername,folder,notebookname,fromurl = None,content = '
577 646
     path = getNotebookPath(jupyterUsername,folder,notebookname)
578 647
     dump('initUserSpace')
579 648
    
580
-
581 649
     if fromurl != None:
582 650
         data = fromurl.split('/')
583 651
         sizeOfData = len(data)
@@ -592,44 +660,48 @@ def initUserSpace(jupyterUsername,folder,notebookname,fromurl = None,content = '
592 660
 
593 661
         # dossier ./source
594 662
         # débloquage de l'origine
595
-        copyCmd = sudoPath + ' ' + chattrPath + ' -i \'' +  buildPath(['home',fromJupyterUuid,'source']) + '\''
596
-        copyCmd += ' && ' + sudoPath + ' ' + chattrPath + ' -i \'' +  buildPath(['home',jupyterUsername,'source']) + '\''
597
-        # déplace le dossier
598
-        copyCmd += ' && ' + sudoPath + ' ' + mvPath + ' \'' + buildPath(['home',fromJupyterUuid,'source',fromFolder]) + '\' \'' + buildPath(['home',jupyterUsername,'source',folder]) + '\''
599
-        # corrige les droits
600
-        copyCmd += ' && ' + chownPath + ' -R ' + jupyterUsername + ' \'' + buildPath(['home',fromJupyterUuid,'source',folder]) + '\''
601
-        copyCmd += ' && ' + sudoPath + ' ' + chattrPath + ' +i \'' +  buildPath(['home',fromJupyterUuid,'source']) + '\''
602
-        copyCmd += ' && ' + sudoPath + ' ' + chattrPath + ' +i \'' +  buildPath(['home',jupyterUsername,'source']) + '\''
603
-        dump(copyCmd)
604
-        os.system(copyCmd)
605
-
606
-        dump( buildPath(['home',fromJupyterUuid,'source',fromFolder]))
607
-        dump( buildPath(['home',jupyterUsername,'source',folder]) )
663
+        mvCmds = []
664
+        mvCmds.append(unlockSourceCmd(fromJupyterUuid))
665
+        mvCmds.append(unlockSourceCmd(jupyterUsername))
608 666
         
667
+        # déplace le dossier
668
+        mvCmds.append(mvCmd(
669
+            buildPath(['home',fromJupyterUuid,'source',fromFolder]),
670
+            buildPath(['home',jupyterUsername,'source',folder])
671
+        ))
672
+
673
+        mvCmds.append(lockSourceCmd(fromJupyterUuid))
674
+        mvCmds.append(lockSourceCmd(jupyterUsername))
675
+
676
+        executeSudoCmds(mvCmds)
677
+
609 678
         # déplace le fichier du notebook s'il existe
610
-        moveCmd = sudoPath + ' ' + mvPath + ' \'' + buildPath(['home',jupyterUsername,'source',folder,fromNotebookName]) + '\' \'' + buildPath(['home',jupyterUsername,'source',folder,notebookname]) + '\''
611
-        dump(moveCmd)
612
-        os.system(moveCmd)
679
+        moveCmd = mvCmd(
680
+            buildPath(['home',jupyterUsername,'source',folder,fromNotebookName]),
681
+            buildPath(['home',jupyterUsername,'source',folder,notebookname]),
682
+            jupyterUsername
683
+        )
684
+        executeSudoCmds(moveCmd)
613 685
 
614 686
     else:
615 687
          # -- config notebook jupyter
616 688
         # creation des dossiers
617 689
 
618 690
         # dossier ./source
619
-        myCmd =  sudoPath + ' -u ' + jupyterUsername + ' ' + mkdirPath + ' -p \'' + buildPath(['home',jupyterUsername,'source']) + '\''
620
-        dump(myCmd) 
621
-        dump(os.system(myCmd))
691
+        mkdirCmds = mkdirCmd(buildPath(['home',jupyterUsername,'source']),jupyterUsername)
692
+        executeSudoCmds(mkdirCmds)
622 693
         
623 694
         # débloquage de source
624
-        myCmd = sudoPath + ' ' + chattrPath + ' -i \'' + buildPath(['home',jupyterUsername,'source']) + '\''
695
+        myCmds = []
696
+        myCmds.append(unlockSourceCmd(jupyterUsername))
697
+
625 698
         # dossier ./[folder]
626
-        myCmd += ' && ' + sudoPath + ' -u ' + jupyterUsername + ' ' + mkdirPath + ' \'' + buildPath(['home',jupyterUsername,'source',folder]) + '\''
699
+        myCmds.append(mkdirCmd(buildPath(['home',jupyterUsername,'source',folder]),jupyterUsername))
700
+
627 701
         # bloquage du source
628
-        myCmd += ' && ' + sudoPath + ' ' + ' ' + chattrPath + ' +i \'' + buildPath(['home',jupyterUsername,'source']) + '\''
702
+        myCmds.append(lockSourceCmd(jupyterUsername))
629 703
 
630
-        dump(myCmd)   
631
-        dump(os.popen(myCmd).read())
632
-        #os.system(myCmd)
704
+        executeSudoCmds(myCmds)
633 705
 
634 706
     if content != '': 
635 707
         write(jupyterUsername,buildPath(['home',jupyterUsername,'source',folder,notebookname]),content)
@@ -686,6 +758,38 @@ def index():
686 758
 def cleanQuotes(string):
687 759
     return urllib.parse.unquote_plus(string)
688 760
 
761
+def nbGraderInstallCmd(user,options):
762
+    result = [
763
+        goToUser(user),
764
+        jupyterPath + ' ' + nbextensionPath + ' install --user --py nbgrader',
765
+        jupyterPath + ' ' + nbextensionPath + ' disable --user --py nbgrader'
766
+    ]
767
+
768
+    for option in options:
769
+        result.append(jupyterPath + ' ' + nbextensionPath + ' enable --user ' + option)
770
+    
771
+    return sudoCmd(runAsUser(user,(' ' + cmdsSeparator + ' ').join(result)))
772
+
773
+def writeConfigurations(jupyterUsername,useSource=True):
774
+    # config du notebook jupyter => changement de la racine d'exploration
775
+    mkdirCmds = mkdirCmd(buildPath(['home',jupyterUsername,'.jupyter']),jupyterUsername,770)
776
+    executeSudoCmds(mkdirCmds)
777
+
778
+    configContents = []
779
+    if useSource:
780
+        configContents.append('c.FileContentsManager.root_dir=\'' + buildPath(['home',jupyterUsername,'source']) + '\'')
781
+        configContents.append('c.NotebookApp.notebook_dir=\'' + buildPath(['home',jupyterUsername,'source']) + '\'')
782
+    
783
+    configContents.append('c.MappingKernelManager.cull_idle_timeout = ' + timeout)
784
+    configContents.append('c.MappingKernelManager.shutdown_no_activity_timeout = ' + timeout)
785
+    
786
+    write(jupyterUsername,buildPath(['home',jupyterUsername,'.jupyter','jupyter_notebook_config.py']),"\n".join(configContents) + "\n")
787
+
788
+    # vérouille les configurations
789
+    #myCmd = 'chattr +i ' +  buildPath(['home',jupyterUsername,'.jupyter'])
790
+    #myCmd += ' && chattr +i ' +  buildPath(['home',jupyterUsername,'.jupyter','jupyter_notebook_config.py'])
791
+    #os.system(myCmd)
792
+
689 793
 """
690 794
 url: [host]/trainer/<username>/<folder>/<notebookName>
691 795
 """
@@ -726,42 +830,18 @@ def createTrainerServer(username,folder,notebookname):
726 830
         # + change les droits du groupe sur le dossier de l'utilisateur
727 831
         jupyterUsername = getJupyterName(username)
728 832
         cmd = changeFolderRightForGroup(jupyterUsername)
729
-        dump(cmd)
730
-        os.system(cmd)
833
+        executeSudoCmd(cmd)
731 834
 
732 835
         cmd = addCurrentUserToJupyterUserGroup(jupyterUsername)
733
-        dump(cmd)
734
-        os.system(cmd)
836
+        executeSudoCmd(cmd)
735 837
 
736 838
         # configuration des extensions de l'utilisateur
737 839
         # config formateur de nbgrader
738
-        myCmd = goToUser(jupyterUsername)
739
-        myCmd += ' && ' + jupyterPath + ' ' + nbextensionPath + ' install --user --py nbgrader'
740
-        myCmd += ' && ' +  jupyterPath + ' ' + nbextensionPath + ' disable --user --py nbgrader'
741
-        myCmd += ' && ' +  jupyterPath + ' ' + nbextensionPath + ' enable --user create_assignment/main'
742
-        myCmd += ' && ' +  jupyterPath + ' ' + nbextensionPath + ' enable --user validate_assignment/main'
743
-        
744
-        myCmd = sudoCmd(myCmd)
745
-        dump(myCmd)
746
-        os.system(myCmd)
747
-
748
-        # config du notebook jupyter => changement de la racine d'exploration
749
-        myCmd = sudoPath + ' ' + mkdirPath + ' -p ' + buildPath(['home',jupyterUsername,'.jupyter'])
750
-        myCmd += ' && ' + sudoPath + ' ' + chownPath + ' ' + jupyterUsername + ' ' + buildPath(['home',jupyterUsername,'.jupyter'])
751
-        myCmd += ' && ' + sudoPath + ' ' + chmodPath + ' 770 ' + ' ' + buildPath(['home',jupyterUsername,'.jupyter'])
752
-        os.system(myCmd)
840
+        myCmds = nbGraderInstallCmd(jupyterUsername,['create_assignment/main','validate_assignment/main'])
841
+        executeCmd(myCmds)
753 842
 
754 843
         #myCmd += ' && ' + sudoPath + ' -u ' + currentUserName + ' ' + chmodPath + ' 770 ' + buildPath(['home',jupyterUsername,'.jupyter'])
755
-        configContent = 'c.FileContentsManager.root_dir=\'' + buildPath(['home',jupyterUsername,'source']) + '\'' + "\n"
756
-        configContent += 'c.NotebookApp.notebook_dir=\'' + buildPath(['home',jupyterUsername,'source']) + '\'' + "\n"
757
-        configContent += 'c.MappingKernelManager.cull_idle_timeout = ' + timeout + "\n"
758
-        configContent += 'c.MappingKernelManager.shutdown_no_activity_timeout = ' + timeout + "\n"
759
-        write(jupyterUsername,buildPath(['home',jupyterUsername,'.jupyter','jupyter_notebook_config.py']),configContent)
760
-
761
-        # vérouille les configurations
762
-        myCmd = 'chattr +i ' +  buildPath(['home',jupyterUsername,'.jupyter'])
763
-        myCmd += ' && chattr +i ' +  buildPath(['home',jupyterUsername,'.jupyter','jupyter_notebook_config.py'])
764
-        os.system(myCmd)
844
+        writeConfigurations(jupyterUsername)
765 845
 
766 846
         #dump(os.popen(myCmd).read())
767 847
 
@@ -814,49 +894,26 @@ def createStudentServer(trainername,username,folder,notebookname):
814 894
     jupyterUsername = getJupyterName(username)
815 895
     trainerJupyterUsername = getJupyterName(trainername)
816 896
 
817
-#
818
-# cas d'une creation de compte utilisateur, il faut le configurer en tant que formateur
897
+    #
898
+    # cas d'une creation de compte utilisateur, il faut le configurer en tant que formateur
819 899
     if 'token' in result['resultUser'] and ((not 'status' in result['result']) or (result['result']['status'] != '400')):
820 900
         # ajout l'utilisateur courant au groupe du nouvel utiliosateur
821 901
         # + change les droits du groupe sur le dossier de l'utilisateur
822 902
         jupyterUsername = getJupyterName(username)
823 903
         cmd = changeFolderRightForGroup(jupyterUsername)
824
-        dump(cmd)
825
-        os.system(cmd)
904
+        executeSudoCmd(cmd)
826 905
 
827 906
         cmd = addCurrentUserToJupyterUserGroup(jupyterUsername)
828
-        dump(cmd)
829
-        os.system(cmd)
907
+        executeSudoCmd(cmd)
830 908
 
831
-        # configuration des extensions de l'utilisateur
832
-        # config formateur de nbgrader
833
-        myCmd = goToUser(jupyterUsername)
834
-        myCmd += ' && ' + nbextensionPath + ' install --user --py nbgrader'
835
-        myCmd += ' && ' + nbextensionPath + ' disable --user --py nbgrader'
836
-        myCmd = runAsUser(jupyterUsername,myCmd)
837
-        dump(myCmd)
838
-        os.system(myCmd)
909
+        myCmd = nbGraderInstallCmd(jupyterUsername,[])
910
+        executeCmd(myCmd)
839 911
 
840 912
         # config du notebook jupyter => changement de la racine d'exploration
841
-        myCmd = sudoPath + ' ' + mkdirPath + ' -p ' + buildPath(['home',jupyterUsername,'.jupyter'])
842
-        myCmd += ' && ' + sudoPath + ' ' + chownPath + ' ' + jupyterUsername + ' ' + buildPath(['home',jupyterUsername,'.jupyter'])
843
-        myCmd += ' && ' + sudoPath + ' ' + chmodPath + ' 770 ' + ' ' + buildPath(['home',jupyterUsername,'.jupyter'])
844
-        os.system(myCmd)
913
+        mkdirCmds = mkdirCmd(buildPath(['home',jupyterUsername,'.jupyter']),jupyterUsername,770)
914
+        executeSudoCmds(mkdirCmds)
845 915
 
846
-        #myCmd += ' && ' + sudoPath + ' -u ' + currentUserName + ' ' + chmodPath + ' 770 ' + buildPath(['home',jupyterUsername,'.jupyter'])
847
-        configContent = 'c.FileContentsManager.root_dir=\'' + buildPath(['home',jupyterUsername,'source']) + '\'' + "\n"
848
-        configContent += 'c.NotebookApp.notebook_dir=\'' + buildPath(['home',jupyterUsername,'source']) + '\'' + "\n"
849
-        configContent += 'c.MappingKernelManager.cull_idle_timeout = ' + timeout + "\n"
850
-        configContent += 'c.MappingKernelManager.shutdown_no_activity_timeout = ' + timeout + "\n"
851
-        write(jupyterUsername,buildPath(['home',jupyterUsername,'.jupyter','jupyter_notebook_config.py']),configContent)
852
-
853
-        # vérouille les configurations
854
-        myCmd = 'chattr +i ' +  buildPath(['home',jupyterUsername,'.jupyter'])
855
-        myCmd += ' && chattr +i ' +  buildPath(['home',jupyterUsername,'.jupyter','jupyter_notebook_config.py'])
856
-        os.system(myCmd)
857
-
858
-        #configPath =  '/home/' + jupyterUsername + '}/.jupyter/jupyter_notebook_config.py'
859
-        #write('root',configPath,configContent)
916
+        writeConfigurations(jupyterUsername)
860 917
 
861 918
         # stop server instance
862 919
         # 400 = deja stoppe
@@ -866,20 +923,19 @@ def createStudentServer(trainername,username,folder,notebookname):
866 923
     initUserSpace(jupyterUsername,folder,notebookname,None)
867 924
 
868 925
     # copie du dossier formateur
869
-    fromPath = buildPath(['home',trainerJupyterUsername,'source',folder])
870
-    toPath = buildPath(['home',jupyterUsername,'source'])
871
-    
872
-    # dévérouillage des dossiers
873
-    copyCmd = ' ' + sudoPath + ' ' + chattrPath + ' -i \'' + buildPath(['home',jupyterUsername,'source']) + '\''
874
-    copyCmd += '&& ' + sudoPath + ' ' + chattrPath + ' -i \'' + buildPath(['home',trainerJupyterUsername,'source']) + '\''
875
-    # copie
876
-    copyCmd += '&& ' + sudoPath + ' ' + cpPath + ' -r \'' + fromPath + '\' \'' + toPath + '\''
877
-    copyCmd += ' && ' + sudoPath + ' ' + chownPath + ' -R ' + jupyterUsername + ' \'' + toPath + '\''
878
-    # vérouillage des dossiers
879
-    copyCmd += ' && ' + sudoPath + ' ' + chattrPath + ' +i \'' + buildPath(['home',jupyterUsername,'source']) + '\''
880
-    copyCmd += ' && ' + sudoPath + ' ' + chattrPath + ' +i \'' + buildPath(['home',trainerJupyterUsername,'source']) + '\''
881
-    dump(copyCmd)
882
-    os.system(copyCmd)
926
+    copyCmds = []
927
+    copyCmds.append(unlockSourceCmd(jupyterUsername))
928
+    copyCmds.append(unlockSourceCmd(trainerJupyterUsername))
929
+    copyCmds.append(
930
+        copyCmd(
931
+            buildPath(['home',trainerJupyterUsername,'source',folder]),
932
+            buildPath(['home',jupyterUsername,'source']),
933
+            jupyterUsername
934
+        )
935
+    )
936
+    copyCmds.append(lockSourceCmd(jupyterUsername))
937
+    copyCmds.append(lockSourceCmd(trainerJupyterUsername))
938
+    executeSudoCmds(copyCmds)
883 939
 
884 940
     # retourne l'url menant au notebook + les infos token utilisateur en cas d'ouverture de son serveur
885 941
     userToken = None
@@ -1150,21 +1206,22 @@ def cloneNotebook(fromuuid,touuid,fromfolder,tofolder,reset):
1150 1206
     dump(pathTo)
1151 1207
 
1152 1208
     # dévérouille les dossiers
1153
-    cloneCommand =  sudoPath + ' ' + chattrPath + ' -i \'' + pathSourceFrom + '\''
1154
-    cloneCommand +=  ' && ' + sudoPath + ' ' + chattrPath + ' -i \'' + pathSourceTo + '\''
1209
+    cloneCommands = []
1210
+    cloneCommands.append(unlockSourceCmd(jupyterUuidFrom))
1211
+    cloneCommands.append(unlockSourceCmd(jupyterUuidTo))
1212
+
1155 1213
     if os.path.isdir(pathFrom) : 
1156 1214
         if os.path.isdir(pathTo) and reset == '1' and pathFrom != pathTo: 
1157 1215
             # suppression
1158
-            cloneCommand += ' && ' + sudoPath + ' ' + rmPath + ' -rf \'' + pathTo + '\''
1216
+            cloneCommands.append(rmCmd(pathTo))
1217
+
1159 1218
         # copie
1160
-        cloneCommand  += ' && ' + sudoPath + ' ' + cpPath + ' -r \'' + pathFrom + '/\' \'' + pathTo + '/\''
1161
-        cloneCommand  += ' && ' + sudoPath + ' ' + chownPath + ' -R ' + jupyterUuidTo + ' \'' + pathSourceTo + '\''
1219
+        cloneCommands.append(copyCmd(pathFrom,buildPath(['home',jupyterUuidTo,'source','']),jupyterUuidTo))
1162 1220
 
1163
-    cloneCommand +=  ' && ' + sudoPath + ' ' + chattrPath + ' +i \'' + pathSourceFrom + '\''
1164
-    cloneCommand +=  ' && ' + sudoPath + ' ' + chattrPath + ' +i \'' + pathSourceTo + '\''
1221
+    cloneCommands.append(lockSourceCmd(jupyterUuidFrom))
1222
+    cloneCommands.append(lockSourceCmd(jupyterUuidTo))
1165 1223
 
1166
-    dump(cloneCommand)
1167
-    os.system(cloneCommand)
1224
+    executeSudoCmds(cloneCommands)
1168 1225
 
1169 1226
     return json.dumps({ 'result':True,'folder': tofolder }),200
1170 1227
 

Loading…
Cancel
Save