Skip to content

Commit

Permalink
Check release date in AutoFreezer (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan authored Jun 30, 2020
1 parent 7919837 commit db38ebe
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
12 changes: 7 additions & 5 deletions netkan/netkan/auto_freezer.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ def _ids(self) -> Iterable[str]:

def _too_old(self, ident: str, update_cutoff: datetime) -> bool:
status = ModStatus.get(ident)
release_date = getattr(status, 'release_date', None)
if release_date:
return release_date < update_cutoff
last_indexed = getattr(status, 'last_indexed', None)
if not last_indexed:
# Never indexed since the start of status tracking = 4+ years old
# ... except for mods that were updated by the old webhooks :(
return False
else:
if last_indexed:
return last_indexed < update_cutoff
# Never indexed since the start of status tracking = 4+ years old
# ... except for mods that were updated by the old webhooks :(
return False

def _add_freezee(self, ident: str) -> None:
self.nk_repo.git_repo.index.move([
Expand Down
3 changes: 3 additions & 0 deletions netkan/netkan/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ def status_attrs(self, new: bool = False) -> Dict[str, Any]:
attrs['ModIdentifier'] = self.ModIdentifier
if self.indexed:
attrs['last_indexed'] = datetime.now(timezone.utc)
release_date = getattr(self.ckan, 'release_date', None)
if release_date:
attrs['release_date'] = release_date
return attrs

def _process_ckan(self) -> None:
Expand Down
16 changes: 15 additions & 1 deletion netkan/netkan/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import uuid
import urllib.parse
import github
import dateutil.parser
from typing import Optional, List, Tuple, Union, Any, Dict


Expand Down Expand Up @@ -253,14 +254,27 @@ def __str__(self) -> str:
'application/x-compressed-tar': 'tar.gz',
'application/zip': 'zip',
}
ISODATETIME_PROPERTIES = [
'release_date'
]

def __init__(self, filename: Union[str, Path] = None, contents: str = None) -> None:
if filename:
self.filename = Path(filename)
self.contents = self.filename.read_text()
elif contents:
self.contents = contents
self._raw = json.loads(self.contents)
self._raw = json.loads(self.contents, object_hook=self._custom_parser)

def _custom_parser(self, dct: Dict[str, Any]) -> Dict[str, Any]:
# Special handling for DateTime fields
for k in self.ISODATETIME_PROPERTIES:
if k in dct:
try:
dct[k] = dateutil.parser.isoparse(dct[k])
except:
pass
return dct

def __getattr__(self, name: str) -> Any:
if name in self._raw:
Expand Down
1 change: 1 addition & 0 deletions netkan/netkan/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Meta:
last_checked = UTCDateTimeAttribute(null=True)
last_indexed = UTCDateTimeAttribute(null=True)
last_inflated = UTCDateTimeAttribute(null=True)
release_date = UTCDateTimeAttribute(null=True)
success = BooleanAttribute()
frozen = BooleanAttribute(default=False)
resources: 'MapAttribute[str, Any]' = MapAttribute(default={})
Expand Down

0 comments on commit db38ebe

Please sign in to comment.