Annotation of doc/techtips/worktime-new-1.html, revision 1.2

1.1       albertel    1: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                      2: <html>
                      3:   <head>
                      4:     <title>Worktime Install, Changes Intro, Handler Creation</title>
                      5:   </head>
                      6: 
                      7:   <body>
                      8:     <h1>Worktime Install, Changes Intro, Handler Creation</h1>
                      9: 
                     10:     <h2> Install </h2>
                     11:     <p>
                     12:       To familiarise you with the system, first we will update these
                     13:       systems from the current STABLE release to the latest release
                     14:     </p>
                     15:     <h3> CVS </h3>
                     16:     <p>
                     17:       First you will need to check out LON-CAPA from CVS
                     18:     </p>
                     19:     <p>
                     20:       Login
                     21:     </p>
                     22:     <p>
                     23:       <tt>cvs -d :pserver:username@zaphod.lite.msu.edu:/home/cvs login</tt>
                     24:     </p>
                     25:     <p> Checkout the LON-CAPA source code </p>
                     26:     <p>
                     27:       <tt>cvs -d :pserver:username@zaphod.lite.msu.edu:/home/cvs checkout LON-CAPA</tt>   
                     28:     </p>
                     29: 
                     30:     <p> Add you current hosts.tab file to the CVS checkout </p>
                     31:     <p><tt>cp /home/httpd/lonTabs/hosts.tab ~/loncapa/loncom/hosts.tab</tt></p>
                     32: 
                     33:     <p> Build and Install the newest version of LON-CAPA </p>
                     34:     <p><tt>cd ~/loncapa/loncom/build</tt></p>
                     35:     <p><tt>su</tt></p>
                     36:     <p><tt>make build</tt></p>
                     37:     <p><tt>make install</tt></p>
                     38: 
                     39:     <p> Restart the necessary services</p>
                     40:     <p><tt>/etc/init.d/httpd restart</tt></p>
                     41:     <p><tt>/etc/init.d/loncontrol restart</tt></p>
                     42: 
                     43: 
                     44:     <hr />
                     45: 
                     46:     <h2>Using CVS</h2>
                     47:     
                     48:     <p> CVS is a code versioning system, that tracks changes in code
                     49:       and supports multiple features to make multiple developers able
                     50:       to coexist with the same central repository of code. It has many
                     51:       options and commands. I highly suggest reading the CVS man page
                     52:       <tt>man cvs</tt> at some time.
                     53:     </p>
                     54: 
                     55:     <p> The most useful commands you will have access to are</p>
                     56:     <ul>
                     57:       <li>
                     58: 	<tt>annotate</tt> this will number the code lines and also
                     59: 	print out who, when, and in what version a line was last
                     60: 	modified, this can be useful for tracking down when a change
                     61: 	was made, and discovering the reason behind it.
                     62:       </li>
                     63:       <li>
                     64: 	<tt>diff</tt> produces a diff between specified versions of
                     65: 	the code, if given no options if will inform you of the
                     66: 	differences between the current local file and the version
                     67: 	that was checked out. It also accepts all of the options that
                     68: 	the normal diff command accepts. I highly suggest using the -u
                     69: 	option (unified diffs).
                     70:       </li>
                     71:       <li>
                     72: 	<tt>log</tt> shows the log messages for a files or files,
                     73: 	those messages should provide a description of what the
                     74: 	changes in the code at least hoped to accomplish.
                     75:       </li>
                     76:       <li>
                     77: 	<tt>update</tt> will modify your local files to be 'updated'
                     78: 	to a specific repository version, by default it will update it
                     79: 	to the latest version of the code. You can also uses this
                     80: 	command to select a specific version and prevent cvs from
                     81: 	updating it. This happens by specifying a specific revision, tag
                     82: 	or date when running update. You can remove this 'stickiness'
                     83: 	with the use of the -A option. Also update by default won't
                     84: 	create any new directories that have been added by default, if
                     85: 	you want it to add directories use the -d option.
                     86:       </li> 
                     87:     </ul>
                     88:     <p>Common options to cvs commands</p>
                     89:     <ul>
                     90:       <li>
                     91: 	<tt>-r</tt> specify a specific file revision, (like -r 1.43)
                     92: 	or a specific tag (like -r STABLE)
                     93:       </li>
                     94:       <li>
                     95: 	<tt>-D</tt> specify a specific revision date, is accepts
                     96: 	absolute dates 
                     97: 	(ex. 'Nov 30 23:30 2001') or relative dates
                     98:         (ex. 'last week' or 'today')
                     99:       </li>
                    100:     </ul>
                    101: 
                    102:     <p>
                    103:       Some commands to try (in the loncom directory)
                    104:     </p>
                    105:     <pre>
                    106: cvs diff -u -r 1.40 -r 1.43 lond | less
                    107: cvs diff -u -r STABLE -r HEAD loncron | less
                    108: cvs log loncron | less
                    109: cvs update -r STABLE loncron
                    110: cvs update -D 'last week'
                    111: cvs update -A loncron
                    112: cvs annotate loncron | less
                    113:     </pre>
                    114: 
                    115:     <h3>Changing Code and detecting errors</h3>
                    116:     <p>
                    117:       We will change the lonhomework handler to act differently, and
                    118:       we will cause it to throw errors
                    119:     </p>
                    120:     
                    121:     <ul>
                    122:       <li>
                    123: 	Bring up loncapa/loncom/homework/lonhomework.html in a text
                    124: 	editor, and introduce a syntax error. (For example delete a ;
                    125: 	somewhere). Then save this version.
                    126:       </li>
                    127:       <li>
                    128: 	Open up a terminal and su to root. In this new window copy the
                    129: 	new version of lonhomework.html to the directory
                    130: 	<tt>/home/httpd/lib/perl/Apache</tt>. Then restart the webserver with
                    131:   <tt>/etc/init.d/httpd restart</tt>
                    132:   
                    133: </li>
                    134:   <li>
                    135:       Note the error message you have just received.
                    136:   </li>
                    137:   <li>
                    138:     Use the command <tt>cvs diff -u lonhomework.pm</tt> to see what
                    139:     you changed.
                    140:   </li>
                    141:   <li>
                    142:     Fix the previous error, and then in the subroutine <tt>handler</tt> add a
                    143:     call to a function that doesn't exist. (Example, on line 438 on
                    144:     lonhomework.html, add the line
                    145:     <pre>
                    146: &amp;idontexist();
                    147:     </pre>
                    148:   </li>
                    149:   <li>
                    150:     Repeat the copy, and httpd restart that you did before. And then
                    151:     go a visit a homework problem.
                    152:   </li>
                    153:   <li>
                    154:     You can find a perl error report in the file
                    155:     /var/log/httpd/error_log You can use the tail command to quickly
                    156:     see the end of a file.
                    157:   </li>
                    158: </ul>
                    159: 
                    160:     <h2>Making a new Handler</h2>
                    161:     <p>
                    162:       In the examples below <i>italicised</i> lines are lines of code
                    163:       that changed from the previous example, <b>bold</b> lines are
                    164:       lines that have been added to the example, and any time
                    165:       "username" appears it should be replaced by your specific
                    166:       username.
                    167:     </p>
                    168:     <h3>Example 1</h3>
                    169:     <pre>
                    170: package Apache::workshop;
                    171: use strict;
                    172: use Apache::Constants qw(:common :http);
                    173: sub handler {
                    174: 	my $r=@_[0];
                    175: 	$r->content_type('text/html');
                    176: 	$r->send_http_header;
                    177: 	return OK if $r->header_only;
                    178: 	$r->print("The workshop handler");
                    179: 	return OK;
                    180: }
                    181: 1;
                    182: __END__
                    183:     </pre>
                    184:     <h3>Example 2</h3>
                    185:     <pre>
                    186: &lt;Location /adm/workshop&gt;
                    187: PerlAccessHandler       Apache::lonacc
                    188: SetHandler perl-script
                    189: PerlHandler Apache::workshop
                    190: ErrorDocument     403 /adm/login
                    191: ErrorDocument     500 /adm/errorhandler
                    192: &lt;/Location&gt;
                    193: 
                    194: &lt;LocationMatch "^/(res|\~).*\.workshop$"&gt;
                    195: SetHandler perl-script
                    196: PerlHandler Apache::workshop
                    197: &lt;/LocationMatch&gt;
                    198:     </pre>
                    199:     <h3>Example 3</h3>
                    200:     <pre>
                    201: package Apache::workshop;
                    202: use strict;
                    203: use Apache::Constants qw(:common :http);
                    204: sub handler {
                    205: 	my $r=@_[0];
                    206: 	$r->content_type('text/html');
                    207: 	$r->send_http_header;
                    208: 	return OK if $r->header_only;
1.2     ! albertel  209: 	<i>$r->print("The workshop handler is in use by $env{'user.name'}");</i>
1.1       albertel  210: 	return OK;
                    211: }
                    212: 1;
                    213: __END__
                    214:     </pre>
                    215:     <h3>Example 4</h3>
                    216:     <pre>
                    217: package Apache::workshop;
                    218: use strict;
                    219: use Apache::Constants qw(:common :http);
                    220: <b>use Apache::lonnet;</b>
                    221: sub handler {
                    222: 	my $r=@_[0];
                    223: 	$r->content_type('text/html');
                    224: 	$r->send_http_header;
                    225: 	return OK if $r->header_only;
1.2     ! albertel  226: 	<i>$r->print("The workshop handler is in use by $env{'user.name'} looking for "
1.1       albertel  227:                      .$r->uri."&lt;br&gt;");</i>
                    228: 	<b>my $file=&amp;Apache::lonnet::filelocation("",$r->uri);</b>
                    229: 	<b>my $contents=&amp;Apache::lonnet::getfile($file);</b>
                    230: 	<b>$r->print($contents);</b>
                    231: 	return OK;
                    232: }
                    233: 1;
                    234: __END__
                    235:     </pre>
                    236:     <h3>Example 5</h3>
                    237:     <pre>
                    238: package Apache::workshop;
                    239: use strict;
                    240: use Apache::Constants qw(:common :http);
                    241: use Apache::lonnet;
                    242: sub handler {
                    243: 	my $r=@_[0];
                    244: 	$r->content_type('text/html');
                    245: 	$r->send_http_header;
                    246: 	return OK if $r->header_only;
1.2     ! albertel  247: 	$r->print("The workshop handler is in use by $env{'user.name'} looking for "
1.1       albertel  248:                    .$r->uri."&lt;br&gt;");
                    249: 	my $file=&amp;Apache::lonnet::filelocation("",$r->uri);
                    250: 	my $contents=&amp;Apache::lonnet::getfile($file);
                    251: 	<b>$contents=~s/simple/complex/g;</b>
                    252: 	$r->print($contents);
                    253: 	return OK;
                    254: }
                    255: 1;
                    256: __END__
                    257:     </pre>
                    258:     <h3>Example 6</h3>
                    259:     <pre>
                    260: package Apache::workshop;
                    261: use strict;
                    262: use Apache::Constants qw(:common :http);
                    263: use Apache::lonnet;
                    264: sub handler {
                    265:         my $r=@_[0];
                    266:         $r->content_type('text/html');
                    267:         $r->send_http_header;
                    268:         return OK if $r->header_only;
1.2     ! albertel  269:         $r->print("The workshop handler is in use by $env{'user.name'} looking for "
1.1       albertel  270:                    .$r->uri."&lt;br&gt;");
                    271:         my $file=&amp;amp;Apache::lonnet::filelocation("",$r->uri);
                    272:         my $contents=&amp;amp;Apache::lonnet::getfile($file);
                    273:         $contents=~s/simple/complex/g;
                    274:         $r->print($contents);
                    275:         <b>my %hash=&amp;Apache::lonnet::get('workshop',['info']);
                    276:         #handle any errors
                    277:         if ($hash{'info'} =~ m/^error:.*/) {
                    278:                 $r->print("&lt;br&gt;An error -$hash{'info'}- occured");
                    279:         } else {
                    280:                 $r->print("&lt;br&gt;Last time you said $hash{'info'}");
                    281:         }
1.2     ! albertel  282:         if ($env{'form.info'}) {
        !           283:                 $r->print("&lt;br&gt;Now you say $env{'form.info'}");
        !           284:                 $hash{'info'}=$env{'form.info'};
1.1       albertel  285:                 &amp;Apache::lonnet::put('workshop',\%hash);
                    286:         }</b>
                    287:         return OK;
                    288: }
                    289: 1;
                    290: __END__
                    291:     </pre>
                    292:     <h3>Example 7</h3>
                    293:     <pre>
                    294: &lt;html&gt;
                    295: 	&lt;head&gt;&lt;title&gt; A simple file &lt;/title&gt;&lt;/head&gt;
                    296: 	&lt;body&gt;
                    297: 		This is a simple file
                    298: 	&lt;/body&gt;
                    299: &lt;/html&gt;
                    300:     </pre>
                    301:     <h3>Example 8</h3>
                    302:     <pre>
                    303: &lt;html&gt;
                    304: 	&lt;head&gt;&lt;title&gt; A simple file &lt;/title&gt;&lt;/head&gt;
                    305: 	&lt;body&gt;
                    306: 		This is a simple file
                    307: 	        <b>&lt;form method="POST" action="/~domcc/a.workshop"&gt;
                    308: 		       &lt;input type="text" name="info"&gt;&lt;/input&gt;
                    309: 		       &lt;input type="submit" name="Submit"&gt;&lt;/input&gt;
                    310:                 &lt;/form&gt;</b>
                    311: 	&lt;/body&gt;
                    312: &lt;/html&gt;
                    313: 
                    314:     </pre>
                    315:     <ol>
                    316:     <li>
                    317:      You will need to add the author role to the domcc user, use the
                    318:      CUSR button on the remote, type in the username 'domcc' and then
                    319:      add the author role. Logout, and log back in. (You will also need
                    320:      to let the webserver have permission to enter domcc's home
                    321:      directory, do this by having domcc do<tt>chmod a+x
                    322:      /home/domcc</tt>
                    323:     </li>
                    324:     <li> 
                    325:       Create the file loncapa/loncom/workshop.pm using your
                    326:       favourite unix text editor and type in example 1
                    327:     </li>
                    328:     <li>
                    329:       Add example 2 to the file /etc/httpd/conf/loncapa_apache.conf
                    330:     </li>
                    331:     <li>
                    332:       Copy the workshop.pm file to /home/httpd/lib/perl/Apache, and
                    333:       restart the webserver. You will need to do this after every
                    334:       change of the workshop.pm file.
                    335:     </li>
                    336:       <li>
                    337: 	Point netscape at "http://cc313-pc-XX.cl.msu.edu/adm/workshop". You
                    338: 	should see the simple message the handler prints out.
                    339:       </li>
                    340:       <li>
                    341: 	Change workshop.pm to be what is in Example 3, the
                    342: 	italicised line is the only one that changed.
                    343:       </li>
                    344:       <li>
                    345: 	In netscape reload
                    346: 	"http://cc313-pc-XX.cl.msu.edu/adm/workshop". You should see the
                    347: 	output of the handler should now have your lon-capa name, which it
                    348: 	got from the session environment.
                    349:       </li>
                    350:       <li>
                    351: 	Next in netscape goto
                    352: 	"http://cc313-pc-XX.cl.msu.edu/~domcc/a.workshop". You should
                    353: 	see the same output as before.
                    354:       </li>
                    355:       <li>
                    356: 	Using the terminal edit the file ~/public_html/a.workshop and
                    357: 	put in it Example 7 using your favourite unix text editor.
                    358:       </li>
                    359:       <li>
                    360: 	Change ~/workshop.pm to be what is in Example 4, the
                    361: 	italicised lines are changed and the bold lines should be
                    362: 	added.
                    363:       </li>
                    364:       <li>
                    365: 	In netscape reload
                    366: 	"http://cc313-pc-XX.cl.msu.edu/~domcc/a.workshop". You should
                    367: 	see the output of the handler contains the contents of the file
                    368: 	that you created along with the name of the file.
                    369:       </li>
                    370:       <li>
                    371: 	Change ~/workshop.pm to be what is in Example 5, the
                    372: 	bold line should be added.
                    373:       </li>
                    374:       <li>
                    375: 	In netscape reload
                    376: 	"http://cc313-pc-XX.cl.msu.edu/~domcc/a.workshop". You should
                    377: 	see the output of the handler contains the contents of the
                    378: 	file that you created along with the name of the file, except
                    379: 	that this time all instances of the word "simple" have been
                    380: 	replaced with the word "complex", this includes the one in the
                    381: 	title and the one in the body of the file.
                    382:       </li>
                    383:       <li>
                    384: 	<ol>
                    385: 	  <li>
                    386: 	    Change what is in ~/workshop.pm to be what is in Example
                    387: 	    6. The bold section of code needs to be added.
                    388: 	  </li>
                    389: 	  <li>
                    390: 	    Change what is in ~/public_html/a.workshop to be what is
                    391: 	    in Example 8. The bold section needs to be added
                    392: 	  </li>
                    393: 	  <li>
                    394: 	    In netscape reload
                    395: 	    "http://cc313-pc-XX.cl.msu.edu/~domcc/a.workshop". The web
                    396: 	    page should now contain a form, and say that an error
                    397: 	    occurred.
                    398: 	  </li>
                    399: 	  <li>
                    400: 	    Type something into the form field and click the submit button.
                    401: 	  </li>
                    402: 	  <li>
                    403: 	    The handler should still report an error, but also echo
                    404: 	    back what you typed into the error handler.
                    405: 	  </li>
                    406: 	  <li>
                    407: 	    Type in the terminal
                    408: 	    <pre>
                    409: ls -l /home/httpd/lonUsers/pcXX/d/o/m/domcc
                    410: 	    </pre>
                    411: 	    Notice that there is a workshop.db file and a
                    412: 	    workshop.hist file.
                    413: 	  </li>
                    414: 	  <li>
                    415: 	    Type in the terminal
                    416: 	    <pre>
                    417: cat /home/httpd/lonUsers/pcXX/d/o/m/workshop.hist
                    418: 	    </pre>
                    419: 	    You should see the information that you submitted.
                    420: 	  </li>
                    421: 	  <li>
                    422: 	    In netscape revisit
                    423: 	    "http://cc313-pc-XX.cl.msu.edu/~domcc/a.workshop". (Do
                    424: 	    this by hitting return in the URL field of netscape, Don't
                    425: 	    use the reload button.) Notice that the handler no longer
                    426: 	    has an error. Also notice that the handler tells you what
                    427: 	    you said last time.
                    428: 	  </li>
                    429: 	  <li>
                    430: 	    Type something new into the text field and hit submit. The
                    431: 	    handler should tell you the first submission and the last
                    432: 	    submission.
                    433: 	  </li>
                    434: 	</ol>
                    435:       </li>
                    436: <!--
                    437:       <li>
                    438: 	Extra credit: convert Example 5 to use store/restore instead
                    439: 	of the get/put. You will need to publish a .workshop file and
                    440: 	include it into a map. (Note that violin.sequence is the
                    441: 	toplevel map for you course.
                    442:       </li>
                    443:       <li>
                    444: 	Extra credit: Use Apache::lonxml::xmlparse to properly process the html file.
                    445: 	Use &lt;window&gt;&lt;/window&gt; in your example .workshop file.
                    446:       </li>
                    447: -->
                    448:     </ol>
                    449:     <h2>Helpful Notes</h2>
                    450:     <ul>
                    451:       <li>
                    452: 	Remember that Apache::lonnet::put and Apache::lonnet::get
                    453: 	store data that is user wide. I use them for simplicity sake
                    454: 	here. Every .workshop file will read and write to the same
                    455: 	data location in the last example. Use store/restore if you
                    456: 	want to have data stored per unique resource instance in a
                    457: 	specific course. However this means that store/restore will
                    458: 	throw errors if you attempt to use them in a context in which
                    459: 	a resource isn't published or isn't uniquely identified
                    460: 	(i.e. browsing resources.)
                    461:       </li>
                    462:     </ul>
                    463:     <hr />
                    464:     <address><a href="mailto:albertel@msu.edu">Guy Albertelli</a></address>
                    465: <!-- Created: Wed May 23 02:34:54 EDT 2001 -->
                    466: <!-- hhmts start -->
                    467: Last modified: Tue Jun 11 14:18:30 EDT 2002
                    468: <!-- hhmts end -->
                    469:   </body>
                    470: </html>

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>
500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.