def diff(trunk=None, modifiers=None): assert isinstance(trunk, str) resource = resource_by_trunk(trunk)() if modifiers is None: modifiers = resource.modifiers def apply(modifiers): def func(expl): for modifier in modifiers: if expl is None: break expl = modifier(expl) return expl return func with get_storage(trunk) as old_explanations: new_explanations = list( map( str, filter(lambda x: x is not None, map(apply(modifiers), resource)))) return difflib.unified_diff(list(map(str, old_explanations.entries())), new_explanations)
def __init__(self, storage_name: str): self._name = storage_name self.explanations_by_name = dict() self.explanations_by_key = dict() self.storage = get_storage(storage_name) for explanation in self.storage.entries(): self.explanations_by_key[explanation.key] = explanation if explanation.title not in self.explanations_by_name: self.explanations_by_name[explanation.title] = list() self.explanations_by_name[explanation.title].append(explanation)
def resource_build(res_obj): trunk = res_obj.trunk if trunk in _built_trunks: print("= Skipping {} generation as the resource is already built".format(trunk)) return _building_trunks.add(trunk) build_deps(res_obj) print("<=> Starting {} generation <=>".format(trunk)) start = time.monotonic() with get_storage(trunk) as out_storage: count = generate_asset(res_obj, out_storage) end = time.monotonic() print("> {} generated in {} seconds".format(trunk, end - start)) print("> {} explanations have passed the filters".format(count)) _building_trunks.remove(trunk) _built_trunks.add(trunk)
def diff(trunk=None, modifiers=None): assert isinstance(trunk, str) resource = resource_by_trunk(trunk)() if modifiers is None: modifiers = resource.modifiers def apply(modifiers): def func(expl): for modifier in modifiers: if expl is None: break expl = modifier(expl) return expl return func with get_storage(trunk) as old_explanations: new_explanations = list(map(str, filter(lambda x: x is not None, map(apply(modifiers), resource)))) return difflib.unified_diff(list(map(str, old_explanations.entries())), new_explanations)
def resource_build(res_obj): trunk = res_obj.trunk if trunk in _built_trunks: print( "= Skipping {} generation as the resource is already built".format( trunk)) return _building_trunks.add(trunk) build_deps(res_obj) print("<=> Starting {} generation <=>".format(trunk)) start = time.monotonic() with get_storage(trunk) as out_storage: count = generate_asset(res_obj, out_storage) end = time.monotonic() print("> {} generated in {} seconds".format(trunk, end - start)) print("> {} explanations have passed the filters".format(count)) _building_trunks.remove(trunk) _built_trunks.add(trunk)
#!/usr/bin/env python3 import sys from hb_res.storage import get_storage name = sys.argv[1] count = int(sys.argv[2]) if len(sys.argv) >= 3 else 500 with get_storage(name) as stor: good = sorted(stor.entries(), key=lambda e: (e.prior_rating, e), reverse=True)[:count] for e in good: print(e)
def test_actuality(trunk): with get_storage(trunk) as storage: stored = tuple(storage.entries()) actual = asset_cache(trunk) unittest.TestCase().assertTupleEqual(stored, actual)
__author__ = 'moskupols' from hb_res.storage import list_storages, get_storage, FileExplanationStorage from diff_match_patch import diff_match_patch CUR_DIR = os.path.dirname(os.path.abspath(__file__)) SEL_PATH = os.path.join(CUR_DIR, 'SelectedAfterMissedModifiers.asset') OUT_PATH = os.path.join(CUR_DIR, 'SelectedWithRightKeys.asset') all_expls = [] by_key = {} by_text = {} by_title = {} for trunk in list_storages(): with get_storage(trunk) as stor: for expl in stor.entries(): expl.trunk = trunk all_expls.append(expl) by_key[expl.key] = expl by_text[expl.text] = expl by_title.setdefault(expl.title, []).append(expl) abused = set() dmp = diff_match_patch() with FileExplanationStorage(SEL_PATH) as inp: with FileExplanationStorage(OUT_PATH) as out: out.clear() for sel in inp.entries():
from hb_res.storage import list_storages, get_storage, FileExplanationStorage from diff_match_patch import diff_match_patch CUR_DIR = os.path.dirname(os.path.abspath(__file__)) SEL_PATH = os.path.join(CUR_DIR, 'SelectedAfterMissedModifiers.asset') OUT_PATH = os.path.join(CUR_DIR, 'SelectedWithRightKeys.asset') all_expls = [] by_key = {} by_text = {} by_title = {} for trunk in list_storages(): with get_storage(trunk) as stor: for expl in stor.entries(): expl.trunk = trunk all_expls.append(expl) by_key[expl.key] = expl by_text[expl.text] = expl by_title.setdefault(expl.title, []).append(expl) abused = set() dmp = diff_match_patch() with FileExplanationStorage(SEL_PATH) as inp: with FileExplanationStorage(OUT_PATH) as out: out.clear() for sel in inp.entries():