Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for Osmand app #158

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions android_world/task_evals/single/osmand.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,8 @@ def initialize_task(self, env: interface.AsyncEnv) -> None:
)

def is_successful(self, env: interface.AsyncEnv) -> float:
with env.controller.pull_file(
os.path.join(_DEVICE_FILES, 'tracks')
with file_utils.tmp_directory_from_device(
os.path.join(_DEVICE_FILES, 'tracks'), env.controller
) as tracks_directory:
for track_file in os.listdir(tracks_directory):
if _track_matches(
Expand Down
2 changes: 1 addition & 1 deletion android_world/task_evals/utils/sqlite_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def delete_all_rows_from_table(
if not table_exists(table_name, remote_db_file_path, env):
# If the database was never created, opening the app may create it.
adb_utils.launch_app(app_name, env.controller)
time.sleep(2.0)
time.sleep(7.0)

with env.controller.pull_file(
remote_db_file_path, timeout_sec
Expand Down
23 changes: 11 additions & 12 deletions android_world/utils/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,8 @@ def get_file_list_with_metadata(
) -> list[FileWithMetadata]:
"""Get the list of all (regular) files with metadata in a given directory.

Right now we only list regular files in the given directory and only grab
file name, full directory and change time in metadata.
Right now we only list regular files in the given directory and only grab file
name, full directory and change time in metadata.

Args:
directory_path: The directory to list all its files.
Expand All @@ -463,21 +463,17 @@ def get_file_list_with_metadata(

Returns:
A list of files with metadata.

Raises:
RuntimeError: If the input directory path is not valid or shell ls fails.
"""
if not check_directory_exists(directory_path, env):
raise RuntimeError(f"{directory_path} is not a valid directory.")

# Run [adb shell ls] to list all files in the given directory.
try:
ls_response = adb_utils.issue_generic_request(
f"shell ls {directory_path} -ll -au", env, timeout_sec
)

adb_utils.check_ok(ls_response, "Failed to list files in directory.")

files = []
# Each file (including links and directories) will be listed in format as
# follows,
Expand All @@ -487,15 +483,18 @@ def get_file_list_with_metadata(
# In shell output, the first character is used to indicate file type and
# "-" means the file is a regular file.
if file_details.startswith("-"):
parts = file_details.split(None, 8)
if len(parts) < 9:
raise RuntimeError(f"Failed to parse file details: {file_details}")

file_name = parts[8] # This will preserve spaces in the filename
files.append(
FileWithMetadata(
file_name=file_details.split(" ")[-1],
full_path=os.path.join(
directory_path, file_details.split(" ")[-1]
),
file_size=int(file_details.split(" ")[-5]),
file_name=file_name,
full_path=os.path.join(directory_path, file_name),
file_size=int(parts[4]),
change_time=datetime.datetime.fromisoformat(
" ".join(file_details.split(" ")[-4:-2])[:-3]
" ".join(parts[5:7])[:-3]
),
)
)
Expand Down