# Path: gogdb/core/storage.py
# class Storage:
#     def __init__(self, storage_path):
#         self.storage_path = pathlib.Path(storage_path)
# 
#         self.ids = StorageItem(self.path_ids)
#         self.token = StorageItem(self.path_token)
#         self.product = StorageItem(self.path_product, self.make_product)
#         self.repository = StorageItem(self.path_repository)
#         self.prices = StorageItem(self.path_prices, self.make_prices)
#         self.prices_old = StorageItem(self.path_prices_old, self.make_prices)
#         self.changelog = StorageItem(self.path_changelog, self.make_changelog)
#         self.manifest_v1 = StorageItem(self.path_manifest_v1, compressed=True)
#         self.manifest_v2 = StorageItem(self.path_manifest_v2, compressed=True)
# 
#     def __repr__(self):
#         return f"Storage({repr(self.storage_path)})"
# 
#     def path_ids(self):
#         return self.storage_path / "ids.json"
# 
#     def path_token(self):
#         return self.storage_path / "secret/token.json"
# 
#     def path_product(self, product_id):
#         return self.storage_path / f"products/{product_id}/product.json"
# 
#     @staticmethod
#     def make_product(json_data):
#         return class_from_json(model.Product, json_data)
# 
#     def path_repository(self, product_id, build_id):
#         return self.storage_path / f"products/{product_id}/builds/{build_id}.json"
# 
#     def path_prices(self, product_id):
#         return self.storage_path / f"products/{product_id}/prices.json"
# 
#     def path_prices_old(self, product_id):
#         return self.storage_path / f"products/{product_id}/prices_pre2019.json"
# 
#     @staticmethod
#     def make_prices(json_data):
#         result = {}
#         for country, country_data in json_data.items():
#             result[country] = {}
#             for currency, currency_records in country_data.items():
#                 record_objects = [
#                     class_from_json(model.PriceRecord, record_data)
#                     for record_data in currency_records
#                 ]
#                 result[country][currency] = record_objects
#         return result
# 
#     def path_changelog(self, product_id):
#         return self.storage_path / f"products/{product_id}/changes.json"
# 
#     @staticmethod
#     def make_changelog(json_data):
#         return [class_from_json(model.ChangeRecord, entry) for entry in json_data]
# 
#     def path_manifest_v1(self, manifest_id):
#         return self.storage_path / f"manifests_v1/{manifest_id[0:2]}/{manifest_id[2:4]}/{manifest_id}.json.gz"
# 
#     def path_manifest_v2(self, manifest_id):
#         return self.storage_path / f"manifests_v2/{manifest_id[0:2]}/{manifest_id[2:4]}/{manifest_id}.json.gz"
# 
#     def path_indexdb(self):
#         return self.storage_path / "index.sqlite3"


import shutil
import flask
from gogdb.core.storage import Storage
    if entry.category == "property" and entry.property_record.property_name == "changelog":
        return False
    elif entry.category == "property" and entry.property_record.property_name == "access":
        return False
    elif entry.action == "change" and entry.category == "download":
        if entry.download_record.dl_type != "bonus":
            if entry.download_record.dl_old_software.is_same(entry.download_record.dl_new_software):
                return False

    return True

def fix_changelog_1(db, prod_id):
    changelog = db.changelog.load(prod_id)
    if changelog is None:
        return
    changelog = [c for c in changelog if valid_changelog_entry(c)]
    db.changelog.save(changelog, prod_id)

def fix_product_empty(db, prod_id):
    product = db.product.load(prod_id)
    if product is None:
        return
    if product.title is None or product.type is None:
        print(prod_id, "is empty")
        product_path = db.path_product(prod_id)
        product_path.rename(product_path.with_name("product_removed.json"))

def main():
    config = flask.Config(".")
    config.from_envvar("GOGDB_CONFIG")

