mirror of https://github.com/jumpserver/jumpserver
优化 playbook ide
parent
7a5195e91e
commit
d68ed57eb9
|
@ -88,20 +88,26 @@ class PlaybookFileBrowserAPIView(APIView):
|
||||||
|
|
||||||
is_directory = request.data.get('is_directory', False)
|
is_directory = request.data.get('is_directory', False)
|
||||||
content = request.data.get('content', '')
|
content = request.data.get('content', '')
|
||||||
|
name = request.data.get('name', '')
|
||||||
|
|
||||||
|
def find_new_name(p, is_file=False):
|
||||||
|
if not p:
|
||||||
|
if is_file:
|
||||||
|
p = 'new_file.yml'
|
||||||
|
else:
|
||||||
|
p = 'new_dir'
|
||||||
|
np = os.path.join(full_path, p)
|
||||||
|
n = 0
|
||||||
|
while os.path.exists(np):
|
||||||
|
n += 1
|
||||||
|
np = os.path.join(full_path, '{}({})'.format(p, n))
|
||||||
|
return np
|
||||||
|
|
||||||
if is_directory:
|
if is_directory:
|
||||||
new_file_path = os.path.join(full_path, 'new_dir')
|
new_file_path = find_new_name(name)
|
||||||
i = 0
|
|
||||||
while os.path.exists(new_file_path):
|
|
||||||
i += 1
|
|
||||||
new_file_path = os.path.join(full_path, 'new_dir({})'.format(i))
|
|
||||||
os.makedirs(new_file_path)
|
os.makedirs(new_file_path)
|
||||||
else:
|
else:
|
||||||
new_file_path = os.path.join(full_path, 'new_file.yml')
|
new_file_path = find_new_name(name, True)
|
||||||
i = 0
|
|
||||||
while os.path.exists(new_file_path):
|
|
||||||
i += 1
|
|
||||||
new_file_path = os.path.join(full_path, 'new_file({}).yml'.format(i))
|
|
||||||
with open(new_file_path, 'w') as f:
|
with open(new_file_path, 'w') as f:
|
||||||
f.write(content)
|
f.write(content)
|
||||||
|
|
||||||
|
@ -118,7 +124,6 @@ class PlaybookFileBrowserAPIView(APIView):
|
||||||
}
|
}
|
||||||
if not is_directory:
|
if not is_directory:
|
||||||
new_node['iconSkin'] = 'file'
|
new_node['iconSkin'] = 'file'
|
||||||
|
|
||||||
return Response(new_node)
|
return Response(new_node)
|
||||||
|
|
||||||
def patch(self, request, **kwargs):
|
def patch(self, request, **kwargs):
|
||||||
|
|
Loading…
Reference in New Issue