chamesle

chamesle.org: the site of Chamesle, a small Linux distribution
git clone https://github.com/tortr-rs/chamesle
Log | Files | Refs | README

package-list.py (1027B)


      1 #!/usr/bin/env python3
      2 # writes docs/packages.json from the repo index, for the search on the packages page
      3 # usage: apk adbdump work/repo/x86_64/Packages.adb | tools/site/package-list.py > docs/packages.json
      4 import json, sys
      5 
      6 pkgs, cur, block = [], None, False
      7 for line in sys.stdin:
      8     if block:
      9         # the rest of a multi-line description
     10         if line.startswith('      '):
     11             cur['d'] = (cur.get('d', '') + ' ' + line.strip()).strip()
     12             continue
     13         block = False
     14     if line.startswith('  - name: '):
     15         cur = {'n': line[10:].strip()}
     16         pkgs.append(cur)
     17     elif cur is not None and line.startswith('    ') and not line.startswith('      '):
     18         k, _, v = line.strip().partition(': ')
     19         if k == 'version':
     20             cur['v'] = v
     21         elif k == 'description':
     22             block = v in ('|', '>', '|-', '>-')
     23             cur['d'] = '' if block else v
     24         elif k == 'installed-size':
     25             cur['s'] = int(v)
     26 json.dump(pkgs, sys.stdout, separators=(',', ':'))