<div dir="ltr"><div><div><div><div><div><div><div><div><div>Dear devs,<br><br></div>What do you think if we move all the function that at the moment are contained in <span style="font-family:monospace,monospace">`/lib/init/grass.py`</span> into a new subfolder under <span style="font-family:monospace,monospace">`/lib/python`</span>?<br><br></div>The main advantages that I see are:<br><br></div>- start a python script in GRASS just setting the the python path and then I can use the same functions that are defined for the normal GRASS start up, without duplicate code;<br></div>- We can add unittest for the start up functions<br></div>- We can remove code duplication between grass.init and grass.script.core<br><br><br></div><div>What do you think?<br></div><div><br></div>I did the changes and at least on my computer GRASS is working, all the changes are available at this link:<br><br><a href="https://git.osgeo.org/gogs/zarch/grass/commit/27c8351423da645d938fb6c2e54781ee24e6f074">https://git.osgeo.org/gogs/zarch/grass/commit/27c8351423da645d938fb6c2e54781ee24e6f074</a><br><br><br></div>I've split the functions that were contained in the grass.py in the following files, any comments?<br><br><br>```<br><span style="font-family:monospace,monospace">$ rg -e "^def\s[a-z_]+\(|^class\s[A-Z][a-z]*|^[A-Za-z_]+\s*="<br>       <br><b>gettext.py</b><br>11:_ = gettext.gettext<br><br><b>message.py</b><br>7:_DEBUG = None<br>10:def warning(text):<br>14:def fatal(msg):<br>19:def message(msg):<br>24:def is_debug():<br>41:def debug(msg):<br><br><b>utils.py</b><br>13:def grep(pattern, lines):<br>23:def print_params():<br>62:def get_username():<br>85:def make_fontcap():<br>93:def ensure_db_connected(mapset):<br>102:def get_shell():<br><br><b>gui.py</b><br>20:def read_gui(gisrc, default_gui):<br>53:def check_gui(expected_gui):<br>94:def save_gui(gisrc, grass_gui):<br>102:def gui_startup(grass_gui):<br>135:def start_gui(grass_gui):<br>148:def close_gui():<br>165:def clear_screen():<br>176:def show_banner():<br>188:def say_hello():<br>203:def show_info(shellname, grass_gui, default_gui):<br>229:def csh_startup(location, location_name, mapset, grass_env_file):<br>280:def bash_startup(location, location_name, grass_env_file):<br>313:PROMPT_COMMAND=grass_prompt\n""" % (_("2D and 3D raster MASKs present"),<br>338:def default_startup(location, location_name):<br>353:def done_message():<br><b><br>subprocess.py</b><br>10:def call(cmd, **kwargs):<br><br><b>info.py</b><br>5:BUILD_GISBASE = "@GISBASE@"<br>6:BUILD_PROJSHARE = "@CONFIG_PROJSHARE@"<br>7:CMD_NAME = "@START_UP@"<br>8:GRASS_VERSION = "@GRASS_VERSION_NUMBER@"<br>9:LD_LIBRARY_PATH = '@LD_LIBRARY_PATH_VAR@'<br>12:GISBASE = os.path.normpath(os.environ.get("GISBASE", BUILD_GISBASE))<br>13:GRASS_PROJSHARE = os.environ.get("GRASS_PROJSHARE", BUILD_PROJSHARE)<br><br><b>data.py</b><br>13:def create_location(gisdbase, location, geostring):<br>47:def is_mapset_valid(full_mapset):<br>56:def is_location_valid(gisdbase, location):<br>72:def get_mapset_invalid_reason(gisdbase, location, mapset):<br>106:def set_mapset(gisrc, arg, geofile=None, create_new=False):<br>191:def set_mapset_interactive(grass_gui):<br>218:def lock_mapset(mapset_path, force_gislock_removal, user, grass_gui):<br>270:class MapsetSettings(object):<br>301:def load_gisrc(gisrc, gisrcrc):<br><br><b>clean.py</b><br>8:def try_remove(path):<br>15:def try_rmdir(path):<br>22:def cleanup_dir(path):<br>33:class Cleaner(object):  # pylint: disable=R0903<br><br><b>env.py</b><br>22:def path_prepend(directory, var):<br>31:def path_append(directory, var):<br>40:def set_paths(grass_config_dir):<br>97:def set_defaults():<br>126:def set_display_defaults():<br>134:def set_browser():<br>173:def ensure_home():<br>180:def clean_env(gisrc):<br>192:def load_env(grass_env_file):<br>218:def set_language(grass_config_dir):<br><br><b>compatibility.py</b><br>5:ENCODING = locale.getdefaultlocale()[1]<br>11:def to_text_string(obj, encoding=ENCODING):<br><br><b>path.py</b><br>11:_WXPYTHON_BASE = None<br>14:def readfile(path):<br>21:def writefile(path, s):<br>27:def gpath(*args):<br>35:def wxpath(*args):<br>50:def get_grass_config_dir():<br>78:def create_tmp(user, gis_lock):<br>125:def clean_temp():<br>132:def get_gisrc_from_config_dir(grass_config_dir, batch_job):<br>143:def get_grass_env_file(sh, grass_config_dir):<br>160:def find_exe(pgm):<br><br><b>system.py</b><br>4:windows = sys.platform == 'win32'<br>5:cygwin = "cygwin" in sys.platform<br>6:macosx = "darwin" in sys.platform<br><br><b>gisrc.py</b><br>13:def create_gisrc(tmpdir, gisrcrc):<br>33:def read_gisrc(filename):<br>54:def read_env_file(path):<br>64:def write_gisrc(kv, filename):<br>71:def create_initial_gisrc(filename):<br><br><b>batch.py</b><br>9:def get_batch_job_from_env_variable():<br>32:def run_batch_job(batch_job):<br><br><b>parser.py</b><br>29:help_text = r"""GRASS GIS $VERSION_NUMBER<br>114:def help_message(default_gui):<br>121:class Parameters(object):<br>135:def parse_cmdline(argv, default_gui):<br>183:def main(argv):</span><br>```<br><br></div>I wish you all a nice week-end.<br><br></div>Pietro<br></div>