Skip to main content

Build cross-platform installers

Project description

a flexible cross-platform package to create installers using Python

About

TBIP is a package designed to let you build installers with python, easily and be very flexible at the same time.

Example

import io
import os

import tbip.installer as install
from tbip.cli import CLI
import tbip.uiutils as utils

LICENCE = """
a fake licence.
"""

README = "Howdy. Bye now, this thing does stuff."


def main():
    installer = install.Installer(
        [
            utils.Readme(io.StringIO(README)),
            # a readme class
            utils.Licence(io.StringIO(LICENCE)),
            # a licence class
            utils.Choice('proceed with installation?'),
            # make sure you want to continue
        ],
        [
            utils.Readme(io.StringIO('you installed it. good work.'))
            # output message after installation
        ],
        # install to home directory/thing
        os.path.join(os.environ.get('HOME')
                    or os.environ.get('USERPROFILE'), 'thing'),
        # use the CLI interface
        CLI,
    )

    # run the installer
    installer.run()

if __name__ == '__main__':
    main()

a very small, but functional example of a script.

Usage

okay, say we had that script saved, and ready to use. but what is the point? it’s not going to actually install anything, because you havent even specified where to install!!

that’s where the command line comes in handy. you should be able to run this with python -m tbip <script-name> -d <data-directory>. this will bundle your data in the installer script, as a zip file encoded in base64, to be extracted at runtime and installed from there on.

Installation

install from pip install tbip. or, clone the repository, git clone https://github.com/michael78912/tbip.git, and run python3 setup.py install

Advanced Usage

Getting Priveleges

Windows

tbip.get_admin() should restart the program as an administrator. if not, the user probably has insufficient rights.

Unix/Linux

tbip.get_root() should replace the current program with gksudo, nd run it as root.

if it does not work, install gksudo in the package gksu, and try again.

Items

a note on how items interact with their UI: the UI object you passed to Installer was sent to each of the items you also sent. when an item’s run method is called, it is expected to return 1 of 2 values, which is passed to the UI’s :

  • 0: everything went OK, continue

  • 1: something happened, abort

there is a wider variety of items in tbip.uiutils that can be used during the installation. they include:

  • Readme

  • Licence

  • Caller

  • Choice

Readme

displays a readme, and tells the user to press enter to continue.

Readme(file) –> tbip.uiutils.Readme object

Licence

displays a licence, preceded by the header “LICENCE:”. aks the user if this is OK and wants to continue.

Licence(file) –> tbip.uiutils.Licence object

Caller

calls an external program, with the arguments specified. just a very thin wrapper around subprocess.call.

Caller(args) –> tbip.uiutils.Caller object

Choice

prompts the user for a string, and acts accordingly. if the string enterd is not valid, prompt again.

Choice(msg="continue?", opts={'y': lambda: 0, 'n': lambda: 1}, ignorecase=True) –> tbip.uiutils.Choice object

Installation progress

there are sevreal ways to watch the installation progress (all accessed in tbip.installer.ProgressUtils)

Description

name

value

a progress bar

ProgressUtils.PROGRESS_BAR

0

percentage

ProgressUtils.PERCENT

1

displaying each file processed

ProgressUtils.FILES-

2

do absolutely nothing

ProgressUtils.NULL

3

at first, display a message

ProgressUtils.MSG

4

Command Line options

tbip uses PyInstaller internally to freeze the output scripts.

Miscellaneous:

-h, --help

display help

-v, --version

display version information

-d, --data <dir>

bundle this data with script in a zip file

-o <output>

output filename of script

-f, --freeze

freeze the installer script

PyInstaller specific:

-u, --upx <dir>

directory where UPX is installed (if at all)

-w, --windowed

use no console window (Windows specific)

-i, --icon <icon>

path to icon file (Windows specific)

Deriving classes

only the classes UI and Item should be derived from. find the base classes for:

  • UI: tbip.ui.UI

  • Item: tbip.uiutils.baseitem.Item

User Interfaces

the CLI (Command Line Interface) is a UI. you can see here:

all those methods should be overridden in a new class. (I actually haven’t used getch yet, but i might, so it would be good to)

they all should be self explanitory, but:

echo outputs the message to the screen in CLI it is just a wrapper around print. it should be able to take all of the arguments you see there, and act accordingly.

get_input should be able to read one line. the length parameter acts a bit like quantifiers in a regex. ?: truncate it to one character, or 0 +: will return if the string is one character or more, if it is null, will prompt again. *: any length (including 0)

(of course, any integer will work too)

getch should read a single character. if echo is true, echo the character too.

clear should simply clear the display

Items

Items are easier. here is Caller:

simple, short and sweet. of course, this is a minimal example, you can create any item you want to do anything you want!

it must have run overridden, because if you didn’t, it would do nothing. remember that :code:`run` must always return 1 or 0!

Contributing

any help is appreciated. if you want to help, please fork this repository, and create a pull request when you want to. also, please note any bugs, and if you have any suggestions, I would be glad to try them! thank you!

In the Future

I plan on making a GUI User interface. this is probably top of my list on things to do. once again, if you have any suggestions, either make an issue, or email me at michael.78912.8@gmail.com

Project details


Download files

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

Source Distribution

tbip-0.0.0.4.tar.gz (16.4 kB view hashes)

Uploaded Source

Built Distribution

tbip-0.0.0.4-py3-none-any.whl (16.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page