Skip to content

Instantly share code, notes, and snippets.

@minexew
Last active August 28, 2019 19:28

Revisions

  1. minexew revised this gist Aug 28, 2019. 3 changed files with 109 additions and 0 deletions.
    34 changes: 34 additions & 0 deletions mf-generic-to-repo.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    #!/usr/bin/env python

    # Convert a generic manifest to a repo manifest

    # Example usage: mf-generic-to-repo PkgBin/Wget.MF packages/wget packages/files/Wget.ISO.C

    from __future__ import print_function

    import os
    import sys

    if len(sys.argv) < 4:
    print('usage: mf-local-to-repo.py <manifest-in> <manifest-out> <installable>')
    sys.exit(-1)

    MANIFEST_IN = sys.argv[1]
    MANIFEST_OUT = sys.argv[2]
    INSTALLABLE = sys.argv[3]

    manifest = {}

    with open(MANIFEST_IN, 'rb') as in_:
    for line in in_:
    (key, value) = line.rstrip().split('\t')
    manifest[key] = value

    #print(manifest)

    manifest['iso.c'] = os.path.relpath(INSTALLABLE, os.path.dirname(MANIFEST_OUT))
    manifest['size'] = os.stat(INSTALLABLE).st_size

    with open(MANIFEST_OUT, 'wb') as out:
    for key in sorted(manifest):
    print(key, manifest[key], sep='\t', file=out)
    39 changes: 39 additions & 0 deletions update-package.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    #!/usr/bin/env python

    from __future__ import print_function

    import os
    import sys

    if len(sys.argv) < 6:
    print('usage: update-package.py <dir> <name> <release> <version> <filename>')
    sys.exit(-1)

    DIR = sys.argv[1]
    PKGNAME = sys.argv[2]
    RELEASE = sys.argv[3]
    VERSION = sys.argv[4]
    FILENAME = sys.argv[5]

    MANIFEST = os.path.join(DIR, PKGNAME)
    TMP = 'package.tmp'

    manifest = {}

    with open(MANIFEST, 'rb') as in_:
    for line in in_:
    (key, value) = line.rstrip().split('\t')
    manifest[key] = value

    #print(manifest)

    manifest['iso.c'] = FILENAME
    manifest['release'] = RELEASE
    manifest['version'] = VERSION
    manifest['size'] = os.stat(os.path.join(DIR, FILENAME)).st_size

    with open(TMP, 'wb') as out:
    for k, v in manifest.iteritems():
    print(k, v, sep='\t', file=out)

    os.rename(TMP, MANIFEST)
    36 changes: 36 additions & 0 deletions update-package2.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    #!/usr/bin/env python

    from __future__ import print_function

    import os
    import sys

    if len(sys.argv) < 5:
    print('usage: update-package2.py <dir> <name> <manifest> <filename>')
    sys.exit(-1)

    DIR = sys.argv[1]
    PKGNAME = sys.argv[2]
    MANIFEST = sys.argv[3]
    FILENAME = sys.argv[4]

    MANIFEST_OUT = os.path.join(DIR, PKGNAME)
    TMP = 'package.tmp'

    manifest = {}

    with open(MANIFEST, 'rb') as in_:
    for line in in_:
    (key, value) = line.rstrip().split('\t')
    manifest[key] = value

    #print(manifest)

    manifest['iso.c'] = FILENAME
    manifest['size'] = os.stat(os.path.join(DIR, FILENAME)).st_size

    with open(TMP, 'wb') as out:
    for k, v in manifest.iteritems():
    print(k, v, sep='\t', file=out)

    os.rename(TMP, MANIFEST_OUT)
  2. minexew created this gist Aug 28, 2019.
    20 changes: 20 additions & 0 deletions build-packages-list.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    #!/usr/bin/env python

    #usage: build-package-list.py <directory>

    from __future__ import print_function

    import os
    import sys

    DIR = sys.argv[1]
    TMP = 'packages.list.tmp'

    files = os.listdir(DIR)

    with open(TMP, 'wb') as out:
    for entry in sorted(files):
    if not '.' in entry and os.path.isfile(os.path.join(DIR, entry)):
    print(entry, file=out)

    os.rename(TMP, os.path.join(DIR, 'packages.list'))