#!/usr/bin/env python3
import hashlib,pathlib,sys,tarfile
here=pathlib.Path(__file__).resolve().parent;business=here.parents[4]/'zhctproject'/'store'
files=[x.split(None,1)[1] for x in (here.parent/'parallel-store-device-catalog-read6-20261010/SOURCE_SHA256.txt').read_text().splitlines()]
files += ['application/api/controller/Card.php','application/api/model/Card.php','application/common/model/Card.php',
 'application/p/controller/Cater.php','application/p/controller/Bill.php','application/p/logic/Bill.php','application/p/controller/Restaurant.php',
 'application/model/Restaurants.php','application/model/Restaurant.php','application/model/Food.php','application/model/Cater.php','application/model/Bill.php',
 'application/p/logic/Menu.php','application/model/Menu.php','application/model/RoleMenu.php','application/model/UserRole.php','application/model/Role.php',
 'application/p/logic/DishCustomCategory.php','application/model/DishesCustomCategory.php','application/p/logic/Dishes.php','application/model/DishesCapeUuid.php']
files=sorted(set(files));assert all((business/f).is_file() for f in files)
(here/'SOURCE_SHA256.txt').write_text(''.join(hashlib.sha256((business/f).read_bytes()).hexdigest()+'  '+f+'\n' for f in files))
with tarfile.open(sys.argv[1],'w:gz') as archive:
    archive.add(here/'runtime_database.php',arcname='source/application/config/poc/database.php',recursive=False)
    for rel in files:
        if not rel.startswith('extend/'):archive.add(business/rel,arcname='source/'+rel,recursive=False)
    for p in here.iterdir():
        if p.is_file() and p.suffix in ['.php','.txt']:archive.add(p,arcname=p.name,recursive=False)
print('frozen_source_files='+str(len(files)))
