Project 9A: Command Practice with pyWings

 < Day Day Up > 



Now that you know a few commands, let’s put them to good use. The program you will be installing in this project is a simple, and admittedly kind of silly, oracle program called pyWings (see Figure 9-7). pyWings will give you cryptic guidance in response to whatever questions you may ask it.

click to expand
Figure 9-7: Seeking wisdom from pyWings

To use pyWings, you type whatever your confusion is in the input box, and then click one of the concern icons on the left (self, another, world), one of the realm icons on the right (love, work, truth), and then you hit the big button that looks like half an eye. The oracle will then tell you what it has to say. As an example, I asked the oracle if I am going to be rich, picked self as my concern and truth as the realm. Figure 9-8 shows the wisdom that was bestowed upon me.

click to expand
Figure 9-8: PyWings bestows its wisdom

As you can see, the oracle told me, “A rush to the ending frightens it away,” which I will interpret as a call for patience — if I push too much, I will remain a paycheck-to-paycheck sort of guy.

pyWings is written in a programming language called Python, which actually creates scripts rather than true conventional programs. You will find out a little more about this distinction in Chapter 11. For now, one of the differences I can mention right off the bat is that you don’t actually have to install pyWings; you are simply going to put it on your hard drive in your Home folder and run it from there, more or less as is.

9A-1: Getting the pyWings Files

OK, so now you are just about ready to begin installing pyWings, but before you do, you must get the files you need. First of all, you will need pyWings itself, which you can get from the project’s home page at http://pywings.sourceforge. net/download.html. Just scroll down the page to the section that says Unix/ Linux/X11 and click the HTTP link, which will get you the file pywings-1.0.1.tar.gz (the .tar.gz ending tells you that this is a tarball — the Linux world’s answer to ZIP files). Put the file in your Tarballs_and_RPMs folder, which is inside your Home folder.

PyWings requires that you have tkinter, one of the several graphical interface packages for Python scripts, installed on your system, and tkinter has three dependencies of its own that you must also install in order for it to work — this is your first real experience with dependency hell. Fortunately, this isn’t all that hellish an endeavor, as all four files are available on your installation disks. Of course, you can simply copy these files to your hard disk via the familiar drag-and- drop method, but because you are learning about the command line, let’s do it via the Terminal.

9A-2: Copying tkinter and Its Dependencies to Your Hard Disk

The files tkinter, itcl, and tix can all be found on the Fedora (or Red Hat) installation disks. Before you copy these files to your hard disk, first use the mkdir command to create a special folder inside your Home folder in which to place these RPM files:

  1. Open a new Terminal window, type mkdir expRPMS and then press ENTER.

    Now that you have a folder in which to place these RPM files, it is time to copy them from the CD to the expRPMS folder you’ve just created. To do this, you will be using the cd (change directory) and cp (copy) commands.

  2. Insert Install Disk 2 (or Disk 3 for Red Hat 9 folk or those of you using the three-CD edition of Fedora Core) into your CD drive and wait until it is automatically mounted.

  3. In the Terminal window, cd to the RPMS folder on the installation disk by typing the following and pressing ENTER: cd /mnt/cdrom/Fedora/RPMS/ (for Red Hat 9 users, that would be /mnt/cdrom/RedHat/RPMS/, of course).

    Now copy each of the RPM files to the expRPMS folder on your hard disk by typing the following command strings and pressing ENTER after each one (be sure to use your username where it says username):

    cp tkinter* /home/username/expRPMS/ cp itcl* /home/username/expRPMS/ cp tix* /home/username/expRPMS/
    Note 

    In the preceding step you used the wildcard character, the asterisk (*), rather than typing in the full filename (for example, tix* instead of tix-8.1.4-93.i386.rpm) in order to save your fingers some wear and tear. The wildcard character (*) is a shortcut of sorts. When you typed in tix*, you were essentially telling your system to copy anything beginning with tix. If you had typed *tix, you would have been telling the system to copy anything ending in tix. As you can see, you should be careful when you do this on your own, because you might end up copying a lot of files you weren’t counting on.

  4. In your Command Terminal, cd back to your home directory by typing cd and pressing ENTER.

  5. The other required dependency file, tk, should already be installed on your system if you followed my system installation instructions in Chapter 2, but you can check it out for yourself using the rpm command with the -q (query) flag. Type in rpm -q tk and press ENTER. If the tk file is already installed, the Terminal will display the filename and version number: tk-8.3.5-93, or whatever the version installed in your system happens to be. Note that you do not have to become root in order to use the rpm command in this case because you are not installing anything and, therefore, you do not need to write anything to disk in root territory.

    If your Terminal tells you that tk is already installed on your system, skip on down to section 9A-If the Terminal tells you, package tk is not installed, you have a little more work to do.

    If you are using Fedora Core, unmount the disk you have in your drive now, and insert Install Disk A small window should open, asking you if you want to run /mnt/cdrom/autorun. Just click No. Once the disk icon appears on your desktop, use the Terminal window to cd to the RPMS folder on that disk by typing cd /mnt/cdrom/Fedora/RPMS/ and pressing ENTER.

    If you are using Red Hat Linux 9, tk will be on Install Disk 3, so you do not have to change disks. Just follow the cd step above, substituting RedHat for Fedora.

  6. Now copy the tk RPM package to your expRPMS folder by typing the following command and pressing ENTER: cp tk* /home/username/expRPMS/

