Skip to content

Commit

Permalink
Tell the status page which mods are frozen
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Nov 20, 2019
1 parent f0ea791 commit ac2f6f4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
13 changes: 13 additions & 0 deletions netkan/netkan/auto_freezer.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ def freeze_idle_mods(self, days_limit):
self._submit_pr(self.BRANCH_NAME, days_limit)
self.netkan_repo.heads.master.checkout()

def mark_frozen_mods(self):
with ModStatus.batch_write() as batch:
logging.info('Marking frozen mods...')
for mod in ModStatus.scan(rate_limit=5):
if not mod.frozen and self._is_frozen(mod.ModIdentifier):
logging.info('Marking frozen: %s', mod.ModIdentifier)
mod.frozen = True
batch.save(mod)
logging.info('Done!')

def _is_frozen(self, ident):
return not Path(self.netkan_repo.working_dir, 'NetKAN', f'{ident}.netkan').exists()

def _checkout_branch(self, name):
try:
self.netkan_repo.remotes.origin.fetch(name)
Expand Down
6 changes: 4 additions & 2 deletions netkan/netkan/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,12 @@ def ticket_closer(token, days_limit):
)
def auto_freezer(netkan_remote, token, repo, user, days_limit, key):
init_ssh(key, '/home/netkan/.ssh')
AutoFreezer(
af = AutoFreezer(
init_repo(netkan_remote, '/tmp/NetKAN'),
GitHubPR(token, repo, user)
).freeze_idle_mods(days_limit)
)
af.freeze_idle_mods(days_limit)
af.mark_frozen_mods()


netkan.add_command(indexer)
Expand Down
2 changes: 2 additions & 0 deletions netkan/netkan/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ def status_attrs(self, new=False):
# If we have perfomed an inflation, we certainly
# have checked the mod!
'last_checked': inflation_time,
# If we're inflating it, it's not frozen
'frozen': False,
}
resources = getattr(self.ckan, 'resources', None)
if resources:
Expand Down
1 change: 1 addition & 0 deletions netkan/netkan/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Meta:
last_indexed = UTCDateTimeAttribute(null=True)
last_inflated = UTCDateTimeAttribute(null=True)
success = BooleanAttribute()
frozen = BooleanAttribute(default=False)
resources = MapAttribute(default={})

def mod_attrs(self):
Expand Down

0 comments on commit ac2f6f4

Please sign in to comment.