Skip to content

Commit

Permalink
Restored Windows testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
lextm committed Apr 28, 2024
1 parent 029c870 commit 14612be
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, ubuntu-latest] #, windows-latest]
os: [macos-latest, ubuntu-latest, windows-latest]
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v4
Expand Down
91 changes: 52 additions & 39 deletions snmpsim/datafile.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,57 +253,70 @@ def __str__(self):


def get_data_files(tgt_dir, top_len=None):
# If top_len is not provided, calculate it based on the target directory
if top_len is None:
top_len = len(tgt_dir.rstrip(os.path.sep).split(os.path.sep))

dir_content = []
# Start processing the directory
return process_directory(tgt_dir, top_len)

def process_directory(tgt_dir, top_len):
# Initialize an empty list to store directory content
dir_content = []
# Iterate over each file in the target directory
for d_file in os.listdir(tgt_dir):
# Get the full path of the file
full_path = os.path.join(tgt_dir, d_file)

# Get the inode information of the file
inode = os.lstat(full_path)

# If the file is a symbolic link, process it
if stat.S_ISLNK(inode.st_mode):
rel_path = full_path.split(os.path.sep)[top_len:]
full_path = os.readlink(full_path)

if not os.path.isabs(full_path):
full_path = os.path.join(tgt_dir, full_path)

inode = os.stat(full_path)

else:
rel_path = full_path.split(os.path.sep)[top_len:]

full_path, inode = process_symlink(full_path, tgt_dir)
# Calculate the relative path of the file
rel_path = full_path.split(os.path.sep)[top_len:]
# If the file is a directory, recursively process it
if stat.S_ISDIR(inode.st_mode):
dir_content += get_data_files(full_path, top_len)
continue

if not stat.S_ISREG(inode.st_mode):
continue

for dExt in variation.RECORD_TYPES:
if d_file.endswith(dExt):
break

else:
continue

# just the file name would serve for agent identification
if rel_path[0] == SELF_LABEL:
rel_path = rel_path[1:]

if len(rel_path) == 1 and rel_path[0] == SELF_LABEL + os.path.extsep + dExt:
rel_path[0] = rel_path[0][4:]

ident = os.path.join(*rel_path)
ident = ident[: -len(dExt) - 1]
ident = ident.replace(os.path.sep, "/")

dir_content.append((full_path, variation.RECORD_TYPES[dExt], ident))

# If the file is a regular file, process it
elif stat.S_ISREG(inode.st_mode):
dir_content += process_file(d_file, full_path, rel_path)
# Return the directory content
return dir_content

def process_symlink(full_path, tgt_dir):
# Read the target of the symbolic link
full_path = os.readlink(full_path)
# If the target is not an absolute path, prepend the target directory
if not os.path.isabs(full_path):
full_path = os.path.join(tgt_dir, full_path)
# Get the inode information of the target file
inode = os.stat(full_path)
# Return the full path and inode
return full_path, inode

def process_file(d_file, full_path, rel_path):
# Check if the file extension matches any of the record types
for dExt in variation.RECORD_TYPES:
if d_file.endswith(dExt):
# If it does, process the file extension
return process_file_extension(d_file, full_path, rel_path, dExt)
# If it does not, return an empty list
return []

def process_file_extension(d_file, full_path, rel_path, dExt):
# Process the relative path to create an identifier for the file
if rel_path[0] == SELF_LABEL:
rel_path = rel_path[1:]
if len(rel_path) == 1 and rel_path[0] == SELF_LABEL + os.path.extsep + dExt:
rel_path[0] = rel_path[0][4:]
# Join the elements of the relative path to create the identifier
ident = os.path.join(*rel_path)
# Remove the file extension from the identifier
ident = ident[: -len(dExt) - 1]
# Replace any path separators in the identifier with a forward slash
ident = ident.replace(os.path.sep, "/")
# Return a tuple containing the full path, the record type, and the identifier
return [(full_path, variation.RECORD_TYPES[dExt], ident)]

def probe_context(transport_domain, transport_address, context_engine_id, context_name):
"""Suggest variations of context name based on request data"""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_datadir_ending.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setup_args():
data_dir = os.path.join(base_dir, "data", "UPS")
test_args = [
"responder.py",
f"--data-dir={data_dir}/",
f"--data-dir={data_dir}{os.sep}",
f"--agent-udpv4-endpoint=127.0.0.1:{PORT_NUMBER}",
f"--timeout={TIME_OUT}",
]
Expand Down

0 comments on commit 14612be

Please sign in to comment.