# Path: gogdb/core/storage.py
# class Storage:
#     def __init__(self, storage_path):
#         self.storage_path = pathlib.Path(storage_path)
# 
#         self.ids = StorageItem(self.path_ids)
#         self.token = StorageItem(self.path_token)
#         self.product = StorageItem(self.path_product, self.make_product)
#         self.repository = StorageItem(self.path_repository)
#         self.prices = StorageItem(self.path_prices, self.make_prices)
#         self.prices_old = StorageItem(self.path_prices_old, self.make_prices)
#         self.changelog = StorageItem(self.path_changelog, self.make_changelog)
#         self.manifest_v1 = StorageItem(self.path_manifest_v1, compressed=True)
#         self.manifest_v2 = StorageItem(self.path_manifest_v2, compressed=True)
# 
#     def __repr__(self):
#         return f"Storage({repr(self.storage_path)})"
# 
#     def path_ids(self):
#         return self.storage_path / "ids.json"
# 
#     def path_token(self):
#         return self.storage_path / "secret/token.json"
# 
#     def path_product(self, product_id):
#         return self.storage_path / f"products/{product_id}/product.json"
# 
#     @staticmethod
#     def make_product(json_data):
#         return class_from_json(model.Product, json_data)
# 
#     def path_repository(self, product_id, build_id):
#         return self.storage_path / f"products/{product_id}/builds/{build_id}.json"
# 
#     def path_prices(self, product_id):
#         return self.storage_path / f"products/{product_id}/prices.json"
# 
#     def path_prices_old(self, product_id):
#         return self.storage_path / f"products/{product_id}/prices_pre2019.json"
# 
#     @staticmethod
#     def make_prices(json_data):
#         result = {}
#         for country, country_data in json_data.items():
#             result[country] = {}
#             for currency, currency_records in country_data.items():
#                 record_objects = [
#                     class_from_json(model.PriceRecord, record_data)
#                     for record_data in currency_records
#                 ]
#                 result[country][currency] = record_objects
#         return result
# 
#     def path_changelog(self, product_id):
#         return self.storage_path / f"products/{product_id}/changes.json"
# 
#     @staticmethod
#     def make_changelog(json_data):
#         return [class_from_json(model.ChangeRecord, entry) for entry in json_data]
# 
#     def path_manifest_v1(self, manifest_id):
#         return self.storage_path / f"manifests_v1/{manifest_id[0:2]}/{manifest_id[2:4]}/{manifest_id}.json.gz"
# 
#     def path_manifest_v2(self, manifest_id):
#         return self.storage_path / f"manifests_v2/{manifest_id[0:2]}/{manifest_id[2:4]}/{manifest_id}.json.gz"
# 
#     def path_indexdb(self):
#         return self.storage_path / "index.sqlite3"


# Path: gogdb/tools/cleanup.py
import shutil
import flask
from gogdb.core.storage import Storage

    if entry.category == "property" and entry.property_record.property_name == "changelog":
        return False
    elif entry.category == "property" and entry.property_record.property_name == "access":
        return False
    elif entry.action == "change" and entry.category == "download":
        if entry.download_record.dl_type != "bonus":
            if entry.download_record.dl_old_software.is_same(entry.download_record.dl_new_software):
                return False

    return True

def fix_changelog_1(db, prod_id):
    changelog = db.changelog.load(prod_id)
    if changelog is None:
        return
    changelog = [c for c in changelog if valid_changelog_entry(c)]
    db.changelog.save(changelog, prod_id)

def fix_product_empty(db, prod_id):
    product = db.product.load(prod_id)
    if product is None:
        return
    if product.title is None or product.type is None:
        print(prod_id, "is empty")
        product_path = db.path_product(prod_id)
        product_path.rename(product_path.with_name("product_removed.json"))

def main():
    config = flask.Config(".")
    config.from_envvar("GOGDB_CONFIG")

    db = Storage(config["STORAGE_PATH"])