nix-overlay/pkgs/test-script/default.nix

37 lines
1 KiB
Nix
Raw Normal View History

2023-09-03 23:24:37 +03:00
{ writers, python3Packages }:
writers.writePython3Bin "test-script" { libraries = []; } ''
import sys
import os
2023-09-04 23:07:34 +03:00
import json
2023-09-03 23:24:37 +03:00
2023-09-04 23:07:34 +03:00
def main():
2023-09-03 23:24:37 +03:00
arg = sys.argv[1]
2023-09-04 23:07:34 +03:00
data = json.loads(arg)
paths = data.get('filesMeta')
path = data.get('path')
for el in paths:
if (el.get('path') is None and el.get('type') == 'folder'):
if (not os.path.exists((path + el.get('name')))):
os.makedirs(path + el.get('name'))
else:
filePath = el.get('path')
type = el.get('type')
name = el.get('name')
rewrite = el.get('rewrite')
newPath = path + filePath + '/'
if (type == 'file'):
if (rewrite and not os.path.exists((newPath + name))):
file = open(newPath + name, 'w')
file.write(str(el))
file.close()
if (type == 'folder'):
if (rewrite and not os.path.exists((newPath + name))):
os.makedirs(newPath + name)
2023-09-03 23:24:37 +03:00
2023-09-04 23:07:34 +03:00
main()
''