Created
January 17, 2020 17:19
-
-
Save danielflira/4909069362c3a93a056b34d91b6d8e40 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import os | |
import subprocess | |
import configparser | |
def find(path): | |
paths = [path] | |
while len(paths) > 0: | |
path = paths.pop() | |
for entry in os.scandir(path): | |
if entry.is_dir(): | |
paths.append(entry.path) | |
else: | |
yield entry | |
def generate_lst(path): | |
paths = [] | |
for entry in find(path): | |
paths.append(os.path.abspath(entry.path)) | |
return ';'.join(paths) | |
class Appserver: | |
def __init__(self, path, includes=None): | |
self.path = path | |
self.environ = os.environ.copy() | |
self.includes = includes | |
def generate_lst(self, paths): | |
lst_path = os.path.abspath(os.path.join(self.path, 'files.lst')) | |
with open(lst_path, 'w') as fp: | |
for path in paths: | |
fp.write(generate_lst(path)) | |
return lst_path | |
def generate_includes(self, includes): | |
if includes == None: | |
return '' | |
return ';'.join([os.path.abspath(i) for i in includes]) | |
def generate_appserver_ini(self): | |
ini_path = os.path.abspath(os.path.join(self.path, 'appserver.ini')) | |
parser = configparser.ConfigParser() | |
parser.read_dict({ | |
'environment': { | |
'sourcepath': os.path.abspath(os.getcwd()), | |
'rpodb': 't', | |
'rpolanguage': 'p', | |
'rpoversion': '120', | |
} | |
}) | |
with open(ini_path, 'w') as fp: | |
fp.write('\n') | |
parser.write(fp) | |
return ini_path | |
def compile(self, environment, files, includes=None): | |
lst_path = self.generate_lst(files) | |
ini_path = self.generate_appserver_ini() | |
includes = self.generate_includes(includes or self.includes) | |
command = ['./appsrvlinux', | |
'-compile', | |
'-src={}'.format(self.path), | |
'-env={}'.format(environment), | |
'-files={}'.format(lst_path), | |
'-includes={}'.format(includes)] | |
print(command) | |
process = subprocess.run(command, | |
env=self.environ, | |
cwd=self.path) | |
os.unlink(lst_path) | |
appserver = Appserver('./appserver', ['./includes/']) | |
appserver.compile('environment', ['./src/']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment