Skip to content

Commit b3fcdbc

Browse files
committed
attempted to add ja support
1 parent 51c25dd commit b3fcdbc

File tree

5 files changed

+432
-208
lines changed

5 files changed

+432
-208
lines changed

config_handler.py

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,80 @@
1+
import os
2+
import glob
3+
import logging
4+
5+
# Initialize logger for config_handler module
6+
logger = logging.getLogger(__name__)
7+
logger.setLevel(logging.INFO) # Or desired level, if not set at root logger
8+
19
def modify_config_file(config_path, setting, new_value):
2-
"""Modifies a setting in bluestacks.conf."""
10+
"""Modifies a setting in bluestacks.conf.
11+
12+
Args:
13+
config_path (str): Path to the bluestacks.conf file.
14+
setting (str): The setting to modify (e.g., "bst.feature.rooting").
15+
new_value (str): The new value for the setting.
16+
"""
317
changed = False
418
try:
5-
with open(config_path, "r") as f:
19+
logger.debug(f"Attempting to modify setting '{setting}' in config file: {config_path}")
20+
# Open with encoding='utf-8' for reading
21+
with open(config_path, "r", encoding='utf-8') as f:
622
lines = f.readlines()
723

8-
with open(config_path, "w") as f:
24+
# Open with encoding='utf-8' for writing
25+
with open(config_path, "w", encoding='utf-8') as f:
926
for line in lines:
1027
if line.startswith(f"{setting}="):
28+
logger.debug(f"Found setting '{setting}', replacing value. Original line: '{line.strip()}'")
1129
f.write(f"{setting}=\"{new_value}\"\n")
1230
changed = True
31+
logger.debug(f"Setting '{setting}' updated to '{new_value}'")
1332
else:
1433
f.write(line)
1534

1635
if changed:
17-
print(f"Successfully updated '{setting}' to '{new_value}' in {config_path}")
36+
logger.info(f"Successfully updated setting '{setting}' to '{new_value}' in {config_path}")
1837
else:
19-
print(f"No changes made for '{setting}' in {config_path}")
38+
logger.info(f"Setting '{setting}' not found in {config_path}, no changes made.")
2039
except FileNotFoundError:
21-
print(f"Error: File not found at {config_path}")
40+
error_msg = f"Config file not found at {config_path}"
41+
logger.error(error_msg)
42+
print(error_msg) # Keep print for user feedback if needed in CLI context, but logging is primary
2243
except Exception as e:
23-
print(f"Error modifying configuration: {e}")
44+
error_msg = f"Error modifying configuration file {config_path}: {e}"
45+
logger.exception(error_msg) # Log full exception traceback
46+
print(error_msg) # Keep print for user feedback
2447

2548

2649
def is_root_enabled(config_path, instance_name):
27-
"""Checks if root access is enabled for a specific instance."""
50+
"""Checks if root access is enabled for a specific instance.
51+
52+
Args:
53+
config_path (str): Path to the bluestacks.conf file.
54+
instance_name (str): The name of the BlueStacks instance.
55+
56+
Returns:
57+
bool: True if root access is enabled, False otherwise.
58+
"""
2859
try:
29-
with open(config_path, "r") as f:
60+
setting_key = f"bst.instance.{instance_name}.enable_root_access="
61+
logger.debug(f"Checking root status for instance '{instance_name}' in {config_path}")
62+
# Open with encoding='utf-8' for reading
63+
with open(config_path, "r", encoding='utf-8') as f:
3064
for line in f:
31-
if line.startswith(f"bst.instance.{instance_name}.enable_root_access="):
32-
return line.strip().endswith("=\"1\"")
33-
return False
65+
if line.startswith(setting_key):
66+
is_enabled = line.strip().endswith("=\"1\"")
67+
logger.debug(f"Root status for instance '{instance_name}': {'Enabled' if is_enabled else 'Disabled'}")
68+
return is_enabled
69+
logger.debug(f"Root setting '{setting_key}' not found for instance '{instance_name}' in {config_path}. Assuming root is disabled.")
70+
return False # Setting not found, assume root is disabled
3471
except FileNotFoundError:
35-
print(f"Error: File not found at {config_path}")
72+
error_msg = f"Config file not found at {config_path}"
73+
logger.error(error_msg)
74+
print(error_msg)
3675
return False
3776
except Exception as e:
38-
print(f"Error reading configuration: {e}")
77+
error_msg = f"Error reading configuration file {config_path}: {e}"
78+
logger.exception(error_msg)
79+
print(error_msg)
3980
return False

instance_handler.py

Lines changed: 60 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,39 @@
11
import os
22
import glob
3+
import logging
4+
5+
# Initialize logger for instance_handler module
6+
logger = logging.getLogger(__name__)
7+
logger.setLevel(logging.INFO) # Or desired level, if not set at root logger
8+
39

410
def modify_instance_files(instance_path, file_names, new_type):
5-
"""Modifies file types in .bstk files to toggle R/W status, and logs changes in detail."""
11+
"""Modifies file types in .bstk files to toggle R/W status, and logs changes in detail.
12+
13+
Args:
14+
instance_path (str): Path to the BlueStacks instance directory.
15+
file_names (list): List of file names to modify within the .bstk files.
16+
new_type (str): The new file type to set ("Normal" or "Readonly").
17+
"""
618
bstk_files = ["Android.bstk.in"]
7-
instance_bstk = glob.glob(os.path.join(instance_path, "*.bstk"))
19+
instance_bstk_files = glob.glob(os.path.join(instance_path, "*.bstk"))
820

9-
if not instance_bstk:
10-
print(f"Error: No .bstk file found in {instance_path}")
21+
if not instance_bstk_files:
22+
error_msg = f"Error: No .bstk file found in instance path: {instance_path}"
23+
logger.error(error_msg)
24+
print(error_msg)
1125
return
1226

13-
bstk_files.append(os.path.basename(instance_bstk[0]))
27+
bstk_files.append(os.path.basename(instance_bstk_files[0])) # Take the first one found
28+
29+
logger.debug(f"Modifying instance files in path: {instance_path}, BSTK files: {bstk_files}, Target files: {file_names}, New type: {new_type}")
1430

1531
for bstk_file in bstk_files:
1632
bstk_path = os.path.join(instance_path, bstk_file)
1733
changed_entries = [] # Store (filename, old_value, new_value)
1834

1935
try:
36+
logger.debug(f"Processing BSTK file: {bstk_path}")
2037
with open(bstk_path, "r") as f:
2138
content = f.readlines()
2239

@@ -29,36 +46,63 @@ def modify_instance_files(instance_path, file_names, new_type):
2946
old_value = "Readonly"
3047
line = line.replace("Readonly", new_type)
3148
changed_entries.append((matched_file_name, old_value, new_type))
49+
logger.debug(f"Modified line for file '{matched_file_name}': from 'Readonly' to '{new_type}'")
3250
elif "Normal" in line:
3351
old_value = "Normal"
3452
line = line.replace("Normal", new_type)
3553
changed_entries.append((matched_file_name, old_value, new_type))
54+
logger.debug(f"Modified line for file '{matched_file_name}': from 'Normal' to '{new_type}'")
3655
f.write(line)
3756

3857
if changed_entries:
3958
for (file_name, old_val, new_val) in changed_entries:
40-
print(f"Successfully updated '{file_name}' from '{old_val}' to '{new_val}' in {bstk_path}")
59+
logger.info(f"Successfully updated file type for '{file_name}' in {bstk_path}: from '{old_val}' to '{new_val}'")
4160
else:
42-
print(f"No changes made in {bstk_path}")
61+
logger.info(f"No target file types ('Readonly' or 'Normal' with filenames {file_names}) found to modify in {bstk_path}.")
4362

4463
except FileNotFoundError:
45-
print(f"Error: File not found at {bstk_path}")
64+
error_msg = f"BSTK file not found at {bstk_path}"
65+
logger.error(error_msg)
66+
print(error_msg)
4667
except Exception as e:
47-
print(f"Error modifying file: {e}")
68+
error_msg = f"Error modifying BSTK file {bstk_path}: {e}"
69+
logger.exception(error_msg)
70+
print(error_msg)
71+
4872

4973
def is_instance_readonly(instance_path):
50-
"""Checks if instance files are set to 'Readonly'."""
51-
for bstk_file in ["Android.bstk.in", f"{os.path.basename(instance_path)}.bstk"]:
74+
"""Checks if instance files are set to 'Readonly'.
75+
76+
Args:
77+
instance_path (str): Path to the BlueStacks instance directory.
78+
79+
Returns:
80+
bool: True if 'Readonly' is found in any checked .bstk file, False otherwise.
81+
"""
82+
bstk_files_to_check = ["Android.bstk.in"] # Define filenames to check directly
83+
instance_bstk_files = glob.glob(os.path.join(instance_path, "*.bstk"))
84+
if instance_bstk_files: # Only add if found, avoid index error if glob returns empty list
85+
bstk_files_to_check.append(os.path.basename(instance_bstk_files[0]))
86+
87+
logger.debug(f"Checking readonly status for instance path: {instance_path}, BSTK files to check: {bstk_files_to_check}")
88+
89+
for bstk_file in bstk_files_to_check:
5290
bstk_path = os.path.join(instance_path, bstk_file)
5391
try:
5492
with open(bstk_path, "r") as f:
5593
for line in f:
5694
if "Readonly" in line:
95+
logger.debug(f"'Readonly' found in {bstk_path}")
5796
return True
58-
return False
97+
logger.debug(f"'Readonly' not found in {bstk_path}") # Log even when not found to confirm check
5998
except FileNotFoundError:
60-
print(f"Error: File not found at {bstk_path}")
61-
return False
99+
error_msg = f"BSTK file not found at {bstk_path}"
100+
logger.error(error_msg)
101+
print(error_msg)
102+
return False # If one file not found, consider it not readonly for safety (or adjust logic)
62103
except Exception as e:
63-
print(f"Error reading file: {e}")
64-
return False
104+
error_msg = f"Error reading BSTK file {bstk_path}: {e}"
105+
logger.exception(error_msg)
106+
print(error_msg)
107+
return False
108+
return False # Readonly not found in any checked files

kitsune_handler.py

Lines changed: 0 additions & 78 deletions
This file was deleted.

0 commit comments

Comments
 (0)