Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjayankur31 committed Jul 27, 2023
1 parent 1c33c44 commit 381389a
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
11 changes: 11 additions & 0 deletions pyneuroml/nsgr/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env python3
"""
Module for working with NSG. See https://github.com/OpenSourceBrain/pynsgr
File: pyneuroml/nsgr/__init__.py
Copyright 2023 NeuroML contributors
"""



46 changes: 46 additions & 0 deletions pyneuroml/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
Copyright 2023 NeuroML Contributors
"""

import os
import typing
import time
from pathlib import Path
import logging
import re
import neuroml


logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)


def extract_position_info(
Expand Down Expand Up @@ -133,3 +137,45 @@ def convert_case(name):
"""Converts from camelCase to under_score"""
s1 = re.sub("(.)([A-Z][a-z]+)", r"\1_\2", name)
return re.sub("([a-z0-9])([A-Z])", r"\1_\2", s1).lower()


def get_files_generated_after(timestamp: float = time.time(),
directory: str = ".",
ignore_suffixes: list[str] = ["xml", "nml"],
include_suffixes: list[str] = []) -> typing.List[str]:
"""Get files modified after provided time stamp in directory, excluding provided suffixes.
Ignores directories.
:param timestamp: time stamp to compare to
:type timestamp: float
:param directory: directory to list files of
:type directory: str
:param ignore_suffixes: file suffixes to ignore
:type ignore_suffixes: str
:returns: list of file names
:rtype: list(str)
"""
logger.debug(f"Timestamp is: {timestamp}")
current_files = list(Path(directory).glob("*"))
# only files, ignore directories
current_files = [f for f in current_files if f.is_file()]
files = []
for file in current_files:
excluded = False
for sfx in ignore_suffixes:
if file.name.endswith(sfx):
excluded = True

# TODO: continue here
included = False
for sfx in include_suffixes:


if include is True:
file_mtime = os.path.getmtime(file)
if file_mtime > timestamp:
files.append(file.name)

return files
18 changes: 17 additions & 1 deletion tests/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@

import logging
import pathlib as pl
import time

from pyneuroml.pynml import read_neuroml2_file
from pyneuroml.utils import extract_position_info
from pyneuroml.utils import extract_position_info, get_files_generated_after

from .. import BaseTestCase

Expand Down Expand Up @@ -46,3 +47,18 @@ def test_extract_position_info(self):

for c in ["HL23PV", "HL23PYR", "HL23VIP", "HL23SST"]:
self.assertIn(c, cell_id_vs_cell.keys())

def test_get_files_generated_after(self):
"""test get_files_generated_after method."""
# compare to epoch, should just list all files
files = get_files_generated_after(timestamp=0)
print(files)
current_files = list(pl.Path(".").glob("*"))
current_files = [f for f in current_files if f.is_file()]
self.assertEqual(len(files), len(current_files))

# no files
files = get_files_generated_after(timestamp=0, ignore_suffixes=[".py"])
print(files)
current_files = list(pl.Path(".").glob("*.hahah"))
self.assertEqual(len(files), len(current_files))

0 comments on commit 381389a

Please sign in to comment.