Skip to content

Commit

Permalink
Version [1.0.2]
Browse files Browse the repository at this point in the history
  • Loading branch information
I-am-PUID-0 committed Jul 16, 2024
1 parent 913bb50 commit ba34f9a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0



## Version [1.0.2] - 2024-16-07

### Fixed

- Zurg: Fixed the removal of Zurg user and password if previously set in config.yml


## Version [1.0.1] - 2024-16-07

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
def main():
logger = get_logger()

version = '1.0.1'
version = '1.0.2'

ascii_art = f'''
Expand Down
45 changes: 24 additions & 21 deletions zurg/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ def zurg_setup():
zurg_config_base = '/zurg/config.yml'

try:
if ZURGLOGLEVEL is not None: # Needs addtional testing
if ZURGLOGLEVEL is not None: # Needs additional testing
os.environ['LOG_LEVEL'] = ZURGLOGLEVEL
LOGLEVEL = os.environ.get('LOG_LEVEL')
# logger.debug(f"'LOG_LEVEL' set to '{LOGLEVEL}' based on 'ZURG_LOG_LEVEL'")
#else:
# logger.info("'ZURG_LOG_LEVEL' not set. Default log level INFO will be used for Zurg.")

# logger.debug(f"'LOG_LEVEL' set to '{LOGLEVEL}' based on 'ZURG_LOG_LEVEL'")
# else:
# logger.info("'ZURG_LOG_LEVEL' not set. Default log level INFO will be used for Zurg.")
except Exception as e:
logger.error(f"Error setting Zurg log level from 'ZURG_LOG_LEVEL': {e}")

Expand All @@ -30,7 +29,7 @@ def update_plex(file_path):
file.write("# on_library_update:\n")
else:
file.write(line)

def update_token(file_path, token):
logger.debug(f"Updating token in config file: {file_path}")
with open(file_path, 'r') as file:
Expand All @@ -52,20 +51,27 @@ def update_port(file_path, port):
file.write(f"port: {port}\n")
else:
file.write(line)

def update_creds(file_path, zurguser, zurgpass):
logger.debug(f"Updating username and password in config file: {file_path}")
with open(file_path, 'r') as file:
lines = file.readlines()

with open(file_path, 'w') as file:
for line in lines:
if line.strip().startswith("username:") or line.strip().startswith("# username:"):
file.write(f"username: {zurguser}\n")
elif line.strip().startswith("password:") or line.strip().startswith("# password:"):
file.write(f"password: {zurgpass}\n")
if zurguser and zurgpass:
if line.strip().startswith("username:") or line.strip().startswith("# username:"):
file.write(f"username: {zurguser}\n")
elif line.strip().startswith("password:") or line.strip().startswith("# password:"):
file.write(f"password: {zurgpass}\n")
else:
file.write(line)
else:
file.write(line)
if line.strip().startswith("username:"):
file.write("# username:\n")
elif line.strip().startswith("password:"):
file.write("# password:\n")
else:
file.write(line)

def check_and_set_zurg_version(dir_path):
zurg_binary_path = os.path.join(dir_path, 'zurg')
Expand All @@ -86,7 +92,7 @@ def check_and_set_zurg_version(dir_path):
version_check()

def setup_zurg_instance(config_dir, token, key_type):
try:
try:
zurg_executable_path = os.path.join(config_dir, 'zurg')
config_file_path = os.path.join(config_dir, 'config.yml')
logger.info(f"Preparing Zurg instance for {key_type}")
Expand Down Expand Up @@ -122,18 +128,16 @@ def setup_zurg_instance(config_dir, token, key_type):
logger.debug(f"Selected port {port} for Zurg w/ {key_type} instance")
update_port(config_file_path, port)


if ZURGUSER and ZURGPASS:
update_creds(config_file_path, ZURGUSER, ZURGPASS)

update_creds(config_file_path, ZURGUSER, ZURGPASS if ZURGUSER and ZURGPASS else None)

os.environ[f'ZURG_PORT_{key_type}'] = str(port)
logger.debug(f"Zurg w/ {key_type} instance configured to port: {port}")

update_token(config_file_path, token)
update_plex(config_file_path)

except Exception as e:
raise Exception(f"Error setting up Zurg instance for {key_type}: {e}")
raise Exception(f"Error setting up Zurg instance for {key_type}: {e}")

try:
if not RDAPIKEY and not ADAPIKEY:
Expand Down Expand Up @@ -164,5 +168,4 @@ def setup_zurg_instance(config_dir, token, key_type):
raise Exception(f"Exception: An error occurred during zurg setup - {e}")

if __name__ == "__main__":
zurg_setup()

zurg_setup()

0 comments on commit ba34f9a

Please sign in to comment.