Skip to content

Commit

Permalink
Add unused functions again - they are used in rasa-x
Browse files Browse the repository at this point in the history
  • Loading branch information
tabergma committed Jul 24, 2019
1 parent b2c3f42 commit e13dd4f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
35 changes: 35 additions & 0 deletions rasa/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,38 @@ def minimal_kwargs(
for k, v in kwargs.items()
if k in possible_arguments and k not in excluded_keys
}


def write_global_config_value(name: Text, value: Any) -> None:
"""Read global Rasa configuration."""

try:
os.makedirs(os.path.dirname(GLOBAL_USER_CONFIG_PATH), exist_ok=True)

c = read_global_config()
c[name] = value
rasa.core.utils.dump_obj_as_yaml_to_file(GLOBAL_USER_CONFIG_PATH, c)
except Exception as e:
logger.warning(
"Failed to write global config. Error: {}. Skipping." "".format(e)
)


def read_global_config_value(name: Text, unavailable_ok: bool = True) -> Any:
"""Read a value from the global Rasa configuration."""

def not_found():
if unavailable_ok:
return None
else:
raise ValueError("Configuration '{}' key not found.".format(name))

if not os.path.exists(GLOBAL_USER_CONFIG_PATH):
return not_found()

c = read_global_config()

if name in c:
return c[name]
else:
return not_found()
12 changes: 12 additions & 0 deletions rasa/utils/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,15 @@ def validate(document: Document) -> None:
raise ValidationError(message=error_message)

return FunctionValidator


def zip_folder(folder: Text) -> Text:
"""Create an archive from a folder."""
import tempfile
import shutil

zipped_path = tempfile.NamedTemporaryFile(delete=False)
zipped_path.close()

# WARN: not thread save!
return shutil.make_archive(zipped_path.name, str("zip"), folder)

0 comments on commit e13dd4f

Please sign in to comment.