[GRASS-dev] move everything from /lib/init/grass.py to /lib/python/init

Pietro peter.zamb at gmail.com
Fri Jul 14 07:00:30 PDT 2017


Dear devs,

What do you think if we move all the function that at the moment are
contained in `/lib/init/grass.py` into a new subfolder under `/lib/python`?

The main advantages that I see are:

- 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;
- We can add unittest for the start up functions
- We can remove code duplication between grass.init and grass.script.core


What do you think?

I did the changes and at least on my computer GRASS is working, all the
changes are available at this link:

https://git.osgeo.org/gogs/zarch/grass/commit/27c8351423da645d938fb6c2e54781ee24e6f074


I've split the functions that were contained in the grass.py in the
following files, any comments?


```
$ rg -e "^def\s[a-z_]+\(|^class\s[A-Z][a-z]*|^[A-Za-z_]+\s*="

*gettext.py*
11:_ = gettext.gettext

*message.py*
7:_DEBUG = None
10:def warning(text):
14:def fatal(msg):
19:def message(msg):
24:def is_debug():
41:def debug(msg):

*utils.py*
13:def grep(pattern, lines):
23:def print_params():
62:def get_username():
85:def make_fontcap():
93:def ensure_db_connected(mapset):
102:def get_shell():

*gui.py*
20:def read_gui(gisrc, default_gui):
53:def check_gui(expected_gui):
94:def save_gui(gisrc, grass_gui):
102:def gui_startup(grass_gui):
135:def start_gui(grass_gui):
148:def close_gui():
165:def clear_screen():
176:def show_banner():
188:def say_hello():
203:def show_info(shellname, grass_gui, default_gui):
229:def csh_startup(location, location_name, mapset, grass_env_file):
280:def bash_startup(location, location_name, grass_env_file):
313:PROMPT_COMMAND=grass_prompt\n""" % (_("2D and 3D raster MASKs present"),
338:def default_startup(location, location_name):
353:def done_message():

*subprocess.py*
10:def call(cmd, **kwargs):

*info.py*
5:BUILD_GISBASE = "@GISBASE@"
6:BUILD_PROJSHARE = "@CONFIG_PROJSHARE@"
7:CMD_NAME = "@START_UP@"
8:GRASS_VERSION = "@GRASS_VERSION_NUMBER@"
9:LD_LIBRARY_PATH = '@LD_LIBRARY_PATH_VAR@'
12:GISBASE = os.path.normpath(os.environ.get("GISBASE", BUILD_GISBASE))
13:GRASS_PROJSHARE = os.environ.get("GRASS_PROJSHARE", BUILD_PROJSHARE)

*data.py*
13:def create_location(gisdbase, location, geostring):
47:def is_mapset_valid(full_mapset):
56:def is_location_valid(gisdbase, location):
72:def get_mapset_invalid_reason(gisdbase, location, mapset):
106:def set_mapset(gisrc, arg, geofile=None, create_new=False):
191:def set_mapset_interactive(grass_gui):
218:def lock_mapset(mapset_path, force_gislock_removal, user, grass_gui):
270:class MapsetSettings(object):
301:def load_gisrc(gisrc, gisrcrc):

*clean.py*
8:def try_remove(path):
15:def try_rmdir(path):
22:def cleanup_dir(path):
33:class Cleaner(object):  # pylint: disable=R0903

*env.py*
22:def path_prepend(directory, var):
31:def path_append(directory, var):
40:def set_paths(grass_config_dir):
97:def set_defaults():
126:def set_display_defaults():
134:def set_browser():
173:def ensure_home():
180:def clean_env(gisrc):
192:def load_env(grass_env_file):
218:def set_language(grass_config_dir):

*compatibility.py*
5:ENCODING = locale.getdefaultlocale()[1]
11:def to_text_string(obj, encoding=ENCODING):

*path.py*
11:_WXPYTHON_BASE = None
14:def readfile(path):
21:def writefile(path, s):
27:def gpath(*args):
35:def wxpath(*args):
50:def get_grass_config_dir():
78:def create_tmp(user, gis_lock):
125:def clean_temp():
132:def get_gisrc_from_config_dir(grass_config_dir, batch_job):
143:def get_grass_env_file(sh, grass_config_dir):
160:def find_exe(pgm):

*system.py*
4:windows = sys.platform == 'win32'
5:cygwin = "cygwin" in sys.platform
6:macosx = "darwin" in sys.platform

*gisrc.py*
13:def create_gisrc(tmpdir, gisrcrc):
33:def read_gisrc(filename):
54:def read_env_file(path):
64:def write_gisrc(kv, filename):
71:def create_initial_gisrc(filename):

*batch.py*
9:def get_batch_job_from_env_variable():
32:def run_batch_job(batch_job):

*parser.py*
29:help_text = r"""GRASS GIS $VERSION_NUMBER
114:def help_message(default_gui):
121:class Parameters(object):
135:def parse_cmdline(argv, default_gui):
183:def main(argv):
```

I wish you all a nice week-end.

Pietro
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20170714/c34657a0/attachment.html>


More information about the grass-dev mailing list