0

I don't really know how to phrase this question any better, so let's go with an example:

I installed liveusb-creator on my Fedora a while ago and I wonder where the files it executes are located. I know about which and whereis:

which liveusb-creator /usr/sbin/liveusb-creator

liveusb-creator itself is some piece of Python code which contains, along with some method parse_args() which simply does what its name says, this:

    import sys
    import os        
    from liveusb import _

    def parse_args():
         #
         # some code that handles parsing command line arguments...
         #

    def main():
        opts, args = parse_args()
        if opts.console:
            from liveusb import LiveUSBCreator
            try:
                live = LiveUSBCreator(opts)
                live.detect_removable_drives()
                live.verify_filesystem()
                live.extract_iso()
                live.update_configs()
                live.install_bootloader()
            except Exception, e:
                print str(e)
            x = raw_input("\nDone!  Press any key to exit")
        else:
            ## Start our graphical interface
            from liveusb.gui import LiveUSBApp
            try:
                LiveUSBApp(opts, sys.argv)
            except KeyboardInterrupt:
                pass

    if __name__ == '__main__':
        if sys.platform != 'win32':
            if os.getuid() != 0:
                print >> sys.stderr, _("You must run this application as root")
                sys.exit(1)
        main()

It occurred to me that the Python code itself isn't the program that you see when you run the LiveUSB-application. I don't understand Python so this is kind of cryptic for me: Where is the actual file that gets executed?

It also seems to do some import magic in

from liveusb import LiveUSBCreator

How does it know what liveusb and LiveUSBCreator are?

  • Those methods inside the try block are the main part of the script. Google them one by one to see what they do. – schaiba Nov 24 '15 at 7:12
2

The first line of the script probably should start with #!, followed by the name of the python interpreter. (Like /usr/bin/env python.) You can start it manually in a terminal, and add a -v:

/usr/bin/env python -v

it will overwhelm you with 100 lines of information because of the -v. To see the location of the liveusb python module, type

import liveusb

(or from liveusb import _), press enter, and you should get the information you are looking for.

Use Control+D to exit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.