Package: tbip
a flexible cross-platform package to create installers using PythonContentsAboutExampleUsageInstallationAdvanced UsageGetting PrivelegesWindowsUnix/LinuxItemsReadmeLicenceCallerChoiceInstallation progressCommand Line optionsDeriving classesUser InterfacesItemsContributingIn the FutureAboutTBIP is a package designed to let you build installers with python,
easily and be very flexible at the same time.Exampleimportioimportosimporttbip.installerasinstallfromtbip.cliimportCLIimporttbip.uiutilsasutilsLICENCE="""
a fake licence.
"""README="Howdy. Bye now, this thing does stuff."defmain():installer=install.Installer([utils.Readme(io.StringIO(README)),# a readme classutils.Licence(io.StringIO(LICENCE)),# a licence classutils.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/thingos.path.join(os.environ.get('HOME')oros.environ.get('USERPROFILE'),'thing'),# use the CLI interfaceCLI,)# run the installerinstaller.run()if__name__=='__main__':main()a very small, but functional example of a script.Usageokay, 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 withpython -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.Installationinstall frompip install tbip. or, clone the repository,git clone https://github.com/michael78912/tbip.git, and runpython3 setup.py installAdvanced UsageGetting PrivelegesWindowstbip.get_admin()should restart the program as an administrator.
if not, the user probably has insufficient rights.Unix/Linuxtbip.get_root()should replace the current program with gksudo,
nd run it as root.if it does not work, install gksudo in the packagegksu, and try again.Itemsa note on how items interact with their UI: the UI object
you passed toInstallerwas sent to each of the items you also sent.
when an item’srunmethod is called, it is expected to return 1 of 2
values, which is passed to the UI’s :0: everything went OK, continue1: something happened, abortthere is a wider variety of  items in tbip.uiutils that can be used during the installation.
they include:ReadmeLicenceCallerChoiceReadmedisplays a readme, and tells the user to press enter to continue.Readme(file)–> tbip.uiutils.Readme objectLicencedisplays a licence, preceded by the header “LICENCE:”.
aks the user if this is OK and wants to continue.Licence(file)–> tbip.uiutils.Licence objectCallercalls an external program, with the arguments specified.
just a very thin wrapper aroundsubprocess.call.Caller(args)–> tbip.uiutils.Caller objectChoiceprompts 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 objectInstallation progressthere are sevreal ways to watch the installation progress
(all accessed intbip.installer.ProgressUtils)Descriptionnamevaluea progress barProgressUtils.PROGRESS_BAR0percentageProgressUtils.PERCENT1displaying each file processedProgressUtils.FILES-2do absolutely nothingProgressUtils.NULL3at first, display a messageProgressUtils.MSG4Command Line optionstbip usesPyInstallerinternally to freeze the output scripts.Miscellaneous:-h,--helpdisplay help-v,--versiondisplay version information-d,--data<dir>bundle this data with script in a zip file-o<output>output filename of script-f,--freezefreeze the installer scriptPyInstaller specific:-u,--upx<dir>directory whereUPXis installed (if at all)-w,--windoweduse no console window (Windows specific)-i,--icon<icon>path to icon file (Windows specific)Deriving classesonly the classes UI and Item should be derived from. find the base classes for:UI:tbip.ui.UIItem:tbip.uiutils.baseitem.ItemUser Interfacesthe 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 usedgetchyet, but i might, so it would be good to)they all should be self explanitory, but:echooutputs the message to the screen in CLI it is just a wrapper aroundprint.
it should be able to take all of the arguments you see there, and act accordingly.get_inputshould 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)getchshould read a single character. if echo is true, echo the character too.clearshould simply clear the displayItemsItems are easier. here isCaller: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 haverunoverridden, because if you didn’t, it would do nothing.remember that :code:`run` must always return 1 or 0!Contributingany help is appreciated. if you want to help, pleaseforkthis 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 FutureI 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 atmichael.78912.8@gmail.com