forked from KolibriOS/kolibrios
[WS] Move simple functions into lib
git-svn-id: svn://kolibrios.org@9370 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
904c78d4e4
commit
4e971e9d6d
@ -1,4 +1,4 @@
|
|||||||
#!/bin/python3
|
#!/usr/bin/python3
|
||||||
# Copyright Magomed Kostoev
|
# Copyright Magomed Kostoev
|
||||||
# Published under MIT license
|
# Published under MIT license
|
||||||
|
|
||||||
@ -7,14 +7,14 @@ import os
|
|||||||
def log(s, end = "\n"):
|
def log(s, end = "\n"):
|
||||||
print(s, end = end, flush = True)
|
print(s, end = end, flush = True)
|
||||||
|
|
||||||
def install_python_script(src, dst, tools_lib):
|
def install_python_script(src, dst, tools):
|
||||||
log(f"Copying {src}... ", end = "")
|
log(f"Copying {src}... ", end = "")
|
||||||
|
|
||||||
with open(src) as src_file:
|
with open(src) as src_file:
|
||||||
script = src_file.read()
|
script = src_file.read()
|
||||||
tools_lib_escaped = tools_lib.replace("\\", "\\\\")
|
tools = tools.replace("\\", "\\\\")
|
||||||
repl_from = "path_to_lib = '../lib'"
|
repl_from = "path_to_tools = '..'"
|
||||||
repl_to = f"path_to_lib ='{tools_lib_escaped}'"
|
repl_to = f"path_to_tools ='{tools}'"
|
||||||
script = script.replace(repl_from, repl_to, 1)
|
script = script.replace(repl_from, repl_to, 1)
|
||||||
with open(dst, "w") as dst_file:
|
with open(dst, "w") as dst_file:
|
||||||
dst_file.write(script)
|
dst_file.write(script)
|
||||||
@ -24,11 +24,10 @@ def install_python_script(src, dst, tools_lib):
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
tools_get_started_py = os.path.abspath(__file__)
|
tools_get_started_py = os.path.abspath(__file__)
|
||||||
tools = os.sep.join(tools_get_started_py.split(os.sep)[:-1])
|
tools = os.sep.join(tools_get_started_py.split(os.sep)[:-1])
|
||||||
tools_lib = os.sep.join([tools, "lib"])
|
|
||||||
tools_workspace = os.sep.join([tools, "workspace"])
|
tools_workspace = os.sep.join([tools, "workspace"])
|
||||||
# Copy scripts from _tools/workspace to current folder, but let them know
|
# Copy scripts from _tools/workspace to current folder, but let them know
|
||||||
# where the _tools/lib is (change their value of tools_lib variable)
|
# where the _tools/lib is (change their value of tools variable)
|
||||||
tools_workspace_run_py = os.sep.join([tools_workspace, "run.py"])
|
tools_workspace_run_py = os.sep.join([tools_workspace, "run.py"])
|
||||||
tools_workspace_build_py = os.sep.join([tools_workspace, "build.py"])
|
tools_workspace_build_py = os.sep.join([tools_workspace, "build.py"])
|
||||||
install_python_script(tools_workspace_run_py, "run.py", tools_lib)
|
install_python_script(tools_workspace_run_py, "run.py", tools)
|
||||||
install_python_script(tools_workspace_build_py, "build.py", tools_lib)
|
install_python_script(tools_workspace_build_py, "build.py", tools)
|
||||||
|
4
_tools/lib/logging.py
Normal file
4
_tools/lib/logging.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
def log(s, end = "\n"):
|
||||||
|
print(s, end = end, flush = True)
|
||||||
|
|
||||||
|
|
8
_tools/lib/network.py
Normal file
8
_tools/lib/network.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import urllib.request
|
||||||
|
|
||||||
|
def download(link, path):
|
||||||
|
log(f"Downloading {path}... ", end = "")
|
||||||
|
urllib.request.urlretrieve(link, path)
|
||||||
|
log("Done.")
|
||||||
|
|
||||||
|
|
16
_tools/lib/platform.py
Normal file
16
_tools/lib/platform.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def path(*args):
|
||||||
|
return os.sep.join(args)
|
||||||
|
|
||||||
|
def is_win32():
|
||||||
|
return True if sys.platform == "win32" else False
|
||||||
|
|
||||||
|
def is_linux():
|
||||||
|
return True if sys.platform == "linux" or sys.platform == "linux2" else False
|
||||||
|
|
||||||
|
def is_osx():
|
||||||
|
return True if sys.platform == "darwin" else False
|
||||||
|
|
||||||
|
|
@ -1,17 +1,17 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
path_to_lib = '../lib'
|
path_to_tools = '..'
|
||||||
sys.path.append(path_to_lib)
|
sys.path.append(path_to_tools)
|
||||||
|
|
||||||
import tupfile_parser
|
from lib.tupfile_parser import parse as parse_tupfile
|
||||||
|
|
||||||
def build():
|
def build():
|
||||||
if not os.path.exists("Tupfile.lua"):
|
if not os.path.exists("Tupfile.lua"):
|
||||||
print("No Tupfile.lua, can't build anything")
|
print("No Tupfile.lua, can't build anything")
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
tup_rules = tupfile_parser.parse("Tupfile.lua")
|
tup_rules = parse_tupfile("Tupfile.lua")
|
||||||
program_files = []
|
program_files = []
|
||||||
for rule in tup_rules:
|
for rule in tup_rules:
|
||||||
# TODO: Manage source dependencies
|
# TODO: Manage source dependencies
|
||||||
|
@ -7,10 +7,13 @@ import subprocess
|
|||||||
|
|
||||||
import build
|
import build
|
||||||
|
|
||||||
path_to_lib = '../lib'
|
path_to_tools = '..'
|
||||||
sys.path.append(path_to_lib)
|
sys.path.append(path_to_tools)
|
||||||
|
|
||||||
from makeflop import Floppy
|
from lib.makeflop import Floppy
|
||||||
|
from lib.platform import is_win32, path
|
||||||
|
from lib.logging import log
|
||||||
|
from lib.network import download
|
||||||
|
|
||||||
# TODO: Move into _tools/lib
|
# TODO: Move into _tools/lib
|
||||||
def get_file_directory(path):
|
def get_file_directory(path):
|
||||||
@ -23,32 +26,6 @@ def get_file_directory(path):
|
|||||||
else:
|
else:
|
||||||
return "." # Just a filename, let's return current folder
|
return "." # Just a filename, let's return current folder
|
||||||
|
|
||||||
# TODO: Move into _tools/lib
|
|
||||||
def is_win32():
|
|
||||||
return True if sys.platform == "win32" else False
|
|
||||||
|
|
||||||
# TODO: Move into _tools/lib
|
|
||||||
def is_linux():
|
|
||||||
return True if sys.platform == "linux" or sys.platform == "linux2" else False
|
|
||||||
|
|
||||||
# TODO: Move into _tools/lib
|
|
||||||
def is_osx():
|
|
||||||
return True if sys.platform == "darwin" else False
|
|
||||||
|
|
||||||
# TODO: Move into _tools/lib
|
|
||||||
def log(s, end = "\n"):
|
|
||||||
print(s, end = end, flush = True)
|
|
||||||
|
|
||||||
# TODO: Move into _tools/lib
|
|
||||||
def download(link, path):
|
|
||||||
log(f"Downloading {path}... ", end = "")
|
|
||||||
urllib.request.urlretrieve(link, path)
|
|
||||||
log("Done.")
|
|
||||||
|
|
||||||
# TODO: Move into _tools/lib
|
|
||||||
def path(*args):
|
|
||||||
return os.sep.join(args)
|
|
||||||
|
|
||||||
# TODO: Move into _tools/lib
|
# TODO: Move into _tools/lib
|
||||||
def run_qemu(start_dir = "workspace"):
|
def run_qemu(start_dir = "workspace"):
|
||||||
qemu_command = f"qemu-system-i386"
|
qemu_command = f"qemu-system-i386"
|
||||||
|
Loading…
Reference in New Issue
Block a user