Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Simplify the structure of the grass init module #7

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
90639ae
lib/init/grass: Simplify removing the tmpdir.
pmav99 Feb 3, 2019
785492b
lib/init/grass: Fix erroneous comment.
pmav99 Feb 3, 2019
39d047b
lib/init/grass: Simplify encode()/decode() functions.
pmav99 Feb 3, 2019
e60e034
lib/init/grass: Move all the imports at the beginning of the file.
pmav99 Feb 3, 2019
47ff016
lib/init/grass: Simplify clean_env().
pmav99 Feb 3, 2019
193277d
lib/init/grass: Just shuffling stuff around
pmav99 Feb 3, 2019
821f43f
lib/init/grass: Group the logging functions together.
pmav99 Feb 3, 2019
3a5de69
lib/init/grass: Capitalize constants.
pmav99 Feb 3, 2019
906ff68
lib/init/grass: Move the info message out of the "show_info()" function.
pmav99 Feb 3, 2019
bb2d09e
lib/init/grass: Remove unused constants
pmav99 Feb 4, 2019
44ce258
lib/init/grass: Use six for cross version Python compatibility
pmav99 Feb 4, 2019
2c00830
lib/init/grass: Remove old comment
pmav99 Feb 4, 2019
d2ab2c2
lib/init/grass: Move all the gisbase stuff in a single place.
pmav99 Feb 4, 2019
7e737ee
lib/init/grass: Clarify comment.
pmav99 Feb 4, 2019
e5d0b31
lib/init/grass: Capitalize all constants
pmav99 Feb 4, 2019
d84f4c4
lib/init/grass: Fix typo
pmav99 Feb 4, 2019
6689f15
lib/init/grass: Simplify setting a value to CONFIG_PROJSHARE
pmav99 Feb 4, 2019
5682b16
lib/init/grass: Add comments about GISBASE
pmav99 Feb 4, 2019
070f9e1
lib/init/grass: Validate cmdline in a separate function
pmav99 Feb 4, 2019
520f4df
lib/init/grass: Inline variable substitution inside "help_message()"
pmav99 Feb 24, 2019
7229f5f
lib/init/grass: Ensure that the init process only happens inside main()
pmav99 Feb 24, 2019
1809611
lib/init/grass: Refuse to start if ~/.grass7 exists but is not a dire…
pmav99 Feb 24, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions lib/init/grass.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,51 +58,45 @@
print("Default locale not found, using UTF-8") # intentionally not translatable


def decode(bytes_, encoding=None):
def decode(bytes_, encoding=ENCODING):
"""Decode bytes with default locale and return (unicode) string
Adapted from lib/python/core/utils.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should say "Adapted from lib/python/script/utils.py" (also for the other function)


No-op if parameter is not bytes (assumed unicode string).

:param bytes bytes_: the bytes to decode
:param encoding: encoding to be used, default value is None
:param encoding: encoding to be used, default value is the system's default
encoding or, if that cannot be determined, 'UTF-8'.
"""
if sys.version_info.major >= 3:
unicode = str
if isinstance(bytes_, unicode):
return bytes_
elif isinstance(bytes_, bytes):
if encoding is None:
enc = ENCODING
else:
enc = encoding
return bytes_.decode(enc)
return bytes_.decode(encoding)
else:
# if something else than text
raise TypeError("can only accept types str and bytes")


def encode(string, encoding=None):
def encode(string, encoding=ENCODING):
"""Encode string with default locale and return bytes with that encoding
Adapted from lib/python/core/utils.py

No-op if parameter is bytes (assumed already encoded).
This ensures garbage in, garbage out.

:param str string: the string to encode
:param encoding: encoding to be used, default value is None
:param encoding: encoding to be used, default value is the system's default
encoding or, if that cannot be determined, 'UTF-8'.
"""
if sys.version_info.major >= 3:
unicode = str
if isinstance(string, bytes):
return string
# this also tests str in Py3:
elif isinstance(string, unicode):
if encoding is None:
enc = ENCODING
else:
enc = encoding
return string.encode(enc)
return string.encode(encoding)
else:
# if something else than text
raise TypeError("can only accept types str and bytes")
Expand Down