9A-3: Installing tkinter and Its Dependencies

  1. As tkinter and its dependencies are all RPM files, you could install them one by one, using the double-click method you learned in Chapter However, because I’ve just introduced the command-line way to do it, what fun would that be? You will also see that using the command-line alternative will allow you to install all four files simultaneously, killing, so to speak, four birds with one stone. This is a good example of how the command line can occasionally save you time.

So just suppress your natural inclinations for the time being and humor me by doing the following:

  1. Open a new Terminal window, and become root by typing su and pressing ENTER.

  2. Type your root password and press ENTER.

  3. Type cd expRPMS and press ENTER. This will take you to your new expRPMS folder.

    Caution 

    In the following step, you are going to use the wildcard character (*) to tell the rpm command to install everything that ends in .rpm into the expRPMS folder. Before you do so, make sure that the only files in your expRPMS folder are the three or four RPM files you are trying to install.

  4. Type rpm -Uvh *.rpm and press ENTER.

    The installation process will then begin, and you will see its progress in your Terminal window. When the progress bars in your Terminal have hit 100 percent and you are back at your root prompt, your Terminal should look like the one in Figure 9-9. If it does, then you’ve successfully installed tkinter and everything it needs to function properly.

    click to expand
    Figure 9-9: Installing RPMs with the rpm command

  5. Type exit and press ENTER to get out of root mode. You can also dump your expRPMS folder by dragging it to the Trash, by right-clicking it, and selecting Move to Trash, or via the command line by typing rmdir expRPMS and pressing ENTER.

9A-4: Creating a LocalApps Folder for pyWings

As I mentioned before, you will be installing the pyWings program locally in your Home folder. Installing a program locally means that you are installing the program and all its support and data files in your own Home folder. This makes things a bit easier, but it also means that the program will not be available to other users. It also means that, if you’re not careful, you might inadvertently delete it.

To make things a bit easier and safer for you in the future, you are going to create another folder in your Home folder in which to place pyWings and all other applications that you install locally on your machine in the future. You will, logically enough, call the folder LocalApps. Let’s make the folder by command in order to get some more practice. Here’s what to do:

In the Terminal, make sure you are in your Home directory and then type the following command and press ENTER: mkdir LocalApps

9A-5: Extracting the pyWings Tarball

Earlier you downloaded the pyWings tarball into the Tarballs_and_RPMs folder, and now it is time to extract the tarball. You can do this by using the command line, but that seems such a pain compared to the double-click method, which is so much more convenient and straightforward, so we will opt for the latter method instead.

  1. In your Tarballs_and_RPMs window, double-click pywings-1.0.1.tar.gz. This will bring up the File Roller program (shown in Figure 9-10), which is used to extract archived files (and to create archives as well).

    click to expand
    Figure 9-10: File Roller extracts and creates file archives

  2. Click the Extract button in the main File Roller window. This will bring up the File Roller Extract window (Figure 9-11).

    click to expand
    Figure 9-11: Using File Roller to extract files from a tarball

    The contents of most tarballs are grouped together in a single folder; however, in the case of pyWings, this is not the case, as you probably noticed in Figure 9-As a result, you will have to create a folder in which you can place all of the pyWings files.

  3. In the Destination folder text box in the File Roller Extract window (shown in Figure 9-11), change the default location to /home/your_username/LocalApps/

    pyWings/ (replacing your_username with your actual username, of course) and  then click OK.

  4. A small window will then pop open to tell you that the destination folder (pyWings) does not exist, and it will ask you if you want to create it. You do, so click Create Folder.

    If you take a look in your LocalApps folder now, you will see that you have a new subfolder inside called pyWings, and that all the pyWings files are in that folder.

  5. Now go ahead and close the File Roller window.

