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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

Details for the file tbip-0.0.0.4.tar.gz.

File metadata

  • Download URL: tbip-0.0.0.4.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.4.3

File hashes

Hashes for tbip-0.0.0.4.tar.gz
Algorithm Hash digest
SHA256 675ab30b32514b83708adb76ab1771ee071ed2ebd3d687bc6254a438923af0a3
MD5 6975e7ddd6495c894eab91ac61e1038f
BLAKE2b-256 f6568395358bb27be638a64cb3b19cbb0d8093b335384e252553589d5fd79df9

See more details on using hashes here.

File details

Details for the file tbip-0.0.0.4-py3-none-any.whl.

File metadata

  • Download URL: tbip-0.0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.4.3

File hashes

Hashes for tbip-0.0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c773699990f564f79d4d4b7d6d6f6500727921a3cd7dd4e733a5a7f497fb6d70
MD5 e191eb71eaeea074a03b70af3670ea7d
BLAKE2b-256 9832db1b559d8ade1364a445c9cb37710c1237fd5c056e66702742ad7b92b51a

See more details on using hashes here.

Supported by

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