Browse Source

Profile config isn't Profile name

This removes the hard-dependency of renaming the Profile's main "config"
file, if you wanted to rename the directory too

This also fixes a minor nusance with CLI tab auto-complete, because the
profile name is also the directory, most CLI (bash), automatically add
the path seperator character '/' ('\' in windows), this allows the
selection of the directory with the CLI extra character
apollo 13 hours ago
parent
commit
a221b12f42
2 changed files with 7 additions and 7 deletions
  1. 0 0
      _example/profile.toml
  2. 7 7
      tyrell.py

+ 0 - 0
_example/_example.toml → _example/profile.toml


+ 7 - 7
tyrell.py

@@ -1,7 +1,7 @@
 
 from os import name as _OS_NAME, environ as _env
 from os import listdir as _listdir, mkdir as _mkdir, chown as _chown
-from os.path import exists as _exists, join as _join, isdir as _isdir
+from os.path import exists as _exists, join as _join, isdir as _isdir, sep as _sep
 from copy import copy as _copy
 from time import sleep as _sleep
 
@@ -87,10 +87,8 @@ def _profile_pre_check(profile_name: str):
             _chown(_join(profile_name, "keys"), int(_env['SUDO_UID']), int(_env['SUDO_GID']))
 
 def _write_profile(profile_name: str):
-    if profile_name.endswith(".toml"):
-        profile_name = profile_name.removesuffix(".toml")
     _profile_pre_check(profile_name)
-    with open(_join(profile_name, profile_name+".toml"), "w") as f:
+    with open(_join(profile_name, "profile.toml"), "w") as f:
         f.writelines("\n".join([
             f'# Tyrell :: v{VERSION} :: More human than human',
             '',
@@ -134,7 +132,7 @@ def _write_profile(profile_name: str):
             'hold = 20',
         ]))
     if "SUDO_USER" in _env:
-        _chown(_join(profile_name, profile_name+".toml"), int(_env['SUDO_UID']), int(_env['SUDO_GID']))
+        _chown(_join(profile_name, "profile.toml"), int(_env['SUDO_UID']), int(_env['SUDO_GID']))
 
 def _write_example(profile_name: str):
     if profile_name.endswith(".toml"):
@@ -475,6 +473,8 @@ class Profile:
             self.name = name.removesuffix(".toml")
         else:
             self.name = name
+        # Fix Directory as name (Sometimes happens with tab complete on CLI)
+        self.name = self.name.removesuffix(_sep)
         # Pre-Check
         if not _exists(self.name):
             # Does not exist, new everything
@@ -483,7 +483,7 @@ class Profile:
             _write_example_mirror(self.name)
         else:
             # Profile config?
-            if not _exists(_join(self.name, self.name+".toml")):
+            if not _exists(_join(self.name, "profile.toml")):
                 _write_profile(self.name)
             # Do we have keys?
             if not _exists(_join(self.name, "keys")):
@@ -493,7 +493,7 @@ class Profile:
             _print_warn("Got example profile, creation only")
             return # Done with example code
         # Load toml config
-        with open(_join(self.name, self.name+".toml"), "r") as f:
+        with open(_join(self.name, "profile.toml"), "r") as f:
             dat = _toml_load(f)
             self.placeholders = {
                 "name": False,