9A-6: Running pyWings

You have now done all you really have to do to use pyWings, so let’s start the great oracle up right now so that you can get a better perspective on how to deal with those problematic aspects of life that trouble you.

In the Terminal, make sure you are in your home directory and then type LocalApps/pyWings/pywings.py and press ENTER.

If all went according to plan, pyWings should be up and running and should soon be making you a wiser person.

9A-7: Creating a Launchable Link for pyWings

The method of running pyWings that you’ve just used works well enough, but it is a pain in the posterior to open your Terminal and type that somewhat lengthy string every time you want to find out what fate has in store for you. Let’s find a way to make things easier in the future.

To run an application from the Terminal, you generally type the name of that application, or, to put it more precisely, the name of that program’s executable file; the application’s name thus acts as a sort of command. In order for your system to recognize that command, however, the command (the executable file, or a link to it) must be in a location where the system can find it. Whenever you run a command of any sort, your system checks a series of locations (all of which are bin folders, where executable files are located) to find that command.

You can easily find out where these locations are by typing echo $PATH in a new Terminal window and then pressing ENTER. As you will see, on your Fedora or Red Hat Linux system, these locations are:

  • /usr/local/bin

  • /usr/bin

  • /bin

  • /usr/X11R6/bin

  • home/username/bin

(The last of these folders you create yourself if and when you need it.) If the command you typed is in one of those locations, the program, or script, will run. As you no doubt know, however, pyWings is not in any of those locations. It is in /home/username/LocalApps/pyWings and is thus, in a sense, out of your system’s sight.

To remedy this situation, you could add the path of your pyWings script to the list of paths that the system checks for run commands, so as to make the system aware of your new application’s existence. However, you will have the same problem later on in this book, and perhaps in your longer life as a Linux user. Instead, let’s try another method that I think is easier. What you will do is create a link, a sort of launchable alias, in one of the locations your system does check for commands.

To create this link, you will be using three commands: cd (to change directories), su (to become root), and ln -s (to create the link).

  1. In the Terminal, type cd /usr/local/bin and press ENTER. This puts you in one of the searchable bin folders.

  2. Type su and press ENTER. You will then be prompted for your root password, so type it and then press ENTER again.

  3. Type ln -s /home/username/LocalApps/pyWings/pywings.py pywings and press ENTER. (Note that there is a space between the words pywings.py and pywings at the end of that command string.) The pywings at the end of that command string is the name that you are giving the link; the name of the link thus becomes the command you will use to run the application. If you type nothing, the link will be called pywings.py, which would mean three more keystrokes for you every time you wanted to start the program.

9A-8: Running pyWings Again

Now that you have created the link, you should be able to run the pyWings program much more easily. Let’s try it out.

  1. Quit pyWings, if it is still running, and then open a new Terminal window.

  2. In the new Terminal window, type pywings and press ENTER. Your friendly pyWings oracle should now open again.

You’ve managed to cut down on the number of keystrokes required to run pyWings from the Terminal. However, if you are really into this pyWings thing and want to use it often, it will probably be handiest to add a launcher to your Panel or drawer, as you learned to do in Chapter 3. Point-and-click still beats the Terminal for most everyday chores. Check out Appendix A for the launcher specs.

9A-9: Adding Emblems to Your LocalApps Folder

Now that pyWings is successfully installed and working, it is probably a good idea to add an emblem to your new LocalApps folder so that you don’t inadvertently dump it in the trash someday. You have already learned how to do this in Chapter 5, so I won’t give you the step-by-step instructions. I will suggest, however, that you select the apps emblem.



 < Day Day Up > 



Linux for Non-Geeks. A Hands-On, Project-Based, Take-It-Slow Guidebook
Linux for Non-Geeks: A Hands-On, Project-Based, Take-It-Slow Guidebook
ISBN: 1593270348
EAN: 2147483647
Year: 2003
Pages: 188

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net