Metadata-Version: 2.1
Name: deb-parse
Version: 0.1.2rc2
Summary: Parses Debian Control-File formats.
Home-page: https://github.com/aihaddad/deb-parse.git
Author: Ahmed Elhaddad
Author-email: aihaddad@outlook.com
License: MIT
Platform: UNKNOWN
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Requires-Python: >=3.7.0
Description-Content-Type: text/markdown


# Deb-Parse

A simple parser for [Debian control file formats][1].

Once initialized, it exposes three attributes with information from the input Control File, and one method to export the information to a JSON file.

_A CLI functionality may be added later._

## Installation

Install using `pip`:

```bash
$ pip install --user deb-parse
```

## Usage

### Import it in your project

```python
from deb_parse.parser import Parser
```
Initialze it with a valid Control File path or a string that follows the schema:

```python
my_parser = Parse("/var/lib/dpkg/status")
```
- __Note:__ A `TypeError` is raised if the input is not `str`
- __Note:__ A `ValueError` is raised if the input string or path don't follow the schema

If everything goes well, `my_parser` will now have three accessible attributes:

- `my_parser.pkg_names` outputs a `list` of package names in the input
- `my_parser.raw_pkg_info` outputs a `list` of raw `dict` objects as seen in input
- `my_parser.clean_pkg_info` outputs a `list` of cleaned up `dict` objects with more useful information

_Examples:_

```python
print(my_parser.pkg_names)

['libws-commons-util-java', 'python-pkg-resources', 'tcpd', ... ]
```

```python
print(my_parser.raw_pkg_info)

[{'name': 'libws-commons-util-java', 'details': {'status': 'install ok installed', 'priority': 'optional', 'section': 'java', 'installed-size': '101', 'maintainer': 'Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>', 'architecture': 'all', 'version': '1.0.1-7', 'description': 'Common utilities from the Apache Web Services Project\n This is a small collection of utility classes, that allow high\n performance XML processing based on SAX.', 'original-maintainer': 'Debian Java Maintainers <pkg-java-maintainers@lists.alioth.debian.org>', 'homepage': 'http://ws.apache.org/commons/util/'}}, ... ]
```

```python
print(my_parser.clean_pkg_info)

[{'name': 'libws-commons-util-java', 'details': {'version': '1.0.1-7', 'synopsis': 'Common utilities from the Apache Web Services Project', 'description': 'This is a small collection of utility classes, that allow high\nperformance XML processing based on SAX.', 'depends': None, 'alt_depends': None, 'reverse_depends': None}}, ... ]
```

If you want, you can also dump the parsed information in a JSON file using `.to_json_file()`:

_Attributes:_

- `outfile=str`, default: `'./datastore/dpkgs.json'`
- `names_only=bool`, default: `False` (if `True` outputs list of names and cancels `raw` option)
- `raw=bool`, default: `False` (if `True` outputs raw parse)

If both options are `False`, JSON will be based on clean package information


## Development

For working on `deb-parse`, you will need Python >= 3.7 and [`pipenv`][2] installed. Configure `pipenv` to create its `.venv` in the current folder if you want to use the VS-Code settings. With these installed, run the following command to create a virtualenv for the project and fetch the dependencies:

```bash
$ pipenv install --dev
...
```

Next, activate the virtual environment and get to work:

```bash
$ pipenv shell
...
(deb-parse) $
```

[1]: https://www.debian.org/doc/debian-policy/ch-controlfields.html
[2]: https://docs.pipenv.org/en/latest/


