Skip to main content
Donate to the Python Software Foundation or Purchase a PyCharm License to Benefit the PSF! Donate Now

Inetsix tools library

Project description

Inetsix Python toolbox

Build Status Documentation Status PyPI version

This module provides some generic python functions usually used in many of scripts. Instead of rewriting these functions in all scripts, we have put them in a single module.

Current classes:

  • ExcelSerializer from inetsix.excel: Class to serialize excel spreadsheet into Python structure to be consume in scripts or templates
  • InetsixTools from inetsix.tools: Use @classmethod to provide some generic functions
    • PPRINT rendering
    • List of files in a given directory
    • Get basname of a complete path to a file
    • Extract a list() of unique values in a list()
    • Convert a dict() to a list()
    • Download file with HTTP/HTTPS transport
    • Set variable from user environment

Installation

$ pip install inetsix

Quick Start

Generic tools Functions usage

This example shows you how to use some functions:

import inetsix.tools
import os
import logging

FOLDER='../dist/'
STRUCTURE_JPRINT='{"access":10,"configured":true,"hostname":"leaf1-demo","mode":"switch","description":"Access interface","name":"ethernet 1"}'
URI_DOWNLOAD='https://web.inetsix.net/index.html'

if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG)
    logging.info('Starting test with version: '+inetsix.version)

    # Print a JSON structure
    # without initiate a pprint configuration

    logging.info('Validate inetsix.jprint with JSON string')
    inetsix.tools.InetsixTools.jprint(STRUCTURE_JPRINT)

    # List all file with `whl` extension in a given directory
    # Result is a list of filenames

    logging.info('Validation inetsix.get_list_files')
    print inetsix.tools.InetsixTools.get_list_files(path=FOLDER, extension='whl')

    # Download a file from an HTTPS server
    # and save it in the current directory

    logging.info('Test download validation with HTTPS')
    result = inetsix.tools.InetsixTools.download_file(remote_file=URI_DOWNLOAD)
    logging.info('Downloaded file %s', result)
    logging.warning('remove downloaded file')
    os.remove(result)

    logging.info('End process validation')

it can also be used with following syntax:

from inetsix.tools import InetsixTools

STRUCTURE_JPRINT='{"access":10,"configured":true,"hostname":"leaf1-demo","mode":"switch","description":"Access interface","name":"ethernet 1"}'
URI_DOWNLOAD='https://web.inetsix.net/index.html'

InetsixTools.jprint(STRUCTURE_JPRINT)
result = InetsixTools.download_file(remote_file=URI_DOWNLOAD)

As code was built with come generic function directly on top of the library, those ones will remains for legacy but not maintained anymore

Class use case:

import inetsix
import logging
from inetsix.excel import ExcelSerializer

EXCELFILENAME = '.ci/excel-demo.xlsx'

if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG)

    myExcel = ExcelSerializer(excel_path=EXCELFILENAME)
    myExcel.serialize_table(sheet="test", nb_columns=3)

    inetsix.jprint(myExcel.get_data(sheet="test"))

Output example:

[   {   u'address': '10.0.0.1/24', u'id': '1', u'name': 'eh0'},
    {   u'address': '10.0.10.1/24', u'id': '2', u'name': 'eth1'},
    {   u'address': '10.0.20.1/24', u'id': '3', u'name': 'eth2'}]

Get code documentation

To get code documentation, use command:

$ python

>>> import inetsix
>>> help(inetsix)

>>> from inetsix.excel import ExcelSerializer
>>> help(ExcelSerializer)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
inetsix-0.0.4.tar.gz (11.5 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page