| next |
Copyright © 2005-06 Python Software Foundation
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
| top | next |
| prev | next |
for loops, if/then/else, …Python (version 2.3 or higher)Cygwin if you're on WindowsSubversionSoftware Carpentry for detailsPythonCode fragmentsCommands«Regular expressions»"Strings"<tags/> and attributesURLsProgram source
$ Shell commandstheir outputand error messages
Exercise 2.1:
What is the largest software project you have ever worked on? How well did it meet its original objectives? What is the most important thing you learned from it?
Exercise 2.2:
Write a point-form list of the programming tools you use on a regular basis. When and how did you learn each one? How proficient do you think you are with each? Compared to whom?
Exercise 2.3:
Suppose you have been given one week to write a program to translate old-style configuration files to a new syntax. Write a point-form description of how you would go about it.
Exercise 2.4:
Rewrite the following fragment of code to make it more readable. Don't worry about the fact that you don't know the language it's written in; feel free to use any functions or language features you're familiar with from other languages.
i = open('oldconfig.cnf', 'r');
ll = i.readlines();
for j in 0..len(ll) {
if len(j) > 0 {
if not defined(r) r = new list;
r.append(j);
}
}
sort(r);
print 'longest line is', r[0];
Exercise 2.5:
What are the errors in the function shown below? Don't worry about the lack of variable declarations: this language doesn't need them. Note that, like C and Java, this language uses 0 as the first index for lists.
# Calculate a running sum of a list of numbers.
# If the input values are [1, 2, 3], the final values are [1, 3, 6].
def running_sum(values) {
i = 1;
while (i < len(values)) {
values[i] = values[i] + values[i-1];
}
}Exercise 2.6:
A sub-contractor in Euphoristan has just written a function that takes two lists of phone numbers (represented as strings), and returns all those in the first list that are not in the second. You only have a few minutes to test it before she goes off-line for the weekend; what are the first half-dozen test cases you would try?
| prev | top | next |
| prev | next |
ls, cp, and wc do![[A Shell in Action]](./img/shell01/shell_screenshot.png)
Figure 3.1: A Shell in Action
sh, is an ancestor of many of thembash (the Bourne Again Shell) in this courseCygwin)![[Operating System]](./img/shell01/operating_system.png)
Figure 3.2: Operating System
notes.txt or home.html.txt is associated with an editor, and .html with a web browser![[A Directory Tree]](./img/shell01/directory_tree.png)
Figure 3.3: A Directory Tree
/C:\home\gvwilson\notes.txt is different from J:\home\gvwilson\notes.txtC:\home\gvwilson as c:/home/gvwilson/cygdrive/c/home/gvwilson":" a special meaning, so Cygwin needed a way to write paths without it…"/"/home/hpotter is Harry Potter's home directory/courses/swc/web/lec/shell.html is this file/courses/swc, the relative path to this file is web/lec/shell.html"." (pronounced “dot”) is the current directory".." (pronounced “dot dot”) is the directory one level up/courses/swc/data, .. is /courses/swc/courses/swc/data/elements, .. is /courses/swc/data![[Parent Directories]](./img/shell01/parent_directory.png)
Figure 3.4: Parent Directories
pwd (short for "print working directory”) to find out where you are$ pwd/home/hpotter/swc
ls (for “listing”) to see what's in the current directory$ lsLICENSE.txt conf data docs index.swc license.swc print.css swc.css testsMakefile config.mk depend.mk img lec press sites swc.dtd util
data directory, type ls data$ ls databio elements haiku.txt morse.txt pdb solarsystem.txt
cd data to “go into” datadatals on its owncd .. to go back to where you started$ cd data$ pwd/home/hpotter/swc/data$ lsbio elements haiku.txt morse.txt pdb solarsystem.txt$ cd ..$ pwd/home/hpotter/swc
ls, the OS:![[Running a Program]](./img/shell01/running_program.png)
Figure 3.5: Running a Program
ls produce more informative output by giving it some flags"-", as in "-c" or "-l"$ ls -FLICENSE.txt conf/ data/ docs/ index.swc license.swc print.css swc.css tests/Makefile config.mk depend.mk img/ lec/ press/ sites/ swc.dtd util/
.ls doesn't show things whose names begin with .. and .. don't always show up$ ls -a. .svn Makefile config.mk depend.mk img lec press sites swc.dtd util.. LICENSE.txt conf data docs index.swc license.swc print.css swc.css tests
.svn directory is for later$ ls -a -F. .svn/ Makefile config.mk depend.mk img/ lec/ press/ sites/ swc.dtd util/.. LICENSE.txt conf/ data/ docs/ index.swc license.swc print.css swc.css tests/
$ mkdir tmp
-v (“verbose”) would tell mkdir to print a confirmation message)$ cd tmp$ ls
earth.txt with the following contents:Name: Earth Period: 365.26 days Inclination: 0.00 Eccentricity: 0.02
venus.txt is to copy earth.txt and edit it$ cp earth.txt venus.txt$ edit venus.txt$ ls -tvenus.txt earth.txt
-t tells ls to list by modification time, instead of alphabeticallycat (short for “concatenate”)$ cat venus.txtName: VenusPeriod: 224.70 daysInclination: 3.39Eccentricity: 0.01
ls -l (“-l” meaning “long form”)$ ls -ltotal 2-rwxr-xr-x 1 gvwilson None 73 Jan 4 15:58 earth.txt-rwxr-xr-x 1 gvwilson None 73 Jan 4 15:58 venus.txt
wc (for “word count”)$ wc earth.txt venus.txt4 9 73 earth.txt4 9 73 venus.txt8 18 146 total
man | Documentation for commands. |
cat | Concatenate and display text files. |
cd | Change working directory. |
clear | Clear the screen. |
cp | Copy files and directories. |
date | Display the current date and time. |
diff | Show differences between two text files. |
echo | Print arguments. |
head | Display the first few lines of a file. |
ls | List files and directories. |
mkdir | Make directories. |
more | Page through a text file. |
mv | Move (rename) files and directories. |
od | Display the bytes in a file. |
passwd | Change your password. |
pwd | Print current working directory. |
rm | Remove files. |
rmdir | Remove directories. |
sort | Sort lines. |
tail | Display the last few lines of a file. |
uniq | Remove adjacent duplicate lines. |
wc | Count lines, words, and characters in a file. |
| Table 3.1: Basic Command-Line Tools | |
|---|---|
Exercise 3.1:
Suppose ls shows you this:
Makefile biography.txt data enrolment.txt programs thesis
What argument(s) will make it print the names in reverse, like this:
thesis programs enrolment.txt data biography.txt Makefile
Exercise 3.2:
What does the command cd ~ do? What about cd ~hpotter?
Exercise 3.3:
What command will show you the first 10 lines of a file? The first 25? The last 12?
Exercise 3.4:
What do the commands pushd, popd,
and dirs do? Where do their names come from?
Exercise 3.5:
How would you send the file earth.txt to the
default printer? How would you check it made it (other than
wandering over to the printer and standing there)?
Exercise 3.6:
The instructor wants you to use a hitherto unknown command for manipulating files. How would you get help on this command?
Exercise 3.7:
diff finds and displays the differences between
two text files. For example, if you modify earth.txt to
create a new file earth2.txt that contains:
Name: Earth Period: 365.26 days Inclination: 0.00 degrees Eccentricity: 0.02 Satellites: 1
you can then compare the two files like this:
$ diff earth.txt earth2.txt3c3< Inclination: 0.00---> Inclination: 0.00 degrees4a5> Satellites: 1
(The rather cryptic header "3c3" means that line 3 of
the first file must be changed to get line 3 of the second;
"4a5" means that a line is being added after line 4 of the
original file.)
What flag(s) should you give diff to tell it to
ignore changes that just insert or delete blank lines? What if
you want to ignore changes in case (i.e., treat lowercase and
uppercase letters as the same)?
| prev | top | next |
| prev | next |
stdin and stdout are$PATH is-rwxr-xr-x means* matches zero or more charactersls bio/*.txt lists all the text files in the bio directory$ ls bio/*.txtbio/albus.txt bio/ginny.txt bio/harry.txt bio/hermione.txt bio/ron.txt
? matches any single characterls jan-??.txt lists text files whose names start with “jan-” followed by two charactersls jan-??.* doesls can't tell whether it was invoked as ls *.txt or as ls earth.txt venus.txtta* does not find the tabulate commandcommand < input_file reads from input_file instead of from the keyboardcommand > output_file writes to output_file instead of to the screencommand < input_file > output_file does both![[Redirecting Standard Input and Output]](./img/shell02/redirection.png)
Figure 4.1: Redirecting Standard Input and Output
words.len:$ cd bio$ wc *.txt > words.len
words.lencat$ cat words.len7 66 468 albus.txt5 46 311 ginny.txt5 49 342 harry.txt5 49 331 hermione.txt6 54 364 ron.txt28 264 1816 total
cat > junk.txtcat reads from the keyboardrm junk.txt to get rid of the filerm * unless you're really, really sure that's what you want to do…sort words >wordssort then goes and reads the empty filewords are lostwc -w *.txt to count the words in some files, then sort -n to sort numerically$ wc -w *.txt > words.tmp$ sort -n words.tmp46 ginny.txt49 harry.txt49 hermione.txt54 ron.txt66 albus.txt264 total$ rm words.tmp
"|"$ wc -w *.txt | sort -n46 ginny.txt49 harry.txt49 hermione.txt54 ron.txt66 albus.txt264 total
![[Pipes]](./img/shell02/pipes.png)
Figure 4.2: Pipes
$ grep 'Title' spells.txt | sort | uniq -c | sort -n -r | head -10 > popular_spells.txt
set at the command prompt to get a listing:$ setBASH=/usr/bin/bashBASH_VERSION='2.05b.0(1)-release'COLUMNS=120HISTFILE=/home/.bash_historyHISTFILESIZE=500HISTSIZE=500HOME=/home/rweasleyHOSTNAME=hogwartsHOSTTYPE=i686LINES=60NUMBER_OF_PROCESSORS=1OSTYPE=cygwinPATH='/usr/local/bin:/usr/bin:/bin:/Python24:/home/rweasley/bin'PWD=/home/rweasleySHELL=/bin/bashUID=1003USER=rweasley
"$" in front of its namels $HOME is the same as ls /home/rweasley (if you're Ron Weasley)echo command to print out a variable's value$ echo $HOME/cygdrive/c/home/rweasley
echo $HOME, and not just $HOME?| Name | Typical Value | Notes |
|---|---|---|
COLUMNS | 80 | The width in characters of the current display window |
EDITOR | /bin/edit | Preferred editor |
HOME | /home/rweasley | The current user's home directory |
HOMEDRIVE | C: | The current user's home drive (Windows only) |
HOSTNAME | "ishad" | This computer's name |
HOSTTYPE | "i686" | What kind of computer this is |
LINES | 60 | The height in characters of the current display |
OS | "Windows_NT" | What operating system is running |
PATH | "/home/rweasley/bin:/usr/local/bin:/usr/bin:/bin:/Python24/" | Where to look for programs |
PWD | /home/rweasley/swc/lec | Present working directory (sometimes CWD, for current working directory) |
SHELL | /bin/bash | What shell is being run |
TEMP | /tmp | Where to store temporary files |
USER | "rweasley" | The current user's ID |
| Table 4.1: Important Environment Variables | ||
$ VILLAIN="Lord Voldemort"
$ VILLAIN="Lord Voldemort"$ bash$ echo $VILLAIN$ exit
![[Setting a Variable Without Export It]](./img/shell02/shell_no_export.png)
Figure 4.3: Setting a Variable Without Export It
$ VILLAIN="Lord Voldemort"$ export VILLAIN$ bash$ echo $VILLAINLord Voldemort$ exit
![[Exporting a Variable's Value]](./img/shell02/shell_with_export.png)
Figure 4.4: Exporting a Variable's Value
$ export VILLAIN="Lord Voldemort"$ bash$ echo $VILLAINLord Voldemort$ exit
~/.bashrc"~" is a shortcut meaning “your home directory”# Add personal tools directory to PATH. PATH=$HOME/bin:$PATH # Personal settings. export EDITOR=/local/bin/emacs export PRINTER=gryffindor-laserwriter # Change default behavior of commands. alias ls="ls -F"
.bashrc files can become very complex…ls won't show themPATH environment variables defines the shell's search pathbroom, the shell:$PATH into components to get a list of directoriesPATH is /home/rweasley/bin:/usr/local/bin:/usr/bin:/bin:/Python24/usr/local/bin/broom and /home/rweasley/bin/broom exist/home/rweasley/bin/broom will be run when you type broom at the command prompt/bin, /usr/bin: core tools like ls/usr/local/bin: optional (but common) tools, like the gcc C compiler$HOME/bin: tools you have built for yourself$HOME is your home directory. (the current working directory) in your pathwhatever, instead of ./whateverCygwin does things a little differently/cygdrive/c/somewhere instead of Windows' C:/somewhereC:/somewhere would clash with the colons in the PATH variableC:/cygwin as the root of its file system/home/rweasley is a synonym for C:/cygwin/home/rweasleygroups command will show you which ones you are inls -l shows this informationrwx triples"-"rw-rw-r-- means:tools has permission rwx--x--x, then:ls tools, permission is deniedtools/pfoldchmodchmod u+x broom allows broom's owner to run itchmod o-r notes.txt takes away the world's read permission for notes.txtnojunk#!/usr/bin/bash rm -f *.junk
man rm to find out what the “-f” flag does#!/usr/bin/bash means “run this using the Bash shell”#!rwxr-xr-x./nojunk$HOME/bin is in your search path, move it theretest/usr/bin/test./trychmod | Change file and directory permissions. |
du | Print the disk space used by files and directories. |
find | Find files with names that match patterns, that are of a certain age or size, etc. |
grep | Print lines matching a pattern. |
gunzip | Uncompress a file. |
gzip | Compress a file. |
lpr | Send a file to a printer. |
lprm | Remove a print job from a printer's queue. |
lpq | Check the status of a printer's queue. |
ps | Display running processes. |
tar | Archive files. |
which | Find the path to a program. |
who | See who is logged in. |
xargs | Execute a command for each line of input. |
| Table 4.2: Advanced Command-Line Tools | |
|---|---|
Exercise 4.1:
-rwxr-xr-x 1 aturing cambridge 69 Jul 12 09:17 mars.txt -rwxr-xr-x 1 ghopper usnavy 71 Jul 12 09:15 venus.txt
According to the listing of the data directory above,
who can read the file earth.txt? Who can write it (i.e.,
change its contents or delete it)? When was earth.txt
last changed? What command would you run to allow everyone to
edit or delete the file?
Exercise 4.2:
Suppose you want to remove all files whose names (not including
their extensions) are of length 3, start with the letter a, and
have .txt as extension. What command would you use? For
example, if the directory contains three files a.txt,
abc.txt, and abcd.txt, the command should remove
abc.txt , but not the other two files.
Exercise 4.3:
You're worried your data files can be read by your nemesis, Dr. Evil. How would you check whether or not he can, and if necessary change permissions so only you can read or write the files?
Exercise 4.4:
What's the difference between the commands cd HOME
and cd $HOME?
Exercise 4.5:
Suppose you want to list the names of all the text files in the
data directory that contain the word "carpentry". What
command or commands could you use?
Exercise 4.6:
Suppose you have written a program called analyze. What
command or commands could you use to display the first ten lines of
its output? What would you use to display lines 50-100? To send
lines 50-100 to a file called tmp.txt?
Exercise 4.7:
The command ls data > tmp.txt writes a listing of
the data directory's contents into tmp.txt. Anything
that was in the file before the command was run is overwritten. What
command could you use to append the listing to tmp.txt
instead?
Exercise 4.8:
What command(s) would you use to find out how many
subdirectories there are in the lectures directory?
Exercise 4.9:
What does rm *.ch? What about rm
*.[ch]?
Exercise 4.10:
What command(s) could you use to find out how many instances of
a program are running on your computer at once? For example, if you
are on Windows, what would you do to find out how many instances of
svchost.exe are running? On Unix, what would you do to
find out how many instances of bash are running?
Exercise 4.11:
A colleague asks for your data files. How would you archive them to send as one file? How could you compress them?
Exercise 4.12:
You have changed a text file on your home PC, and mailed it to the university terminal. What steps can you take to see what changes you may have made, compared with a master copy in your home directory?
Exercise 4.13:
How would you change your password?
Exercise 4.14:
grep is one of the more useful tools in the
toolbox. It finds lines in files that match a pattern and
prints them out. For example, assume the files
earth.txt and venus.txt contain lines like
this:
Name: Earth Period: 365.26 days Inclination: 0.00 Eccentricity: 0.02
grep can extract lines containing the text
"Period" from all the files:
$ grep Period *.txtearth.txt:Period: 365.26 daysvenus.txt:Period: 224.70 days
Search strings can use regular
expressions, which will be discussed in a Regular Expressions. grep takes many
options as well; for example, grep -c /bin/bash
/etc/passwd reports how many lines in /etc/passwd
(the Unix password file) that contain the string
/bin/bash, which in turn tells me how many users are
using bash as their shell.
Suppose all you wanted was a list of the files that
contained lines matching a pattern, rather than the matches
themselves—what flag or flags would you give to
grep? What if you wanted the line numbers of
matching lines?
Exercise 4.15:
Suppose you wanted ls to sort its output by
filename extension, i.e., to list all .cmd files before
all .exe files, and all .exe's before all
.txt files. What command or commands would you
use?
Exercise 4.16:
What does the alias command do? When would
you use it?
| prev | top | next |
| prev | next |
print statements![[Managing Multi-Author Collaboration]](./img/version/multi_author_collab.png)
Figure 5.1: Managing Multi-Author Collaboration
![[Version Control as a Time Machine]](./img/version/time_machine.png)
Figure 5.2: Version Control as a Time Machine
Perforce is excellentCVS and Subversion are:CVS has been around since the 1980sSubversion developed from 2000 onward as a workalike replacementsolarsystem project repositorysvn update to synchronize his working copy with the repositoryjupiter directory and creates moons.txtName Orbital Radius Orbital Period Mass Radius Io 421.6 1.769138 893.2 1821.6 Europa 670.9 3.551181 480.0 1560.8 Ganymede 1070.4 7.154553 1481.9 2631.2 Callisto 1882.7 16.689018 1075.9 2410.3
svn add moons.txt to bring it to Subversion's noticesvn commit to save his changes in the repositorysvn update on her working copySubversion sends her Ron's changes![[The Basic Edit/Update Cycle]](./img/version/edit_update_cycle.png)
Figure 5.3: The Basic Edit/Update Cycle
RapidSVN is a GUI that runs on Windows, Linux, and Mac![[RapidSVN]](./img/version/rapidsvn.png)
Figure 5.4: RapidSVN
TortoiseSVN is a Windows shell extension![[TortoiseSVN]](./img/version/tortoisesvn.png)
Figure 5.5: TortoiseSVN
Subversion) do thismoons.txt and commits his changes to create version 152Name Orbital Radius Orbital Period Mass Radius Io 421.6 1.769138 893.2 1821.6 Europa 670.9 3.551181 480.0 1560.8 Ganymede 1070.4 7.154553 1481.9 2631.2 Callisto 1882.7 16.689018 1075.9 2410.3 Amalthea 181.4 0.498179 0.075 131 x 73 x 67 Himalia 11460 250.5662 0.095 85 Elara 11740 259.6528 0.008 40
moons.txtName Orbital Radius Orbital Period Mass Radius
(10**3 km) (days) (10**20 kg) (km)
Io 421.6 1.769138 893.2 1821.6
Europa 670.9 3.551181 480.0 1560.8
Ganymede 1070.4 7.154553 1481.9 2631.2
Callisto 1882.7 16.689018 1075.9 2410.3
Amalthea 181.4 0.498179 0.075 131
Himalia 11460 250.5662 0.095 85
Elara 11740 259.6528 0.008 40
Pasiphae 23620 743.6 0.003 18
Sinope 23940 758.9 0.0008 14
Lysithea 11720 259.22 0.0008 12
Subversion tells her there's a conflict![[Merging Conflicts]](./img/version/conflict_merge.png)
Figure 5.6: Merging Conflicts
Subversion puts Hermione's changes and Ron's in moons.txtName Orbital Radius Orbital Period Mass Radius
(10**3 km) (days) (10**20 kg) (km)
Io 421.6 1.769138 893.2 1821.6
Europa 670.9 3.551181 480.0 1560.8
Ganymede 1070.4 7.154553 1481.9 2631.2
Callisto 1882.7 16.689018 1075.9 2410.3
<<<<<<< .mine
Amalthea 181.4 0.498179 0.075 131
Himalia 11460 250.5662 0.095 85
Elara 11740 259.6528 0.008 40
Pasiphae 23620 743.6 0.003 18
Sinope 23940 758.9 0.0008 14
Lysithea 11720 259.22 0.0008 12
=======
Amalthea 181.4 0.498179 0.075 131 x 73 x 67
Himalia 11460 250.5662 0.095 85
Elara 11740 259.6528 0.008 40
>>>>>>> .r152
<<<<<<< shows the start of the section from the first file======= divides sections>>>>>>> shows the end of the section from the second fileSubversion also creates:moons.txt.mine: contains Hermione's changesmoons.txt.151: the file before either set of changesmoons.txt.152: the most recent version of the file in the repositorysvn revert moons.txt to throw away her changesmoons.txtmoons.txt to remove the conflict markerssvn resolved moons.txt to let Subversion know she's donesvn commit to commit her changes (creating version 153 of the repository)svn diff shows him which files he has changed, and what those changes aresvn revert to discard his workmoons.txtsvn log shows recent historysvn merge -r 157:156 moons.txt will do the trick-r flag specifies the revisions involved![[Rolling Back]](./img/version/rollback.png)
Figure 5.7: Rolling Back
/svn/rotor)cd /svnsvnadmin create rotorsvn checkout file:///svn/rotorsvn checkout http://www.hogwarts.edu/svn/rotorsvn checkout once, to initialize your working copysvn update in that directorysvn co http://www.hogwarts.edu/svn/rotor/engine/dynamics| Name | Purpose | Example |
|---|---|---|
svn add | Add files and/or directories to version control. | svn add newfile.c newdir |
svn checkout | Get a fresh working copy of a repository. | svn checkout https://your.host.name/rotor/repo rotorproject |
svn commit | Send changes from working copy to repository (inverse of update). | svn commit -m "Comment on the changes" |
svn delete | Delete files and/or directories from version control. | svn delete oldfile.c |
svn help | Get help (in general, or for a particular command). | svn help update |
svn log | Show history of recent changes. | svn log --verbose *.c |
svn merge | Merge two different versions of a file into one. | svn merge -r 18:16 spin.c |
svn mkdir | Create a new directory and put it under version control. | svn mkdir newmodule |
svn rename | Rename a file or directory, keeping track of history. | svn rename temp.txt release_notes.txt |
svn revert | Undo changes to working copy (i.e., resynchronize with repository). | svn revert spin.h |
svn status | Show the status of files and directories in the working copy. | svn status |
svn update | Bring changes from repository into working copy (inverse of commit). | svn update |
| Table 5.1: Common Subversion Commands | ||
svn status compares your working copy with the repository$ svn statusM jupiter/moons.txtC readme.txt
jupiter/moons.txt has been modifiedreadme.txt has conflictssvn update prints one line for each file or directory it does something to$ svn updateA saturn/moons.txtU mars/mars.txt
saturn/moons.txt has been addedmars/mars.txt has been updated (i.e., someone else modified it)Exercise 5.1:
Follow the instructions given to you by your instructor to
check out a copy of the Subversion repository you'll be using in
this course. Unless otherwise noted, the exercises below
assume that you have done this, and that your working copy is in
a directory called course. You will submit all of your
exercises in this course by checking files into your
repository.
Exercise 5.2:
Create a file course/ex01/bio.txt (where
course is the root of your working copy of your
Subversion repository), and write a short biography of yourself
(100 words or so) of the kind used in academic journals,
conference proceedings, etc. Commit this file to your
repository. Remember to provide a meaningful comment when
committing the file!
Exercise 5.3:
What's the difference between mv and svn
mv? Put the answer in a file called
course/ex01/mv.txt and commit your changes.
Once you have committed your changes, type svn
log in your course directory. If you didn't know
what you'd just done, would you be able to figure it out from
the log messages? If not, why not?
Exercise 5.4:
In this exercise, you'll simulate the actions of two people editing a single file. To do that, you'll need to check out a second copy of your repository. One way to do this is to use a separate computer (e.g., your laptop, your home computer, or a machine in the lab). Another is to make a temporary directory, and check out a second copy of your repository there. Please make sure that the second copy isn't inside the first, or vice versa—Subversion will become very confused.
Let's call the two working copies Blue and Green. Do the following:
a) Create Blue/ex01/planets.txt, and add the
following lines:
Mercury Venus Earth Mars Jupiter Saturn
Commit the file.
b) Update the Green repository. (You should get a copy of
planets.txt.)
c) Change Blue/ex01/planets.txt so that it reads:
1. Mercury 2. Venus 3. Earth 4. Mars 5. Jupiter 6. Saturn
Commit the changes.
d) Edit Green/ex01/planets.txt so that its contents
are as shown below. Do not do svn update
before editing this file, as that will spoil the
exercise.
Mercury 0 Venus 0 Earth 1 Mars 2 Jupiter 16 (and counting) Saturn 14 (and counting)
e) Now, in Green, do svn update. Subversion
should tell you that there are conflicts in planets.txt.
Resolve the conflicts so that the file contains:
1. Mercury 0 2. Venus 0 3. Earth 1 4. Mars 2 5. Jupiter 16 6. Saturn 14
Commit the changes.
f) Update the Blue repository, and check that
planets.txt now has the same content as it has in the
Green repository.
Exercise 5.5:
Add another line or two to course/ex01/bio.txt and
commit those changes. Then, use svn merge to restore
the original contents of your biography
(course/ex01/bio.txt), and commit the result. When you
are done, bio.txt should look the way it did at the end
of the first part of the previous exercise.) Note: the purpose
of this exercise is to teach you how to go back in time to get
old versions of files—while it would be simpler in this
case just to edit bio.txt, you can't (reliably) do that
when you've made larger changes, to multiple files, over a
longer period of time.
Exercise 5.6:
Subversion allows users to set properties on files and
directories using svn propset, and to inspect their
values using svn propget. Describe three properties
you might want to change on a file or directory, and how you
might use them in your current project.
| prev | top | next |
| prev | next |
gcc -c -Wall -ansi -I/pkg/chempak/include dat2csv.c once is bad enoughMakeMake is freely available for every major platform, and very well documentedMake's syntaxTime: 1.2271 Concentration: 0.0050 Yield: 11.41 Time: 2.5094 Concentration: 0.0055 Yield: 11.20 Time: 3.7440 Concentration: 0.0060 Yield: 10.90
dat2csvhello.mk:hydroxyl_422.csv : hydroxyl_422.dat dat2csv hydroxyl_422.dat > hydroxyl_422.csv
make -f hello.mkmake -f hello.mk againhydroxyl_422.csv is newer than hydroxyl_422.dat, Make does not run the command again![[Structure of a Make Rule]](./img/build/rule_structure.png)
Figure 6.1: Structure of a Make Rule
hydroxyl_422.csv is the target of the rulehydroxyl_422.dat is its prerequisiteMake runs them on your behalf, just as the shell runs the command you typehydroxyl_422.csv : hydroxyl_422.dat dat2csv hydroxyl_422.dat > hydroxyl_422.csv methyl_422.csv : methyl_422.dat dat2csv methyl_422.dat > methyl_422.csv
make -f double.mk, only hydroxyl_422.csv is compiledMake will updatemake -f double.mk methyl_422.csv to build methyl_422.csvMake separately for each target would hardly count as “automation”all : hydroxyl_422.csv methyl_422.csv hydroxyl_422.csv : hydroxyl_422.dat dat2csv hydroxyl_422.dat > hydroxyl_422.csv methyl_422.csv : methyl_422.dat dat2csv methyl_422.dat > methyl_422.csv
make -f phony.mk all now creates both .csv filesall depends on hydroxyl_422.csv and methyl_422.csv.dat fileMake's built-in processing cycle:Make can execute actions in any order it wants to, as long as it doesn't violate dependency orderinghydroxyl_422.cv or methyl_422.csv firstallmake with no arguments, it automatically looks for a file called Makefilemake only updates the first one it finds"all": recompile everything"clean": delete all temporary files, and everything produced by compilation"install": copy files to system directoriesmake configuremakemake testmake installMake defines automatic variables to represent parts of rules"$@" | The rule's target |
"$<" | The rule's first prerequisite |
"$?" | All of the rule's out-of-date prerequisites |
"$^" | All prerequisites |
| Table 6.1: Automatic Variables in Make | |
|---|---|
all : hydroxyl_422.csv methyl_422.csv hydroxyl_422.csv : hydroxyl_422.dat @dat2csv $< > $@ methyl_422.csv : methyl_422.dat @dat2csv $< > $@ clean : @rm -f *.csv
Make echoes actions before executing them"@" at the start of the action line prevents thisclean to tidy up generated filesrm -f instead of just rm?all : hydroxyl_422.csv methyl_422.csv %.csv : %.dat @dat2csv $< > $@ clean : @rm -f *.csv <