don't require a config file for 'preflight' and 'init'
This commit is contained in:
		| @@ -60,6 +60,8 @@ class CommitCommand(CliCommand): | ||||
|         ) | ||||
|  | ||||
|     def execute(self, args: argparse.Namespace) -> None: | ||||
|         cm().require_config() | ||||
|         chdir_to_wiki() | ||||
|         if cm().commit_require_branch: | ||||
|             current_branch = git.read("rev-parse", "--abbrev-ref", "HEAD") | ||||
|             if current_branch != cm().commit_require_branch: | ||||
| @@ -99,6 +101,8 @@ class ListenCommand(CliCommand): | ||||
|         ) | ||||
|      | ||||
|     def execute(self, args: argparse.Namespace) -> None: | ||||
|         cm().require_config() | ||||
|         chdir_to_wiki() | ||||
|         try: | ||||
|             tw.exec( | ||||
|                 [ | ||||
| @@ -198,6 +202,8 @@ class BuildCommand(CliCommand): | ||||
|                  f"in your config file.") | ||||
|  | ||||
|     def execute(self, args: argparse.Namespace) -> None: | ||||
|         cm().require_config() | ||||
|         chdir_to_wiki() | ||||
|         self._precheck(args.product) | ||||
|  | ||||
|         # Find the build steps for the product the user specified. | ||||
| @@ -244,6 +250,27 @@ class BuildCommand(CliCommand): | ||||
|         print(f"tzk: Build of product '{args.product}' completed successfully.") | ||||
|  | ||||
|  | ||||
| def chdir_to_wiki(): | ||||
|     """ | ||||
|     For most operations, we want the current directory to be the wiki folder. | ||||
|     """ | ||||
|     if not cm().wiki_folder: | ||||
|         fail("No 'wiki_folder' option found in config. Set this option to the name " | ||||
|             "of the wiki subfolder within the current directory.") | ||||
|  | ||||
|     try: | ||||
|         os.chdir(cm().wiki_folder) | ||||
|     except FileNotFoundError: | ||||
|         fail(f"Tried to change directory into the wiki_folder '{cm().wiki_folder}' " | ||||
|             f"specified in your config file, but that directory does not exist.") | ||||
|  | ||||
|     if not os.path.exists("tiddlywiki.info"): | ||||
|         fail(f"After changing directory into {cm().wiki_folder} per your config file: " | ||||
|             f"Expected a 'tiddlywiki.info' file in {os.getcwd()}. " | ||||
|             f"Please check that your wiki is initialized " | ||||
|             f"and you specified the correct wiki_folder_name.") | ||||
|  | ||||
|  | ||||
| def launch(): | ||||
|     parser = argparse.ArgumentParser() | ||||
|  | ||||
| @@ -259,25 +286,6 @@ def launch(): | ||||
|         parser.print_help() | ||||
|         sys.exit(0) | ||||
|  | ||||
|     # For all operations except 'init', we start in the wiki folder. | ||||
|     # (For init, we're actually *creating* the wiki folder.) | ||||
|     if not args._cls.cmd == "init": | ||||
|         if not cm().wiki_folder: | ||||
|             fail("No 'wiki_folder' option found in config. Set this option to the name " | ||||
|                 "of the wiki subfolder within the current directory.") | ||||
|  | ||||
|         try: | ||||
|             os.chdir(cm().wiki_folder) | ||||
|         except FileNotFoundError: | ||||
|             fail(f"Tried to change directory into the wiki_folder '{cm().wiki_folder}' " | ||||
|                 f"specified in your config file, but that directory does not exist.") | ||||
|  | ||||
|         if not os.path.exists("tiddlywiki.info"): | ||||
|             fail(f"After changing directory into {cm().wiki_folder} per your config file: " | ||||
|                 f"Expected a 'tiddlywiki.info' file in {os.getcwd()}. " | ||||
|                 f"Please check that your wiki is initialized " | ||||
|                 f"and you specified the correct wiki_folder_name.") | ||||
|  | ||||
|     args._cls().execute(args) | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -26,14 +26,27 @@ class ConfigurationManager: | ||||
|                     del sys.path[0:1] | ||||
|                     break | ||||
|         else: | ||||
|             fail( | ||||
|                 f"Your TZK config file could not be found. " | ||||
|                 f"Please ensure there is a file called tzk_config.py " | ||||
|                 f"in the current directory.") | ||||
|             # no config file | ||||
|             self.conf_mod = None | ||||
|  | ||||
|     def __getattr__(self, attr): | ||||
|         return getattr(self.conf_mod, attr, None) | ||||
|         if self.conf_mod is None: | ||||
|             return None | ||||
|         else: | ||||
|             return getattr(self.conf_mod, attr, None) | ||||
|  | ||||
|     def has_config(self) -> bool: | ||||
|         return self.conf_mod is not None | ||||
|  | ||||
|     def require_config(self) -> None: | ||||
|         """ | ||||
|         Quit with exit status 1 if no config file was found. | ||||
|         """ | ||||
|         if not self.has_config(): | ||||
|             fail(f"No tzk_config.py found in the current directory. " | ||||
|                  f"(Try 'tzk init' if you want to create a new one.)") | ||||
|  | ||||
|     #TODO: trash this function | ||||
|     def write_attr(self, attr: str, value: str) -> bool: | ||||
|         """ | ||||
|         Try to add a simple attribute = string value config parameter to the | ||||
|   | ||||
| @@ -166,7 +166,7 @@ def install(wiki_name: str, tw_version_spec: str, author: Optional[str]): | ||||
|  | ||||
|     _init_npm(wiki_name, tw_version_spec, author) | ||||
|     _init_tw(wiki_name) | ||||
|     warnings |= not _save_wikifolder_to_config(wiki_name) | ||||
|     #warnings |= not _save_wikifolder_to_config(wiki_name)  ## TODO: now write entire config | ||||
|     _add_filesystem_plugins(wiki_name) | ||||
|     _init_gitignore() | ||||
|     _initial_commit() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Soren I. Bjornstad
					Soren I. Bjornstad