Giter Club home page Giter Club logo

Comments (2)

mingwandroid avatar mingwandroid commented on May 29, 2024

This horribleness is what I am currently doing (from Python) to determine the filters and formats:

def _get_exports(filename, arch='native'):
    if not os.path.exists(filename):
        return []
    if filename.endswith('.a') or filename.endswith('.lib'):
        # Crappy, sorry.
        import subprocess
        # syms = os.system('nm -g {}'.filename)
        # on macOS at least:
        # -PgUj is:
        # P: posix format
        # g: global (exported) only
        # U: not undefined
        # j is name only
        if sys.platform == 'darwin':
            flags = '-PgUj'
        else:
            flags = '-P'
        out, _ = subprocess.Popen(['nm', flags, filename], shell=False,
                         stdout=subprocess.PIPE).communicate()
        results = out.decode('utf-8').splitlines()
        exports = [r.split(' ')[0] for r in results if (' T ') in r]
        return exports


def get_libarchive_filters():
    # This is horrible!
    exports = _get_exports(os.path.join(sys.prefix, 'lib', 'libarchive.a'))
    filters = {export.replace('_archive_write_add_filter_', '')
               for export in exports if '_archive_write_add_filter_' in export}
    for unwanted in ('by_name', 'program'):
        if unwanted in filters:
            filters.remove(unwanted)
    return filters


def get_libarchive_formats():
    # This is too!
    exports = _get_exports(os.path.join(sys.prefix, 'lib', 'libarchive.a'))
    formats = {export.replace('_archive_write_set_format_', '')
               for export in exports if '_archive_write_set_format_' in export}
    for unwanted in ('by_name', 'filter_by_ext', 'filter_by_ext_def', 'option'):
        if unwanted in formats:
            formats.remove(unwanted)
    return formats

from python-libarchive-c.

mingwandroid avatar mingwandroid commented on May 29, 2024

This works better!

def get_libarchive_filters():
    from libarchive.ffi import WRITE_FILTERS
    return WRITE_FILTERS

def get_libarchive_formats():
    from libarchive.ffi import WRITE_FORMATS
    return WRITE_FORMATS

from python-libarchive-c.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.