annotate simporter.nim @ 391:68198310770b

add: function to zip directories, usefull when creating dists
author Sam <sam@basx.dev>
date Wed, 06 Dec 2023 00:37:34 +0700
parents 1727bec9ca2f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
390
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
1 import std/os
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
2 import std/paths
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
3 import std/dirs
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
4 import std/osproc
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
5 import std/cmdline
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
6 import std/strutils
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
7 import std/strformat
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
8
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
9 import ./semicongine/core/audiotypes
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
10
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
11 proc import_meshes*(files: seq[(string, string)]) =
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
12 let converter_script = currentSourcePath.parentDir().joinPath("scripts/blender_gltf_converter.py")
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
13
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
14 var args = @["--background", "--python", converter_script, "--"]
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
15 for (input, output) in files:
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
16 args.add input
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
17 args.add output
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
18
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
19 let p = startProcess("blender", args=args, options={poStdErrToStdOut, poUsePath})
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
20 let exitCode = p.waitForExit()
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
21 p.close()
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
22 if exitCode != 0:
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
23 raise newException(OSError, &"blender had exit code {exitCode}")
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
24
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
25 proc import_audio*(files: seq[(string, string)]) =
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
26 for (input, output) in files:
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
27 let p = startProcess("ffmpeg", args=["-y", "-i", input, "-ar", $AUDIO_SAMPLE_RATE, output], options={poStdErrToStdOut, poUsePath})
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
28 let exitCode = p.waitForExit()
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
29 p.close()
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
30 if exitCode != 0:
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
31 raise newException(OSError, &"ffmpeg had exit code {exitCode}")
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
32
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
33 when isMainModule:
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
34 var meshfiles: seq[(string, string)]
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
35 var audiofiles: seq[(string, string)]
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
36
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
37 for arg in commandLineParams():
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
38 if arg.count(':') != 1:
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
39 raise newException(Exception, &"Argument {arg} requires exactly one colon to separate input from output, but it contains {arg.count(':')} colons.")
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
40 let
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
41 input_output = arg.split(':', 1)
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
42 input = input_output[0]
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
43 output = input_output[1]
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
44 if not input.fileExists:
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
45 raise newException(IOError, &"Not found: {input}")
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
46 if not output.fileExists or input.fileNewer(output):
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
47 echo &"{output} is outdated"
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
48 if input.endsWith("blend"):
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
49 meshfiles.add (input, output)
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
50 elif input.endsWith("mp3") or input.endsWith("ogg") or input.endsWith("wav"):
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
51 audiofiles.add (input, output)
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
52 else:
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
53 raise newException(Exception, &"unkown file type: {input}")
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
54 Path(output.parentDir()).createDir()
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
55 else:
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
56 echo &"{output} is up-to-date"
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
57
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
58 import_meshes meshfiles
1727bec9ca2f did: finish importing system
Sam <sam@basx.dev>
parents:
diff changeset
59 import_audio audiofiles