Skip to content

Commit

Permalink
Merge pull request #24 from aanil/main
Browse files Browse the repository at this point in the history
Add an option to use a list of users to upload reports for
  • Loading branch information
alneberg authored Sep 5, 2023
2 parents 3c365d3 + eb868dc commit 78d76e6
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ DAILY_READ_STHLM_STATUSDB_PASSWORD=
# SNP&SEQ status api URL

DAILY_READ_SNPSEQ_URL=

#User List to send reports to, can be empty
DAILY_READ_USERS_LIST_LOCATION=
1 change: 1 addition & 0 deletions daily_read/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def __init__(self):
self.REPORTS_LOCATION = os.getenv("DAILY_READ_REPORTS_LOCATION")
self.DATA_LOCATION = os.getenv("DAILY_READ_DATA_LOCATION")
self.LOG_LOCATION = os.getenv("DAILY_READ_LOG_LOCATION")
self.USERS_LIST_LOCATION = os.getenv("DAILY_READ_USERS_LIST_LOCATION")
self.STHLM_STATUSDB_URL = os.getenv("DAILY_READ_STHLM_STATUSDB_URL")
self.STHLM_STATUSDB_USERNAME = os.getenv("DAILY_READ_STHLM_STATUSDB_USERNAME")
self.STHLM_STATUSDB_PASSWORD = os.getenv("DAILY_READ_STHLM_STATUSDB_PASSWORD")
Expand Down
42 changes: 38 additions & 4 deletions daily_read/ngi_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def __init__(self, config):

self.data = {} # Key: Portal_id, Value: ProjectDataRecord

self.user_list = self._read_user_list(config.USERS_LIST_LOCATION)

def __setup_data_repo(self):
# Safety check of path
if not os.path.isabs(self.data_location):
Expand Down Expand Up @@ -66,6 +68,15 @@ def __setup_data_repo(self):

return data_repo

def _read_user_list(self, users_list_location):
users_list = []
if users_list_location:
if os.path.exists(users_list_location):
with open(users_list_location, "r") as fh:
users_list = [line.strip() for line in fh]

return users_list

@property
def staged_files(self):
return [diff.b_path for diff in self.data_repo.index.diff("HEAD")]
Expand Down Expand Up @@ -134,7 +145,13 @@ def any_modified_or_new(self):
- Untracked files
"""
return any([self.data_repo.is_dirty(), self.data_repo.untracked_files, self.staged_files])
return any(
[
self.data_repo.is_dirty(),
self.data_repo.untracked_files,
self.staged_files,
]
)

def get_modified_or_new_projects(self):
"""Returns files which are either:
Expand All @@ -156,6 +173,7 @@ def get_modified_or_new_projects(self):
projects.update(self.data_repo.untracked_files)

projects_list = []

for project_relpath in projects:
portal_id = ProjectDataRecord.portal_id_from_path(project_relpath)
if portal_id in self.data:
Expand All @@ -164,7 +182,12 @@ def get_modified_or_new_projects(self):
log.info(f"Data not fetched this time for {portal_id}, read data from file")
project_path = os.path.join(self.data_location, project_relpath)

orderer, project_dates, internal_id, internal_name = ProjectDataRecord.data_from_file(project_path)
(
orderer,
project_dates,
internal_id,
internal_name,
) = ProjectDataRecord.data_from_file(project_path)
project_record = ProjectDataRecord(project_path, orderer, project_dates, internal_id, internal_name)
projects_list.append(project_record)

Expand All @@ -174,7 +197,11 @@ def find_unique_orderers(self):
projects_list = self.get_modified_or_new_projects()
orderers = set()
for project in projects_list:
orderers.add(project.orderer)
if self.user_list:
if project.orderer in self.user_list:
orderers.add(project.orderer)
else:
orderers.add(project.orderer)

return orderers

Expand All @@ -200,7 +227,14 @@ class ProjectDataRecord(object):
"None": 0,
}

def __init__(self, relative_path, orderer, project_dates, internal_id=None, internal_name=None):
def __init__(
self,
relative_path,
orderer,
project_dates,
internal_id=None,
internal_name=None,
):
"""relative_path: e.g. "NGIS/2023/NGI0002313.json" """
node_year, file_name = os.path.split(relative_path)
node, year = os.path.split(node_year)
Expand Down

0 comments on commit 78d76e6

Please sign in to comment.