Write a GUI for Exercise 3.14. The purpose of this exercise is to write a clean-up script of the…

Write a GUI for Exercise 3.14.

The purpose of this exercise is to write a clean-up script
of the type described in Exercise 3.14 (page 126), but now with a graphical
user interface. The GUI should be realized as a class, which we call
cleanfilesGUI.

The directory tree to be searched is given through a text
entry in the GUI. (Note that in a path specification like ~user/src, the tilde
is not expanded to a full path unless you call the os.path.expanduser function
in the Python code.) The wildcard notation of target names of files to be
removed, as defined by default in the script or in the .
»

Write a GUI for Exercise 3.14.

The purpose of this exercise is to write a clean-up script
of the type described in Exercise 3.14 (page 126), but now with a graphical
user interface. The GUI should be realized as a class, which we call
cleanfilesGUI.

The directory tree to be searched is given through a text
entry in the GUI. (Note that in a path specification like ~user/src, the tilde
is not expanded to a full path unless you call the os.path.expanduser function
in the Python code.) The wildcard notation of target names of files to be
removed, as defined by default in the script or in the .cleanrc file in the
user’s home directory, can be listed in a row of check buttons. All of the
check buttons can be on by default.

Three buttons should also be present: Show files for listing
all candidate files for removal in a scrollable list box widget, Remove for
physically removing these files, and Quit for terminating the program. Each
line in the list box should contain the filename, the size in megabytes, and
the age in months, written in a nicely formatted way. The information in the
list is easily obtained by using the add_file function (and find) from the
cleanfiles module developed in Exercise 3.14. Clicking on one or more list
items marks that the associated files should not be removed. All key widgets
should be equipped with balloon help.

To reuse this script in Exercise 11.10, one can create a
separate function for setting up the scrollable list box widget, and let the
function called when pressing Show files first create a list of the file data
and then send the list to the list box widget. Each list item should be a
two-tuple consisting of the filename and a help text with size and age.

Exercise 3.14

Remove redundant files in a directory tree.

Make a script cleanfiles.py that takes a root of a directory
tree as argument, traverses this directory tree, and for each file removes the
file if the name is among a prescribed set of target names. Target names can be
specified in Unix shell-style wildcard notation, for example,

*tmp* .*tmp* *.log *.aux *.idx *~ core a.out *.blg

If the user has a file called .cleanrc in the home
directory, assume that this file contains a list of target names, separated by
whitespace. Use a default set of target names in the case the user does not
have a .cleanrc file.

With the option –fake, the script should just write the
name of the file to be removed to the screen but not perform the physical
removal. The options –size X and –age Y cause the script to also write out a
list of files that are larger than X Mb or older than Y weeks. The user can
examine this list for later removal.

The script file should act both as a module and as an
executable script (read about modules in Appendix B.1.1). For traversing the
directory tree, use the find function from page 124, available in the
scitools.misc module. Make a function add_file for processing each file found
by find:

def add_file(fullpath, arg): “””

Add the given fullpath, to arg[’rm_files’] if fullpath

matches one of the names in the arg[’targetnames’] list.

The specification of names in targetnames follow the Unix

shell-style wildcard notation (an example may be

arg[’targetnames’]=[’tmp*’, ’*.log’, ’fig*.*ps’]).

arg[’rm_files’] contains pairs (fullpath, info), where

info is a string containing the file’s size (in Mb)

and the age (in weeks). In addition, add fullpath to

the arg[’old_or_large_files’] list if the size of the file

is larger than arg[’max_size’] (measured in Mb) or older

than arg[’max_age’] (measured in weeks).

“””

Make another function cleanfiles, employing find and
add_date, for printing the removed files and the old or large candidate files.

Hints: Exercises 3.12 and 3.13 might be a useful starting
point. Use the fnmatch module to handle Unix shell-style wildcard notation. It
is advantageous to store files for removal in a list and the large and/or old
files in another list. When the traversal of the directory tree has terminated,
files can be physically removed and lists can be printed. To test the script,
generate a directory tree using the fakefiletree.py utility mentioned in
Exercise 3.13 and comment out the os.remove call.

Exercises B.4–B.11 (starting on page 734) equip the useful
cleanfiles.py script with good software engineering habits: user documentation,
automatic verification, and a well-organized directory structure packed in a
single file.

Exercise 11.10

Extend the GUI in Exercise 6.17 with a fancy list. Class
cleanfilesGUI from Exercise 6.17 applies a scrolled list box widget for holding
the filenames and the associated data (age and size). The list could be easier
to read if it contained just the filenames. When pointing with the mouse at an
item in the list, the associated age and size data can appear in a label below
the list. Implement this functionality using constructions from the
src/py/gui/fancylist3.py script. Let the name of the improved version of class
cleanfilesGUI be cleanfilesGUI_fancy.

The cleanfilesGUI_fancy class can be realized by just a few
lines code provided class cleanfilesGUI has been implemented according to the
suggestions given at the end of Exercise 6.17. To reuse class cleanfilesGUI as
much as possible, we let cleanfilesGUI_fancy be a subclass of cleanfilesGUI. We
can then just redefine the function for creating the list widget and the
statements for filling the list widget with data. Put emphasis on maximizing
the reuse of class cleanfilesGUI in the extended class cleanfilesGUI_fancy

Exercises 3.12

Remove temporary files in a directory tree.

Computer work often involves a lot of temporary files, i.e.,
files that you need for a while, but that can be cleaned up after some days. If
you let the name of all such temporary files contain the stem tmp, you can now
and then run a clean-up script that removes the files. Write a script that
takes the name of a directory tree as command-line argument and then removes
all files (in this tree) whose names contain the string tmp.

Hint: Use os.path.walk to traverse the directory tree (see
Chapter 3.4.7) and look up Chapter 3.2.8 to see how one can test if a string
contains the substring tmp. Avoid giving the script a name containing tmp as
the script may then remove itself! Also remember to test the script thoroughly,
with the physical removal statement replaced by some output message, before you
try it on a directory tree.

»

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
The price is based on these factors:
Academic level
Number of pages
Urgency
Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.

Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism guarantee

Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

Read more

Free-revision policy

Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.

Read more

Privacy policy

Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.

Read more

Fair-cooperation guarantee

By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.

Read more