File: gen_include.py

package info (click to toggle)
gle-graphics-library 4.3.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,120 kB
  • sloc: python: 183; makefile: 2
file content (59 lines) | stat: -rw-r--r-- 1,528 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#
# -- gen_include.py - generate gle-library.gle include  file from all files in include folder
#
import os
import platform
from enum import Enum
import pathlib
import glob
from datetime import datetime
import yaml


include_filename = "gle-library.gle"
include_folder   = "../include"
glob_pattern        = '*.gle'

class OS(Enum):
    WINDOWS = 1
    MACOS = 2
    LINUX = 3

this_os = OS.LINUX
os_type = platform.system()
if os_type == "Windows":
    this_os = OS.WINDOWS
elif os_type == "Linux":
    this_os = OS.LINUX
elif os_type == "Darwin":
    this_os = OS.MACOS
else:
    print(f"Unknown operating system: {os_type} - assuming Linux")

def enumerate_files(root_dir, pattern):
    files = []
    for dirpath, dirnames, filenames in os.walk(root_dir):
        for filename in glob.glob(os.path.join(dirpath, pattern)):
            files.append(filename)
    return files

#gle_files  = enumerate_files(include_folder, glob_pattern)

cwd = os.getcwd()
os.chdir(include_folder)
gle_files = []
for filename in glob.glob(glob_pattern):
    gle_files.append(filename)

with open( include_filename, "w") as f:
    f.write(f"!\n")
    f.write(f"! -- {include_filename} -- Global include filename for all routines in the GLE library\n")
    f.write(f"!\n")
    f.write(f"!    Automatically generated by scripts/gen_include.py\n")
    f.write(f"!\n")
    for file in gle_files:
        if(file != include_filename):
            f.write(f"include \"{file}\"\n")

os.chdir(cwd)
print(f"{include_filename} generated successfully.")