File:  [LON-CAPA] / doc / techtips / worktime-new-1.html
Revision 1.2: download - view: text, annotated - select for diffs
Thu Apr 7 06:56:20 2005 UTC (18 years, 11 months ago) by albertel
Branches: MAIN
CVS tags: version_2_9_X, version_2_9_99_0, version_2_9_1, version_2_9_0, version_2_8_X, version_2_8_99_1, version_2_8_99_0, version_2_8_2, version_2_8_1, version_2_8_0, version_2_7_X, version_2_7_99_1, version_2_7_99_0, version_2_7_1, version_2_7_0, version_2_6_X, version_2_6_99_1, version_2_6_99_0, version_2_6_3, version_2_6_2, version_2_6_1, version_2_6_0, version_2_5_X, version_2_5_99_1, version_2_5_99_0, version_2_5_2, version_2_5_1, version_2_5_0, version_2_4_X, version_2_4_99_0, version_2_4_2, version_2_4_1, version_2_4_0, version_2_3_X, version_2_3_99_0, version_2_3_2, version_2_3_1, version_2_3_0, version_2_2_X, version_2_2_99_1, version_2_2_99_0, version_2_2_2, version_2_2_1, version_2_2_0, version_2_1_X, version_2_1_99_3, version_2_1_99_2, version_2_1_99_1, version_2_1_99_0, version_2_1_3, version_2_1_2, version_2_1_1, version_2_1_0, version_2_12_X, version_2_11_X, version_2_11_4_uiuc, version_2_11_4_msu, version_2_11_4, version_2_11_3_uiuc, version_2_11_3_msu, version_2_11_3, version_2_11_2_uiuc, version_2_11_2_msu, version_2_11_2_educog, version_2_11_2, version_2_11_1, version_2_11_0_RC3, version_2_11_0_RC2, version_2_11_0_RC1, version_2_11_0, version_2_10_X, version_2_10_1, version_2_10_0_RC2, version_2_10_0_RC1, version_2_10_0, version_2_0_X, version_2_0_99_1, version_2_0_2, version_2_0_1, version_2_0_0, version_1_99_3, version_1_99_2, version_1_99_1_tmcc, version_1_99_1, version_1_99_0_tmcc, version_1_99_0, loncapaMITrelate_1, language_hyphenation_merge, language_hyphenation, bz6209-base, bz6209, HEAD, GCI_3, GCI_2, GCI_1, BZ4492-merge, BZ4492-feature_horizontal_radioresponse, BZ4492-feature_Support_horizontal_radioresponse, BZ4492-Support_horizontal_radioresponse
- ENV -> env

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>Worktime Install, Changes Intro, Handler Creation</title>
  </head>

  <body>
    <h1>Worktime Install, Changes Intro, Handler Creation</h1>

    <h2> Install </h2>
    <p>
      To familiarise you with the system, first we will update these
      systems from the current STABLE release to the latest release
    </p>
    <h3> CVS </h3>
    <p>
      First you will need to check out LON-CAPA from CVS
    </p>
    <p>
      Login
    </p>
    <p>
      <tt>cvs -d :pserver:username@zaphod.lite.msu.edu:/home/cvs login</tt>
    </p>
    <p> Checkout the LON-CAPA source code </p>
    <p>
      <tt>cvs -d :pserver:username@zaphod.lite.msu.edu:/home/cvs checkout LON-CAPA</tt>   
    </p>

    <p> Add you current hosts.tab file to the CVS checkout </p>
    <p><tt>cp /home/httpd/lonTabs/hosts.tab ~/loncapa/loncom/hosts.tab</tt></p>

    <p> Build and Install the newest version of LON-CAPA </p>
    <p><tt>cd ~/loncapa/loncom/build</tt></p>
    <p><tt>su</tt></p>
    <p><tt>make build</tt></p>
    <p><tt>make install</tt></p>

    <p> Restart the necessary services</p>
    <p><tt>/etc/init.d/httpd restart</tt></p>
    <p><tt>/etc/init.d/loncontrol restart</tt></p>


    <hr />

    <h2>Using CVS</h2>
    
    <p> CVS is a code versioning system, that tracks changes in code
      and supports multiple features to make multiple developers able
      to coexist with the same central repository of code. It has many
      options and commands. I highly suggest reading the CVS man page
      <tt>man cvs</tt> at some time.
    </p>

    <p> The most useful commands you will have access to are</p>
    <ul>
      <li>
	<tt>annotate</tt> this will number the code lines and also
	print out who, when, and in what version a line was last
	modified, this can be useful for tracking down when a change
	was made, and discovering the reason behind it.
      </li>
      <li>
	<tt>diff</tt> produces a diff between specified versions of
	the code, if given no options if will inform you of the
	differences between the current local file and the version
	that was checked out. It also accepts all of the options that
	the normal diff command accepts. I highly suggest using the -u
	option (unified diffs).
      </li>
      <li>
	<tt>log</tt> shows the log messages for a files or files,
	those messages should provide a description of what the
	changes in the code at least hoped to accomplish.
      </li>
      <li>
	<tt>update</tt> will modify your local files to be 'updated'
	to a specific repository version, by default it will update it
	to the latest version of the code. You can also uses this
	command to select a specific version and prevent cvs from
	updating it. This happens by specifying a specific revision, tag
	or date when running update. You can remove this 'stickiness'
	with the use of the -A option. Also update by default won't
	create any new directories that have been added by default, if
	you want it to add directories use the -d option.
      </li> 
    </ul>
    <p>Common options to cvs commands</p>
    <ul>
      <li>
	<tt>-r</tt> specify a specific file revision, (like -r 1.43)
	or a specific tag (like -r STABLE)
      </li>
      <li>
	<tt>-D</tt> specify a specific revision date, is accepts
	absolute dates 
	(ex. 'Nov 30 23:30 2001') or relative dates
        (ex. 'last week' or 'today')
      </li>
    </ul>

    <p>
      Some commands to try (in the loncom directory)
    </p>
    <pre>
cvs diff -u -r 1.40 -r 1.43 lond | less
cvs diff -u -r STABLE -r HEAD loncron | less
cvs log loncron | less
cvs update -r STABLE loncron
cvs update -D 'last week'
cvs update -A loncron
cvs annotate loncron | less
    </pre>

    <h3>Changing Code and detecting errors</h3>
    <p>
      We will change the lonhomework handler to act differently, and
      we will cause it to throw errors
    </p>
    
    <ul>
      <li>
	Bring up loncapa/loncom/homework/lonhomework.html in a text
	editor, and introduce a syntax error. (For example delete a ;
	somewhere). Then save this version.
      </li>
      <li>
	Open up a terminal and su to root. In this new window copy the
	new version of lonhomework.html to the directory
	<tt>/home/httpd/lib/perl/Apache</tt>. Then restart the webserver with
  <tt>/etc/init.d/httpd restart</tt>
  
</li>
  <li>
      Note the error message you have just received.
  </li>
  <li>
    Use the command <tt>cvs diff -u lonhomework.pm</tt> to see what
    you changed.
  </li>
  <li>
    Fix the previous error, and then in the subroutine <tt>handler</tt> add a
    call to a function that doesn't exist. (Example, on line 438 on
    lonhomework.html, add the line
    <pre>
&amp;idontexist();
    </pre>
  </li>
  <li>
    Repeat the copy, and httpd restart that you did before. And then
    go a visit a homework problem.
  </li>
  <li>
    You can find a perl error report in the file
    /var/log/httpd/error_log You can use the tail command to quickly
    see the end of a file.
  </li>
</ul>

    <h2>Making a new Handler</h2>
    <p>
      In the examples below <i>italicised</i> lines are lines of code
      that changed from the previous example, <b>bold</b> lines are
      lines that have been added to the example, and any time
      "username" appears it should be replaced by your specific
      username.
    </p>
    <h3>Example 1</h3>
    <pre>
package Apache::workshop;
use strict;
use Apache::Constants qw(:common :http);
sub handler {
	my $r=@_[0];
	$r->content_type('text/html');
	$r->send_http_header;
	return OK if $r->header_only;
	$r->print("The workshop handler");
	return OK;
}
1;
__END__
    </pre>
    <h3>Example 2</h3>
    <pre>
&lt;Location /adm/workshop&gt;
PerlAccessHandler       Apache::lonacc
SetHandler perl-script
PerlHandler Apache::workshop
ErrorDocument     403 /adm/login
ErrorDocument     500 /adm/errorhandler
&lt;/Location&gt;

&lt;LocationMatch "^/(res|\~).*\.workshop$"&gt;
SetHandler perl-script
PerlHandler Apache::workshop
&lt;/LocationMatch&gt;
    </pre>
    <h3>Example 3</h3>
    <pre>
package Apache::workshop;
use strict;
use Apache::Constants qw(:common :http);
sub handler {
	my $r=@_[0];
	$r->content_type('text/html');
	$r->send_http_header;
	return OK if $r->header_only;
	<i>$r->print("The workshop handler is in use by $env{'user.name'}");</i>
	return OK;
}
1;
__END__
    </pre>
    <h3>Example 4</h3>
    <pre>
package Apache::workshop;
use strict;
use Apache::Constants qw(:common :http);
<b>use Apache::lonnet;</b>
sub handler {
	my $r=@_[0];
	$r->content_type('text/html');
	$r->send_http_header;
	return OK if $r->header_only;
	<i>$r->print("The workshop handler is in use by $env{'user.name'} looking for "
                     .$r->uri."&lt;br&gt;");</i>
	<b>my $file=&amp;Apache::lonnet::filelocation("",$r->uri);</b>
	<b>my $contents=&amp;Apache::lonnet::getfile($file);</b>
	<b>$r->print($contents);</b>
	return OK;
}
1;
__END__
    </pre>
    <h3>Example 5</h3>
    <pre>
package Apache::workshop;
use strict;
use Apache::Constants qw(:common :http);
use Apache::lonnet;
sub handler {
	my $r=@_[0];
	$r->content_type('text/html');
	$r->send_http_header;
	return OK if $r->header_only;
	$r->print("The workshop handler is in use by $env{'user.name'} looking for "
                   .$r->uri."&lt;br&gt;");
	my $file=&amp;Apache::lonnet::filelocation("",$r->uri);
	my $contents=&amp;Apache::lonnet::getfile($file);
	<b>$contents=~s/simple/complex/g;</b>
	$r->print($contents);
	return OK;
}
1;
__END__
    </pre>
    <h3>Example 6</h3>
    <pre>
package Apache::workshop;
use strict;
use Apache::Constants qw(:common :http);
use Apache::lonnet;
sub handler {
        my $r=@_[0];
        $r->content_type('text/html');
        $r->send_http_header;
        return OK if $r->header_only;
        $r->print("The workshop handler is in use by $env{'user.name'} looking for "
                   .$r->uri."&lt;br&gt;");
        my $file=&amp;amp;Apache::lonnet::filelocation("",$r->uri);
        my $contents=&amp;amp;Apache::lonnet::getfile($file);
        $contents=~s/simple/complex/g;
        $r->print($contents);
        <b>my %hash=&amp;Apache::lonnet::get('workshop',['info']);
        #handle any errors
        if ($hash{'info'} =~ m/^error:.*/) {
                $r->print("&lt;br&gt;An error -$hash{'info'}- occured");
        } else {
                $r->print("&lt;br&gt;Last time you said $hash{'info'}");
        }
        if ($env{'form.info'}) {
                $r->print("&lt;br&gt;Now you say $env{'form.info'}");
                $hash{'info'}=$env{'form.info'};
                &amp;Apache::lonnet::put('workshop',\%hash);
        }</b>
        return OK;
}
1;
__END__
    </pre>
    <h3>Example 7</h3>
    <pre>
&lt;html&gt;
	&lt;head&gt;&lt;title&gt; A simple file &lt;/title&gt;&lt;/head&gt;
	&lt;body&gt;
		This is a simple file
	&lt;/body&gt;
&lt;/html&gt;
    </pre>
    <h3>Example 8</h3>
    <pre>
&lt;html&gt;
	&lt;head&gt;&lt;title&gt; A simple file &lt;/title&gt;&lt;/head&gt;
	&lt;body&gt;
		This is a simple file
	        <b>&lt;form method="POST" action="/~domcc/a.workshop"&gt;
		       &lt;input type="text" name="info"&gt;&lt;/input&gt;
		       &lt;input type="submit" name="Submit"&gt;&lt;/input&gt;
                &lt;/form&gt;</b>
	&lt;/body&gt;
&lt;/html&gt;

    </pre>
    <ol>
    <li>
     You will need to add the author role to the domcc user, use the
     CUSR button on the remote, type in the username 'domcc' and then
     add the author role. Logout, and log back in. (You will also need
     to let the webserver have permission to enter domcc's home
     directory, do this by having domcc do<tt>chmod a+x
     /home/domcc</tt>
    </li>
    <li> 
      Create the file loncapa/loncom/workshop.pm using your
      favourite unix text editor and type in example 1
    </li>
    <li>
      Add example 2 to the file /etc/httpd/conf/loncapa_apache.conf
    </li>
    <li>
      Copy the workshop.pm file to /home/httpd/lib/perl/Apache, and
      restart the webserver. You will need to do this after every
      change of the workshop.pm file.
    </li>
      <li>
	Point netscape at "http://cc313-pc-XX.cl.msu.edu/adm/workshop". You
	should see the simple message the handler prints out.
      </li>
      <li>
	Change workshop.pm to be what is in Example 3, the
	italicised line is the only one that changed.
      </li>
      <li>
	In netscape reload
	"http://cc313-pc-XX.cl.msu.edu/adm/workshop". You should see the
	output of the handler should now have your lon-capa name, which it
	got from the session environment.
      </li>
      <li>
	Next in netscape goto
	"http://cc313-pc-XX.cl.msu.edu/~domcc/a.workshop". You should
	see the same output as before.
      </li>
      <li>
	Using the terminal edit the file ~/public_html/a.workshop and
	put in it Example 7 using your favourite unix text editor.
      </li>
      <li>
	Change ~/workshop.pm to be what is in Example 4, the
	italicised lines are changed and the bold lines should be
	added.
      </li>
      <li>
	In netscape reload
	"http://cc313-pc-XX.cl.msu.edu/~domcc/a.workshop". You should
	see the output of the handler contains the contents of the file
	that you created along with the name of the file.
      </li>
      <li>
	Change ~/workshop.pm to be what is in Example 5, the
	bold line should be added.
      </li>
      <li>
	In netscape reload
	"http://cc313-pc-XX.cl.msu.edu/~domcc/a.workshop". You should
	see the output of the handler contains the contents of the
	file that you created along with the name of the file, except
	that this time all instances of the word "simple" have been
	replaced with the word "complex", this includes the one in the
	title and the one in the body of the file.
      </li>
      <li>
	<ol>
	  <li>
	    Change what is in ~/workshop.pm to be what is in Example
	    6. The bold section of code needs to be added.
	  </li>
	  <li>
	    Change what is in ~/public_html/a.workshop to be what is
	    in Example 8. The bold section needs to be added
	  </li>
	  <li>
	    In netscape reload
	    "http://cc313-pc-XX.cl.msu.edu/~domcc/a.workshop". The web
	    page should now contain a form, and say that an error
	    occurred.
	  </li>
	  <li>
	    Type something into the form field and click the submit button.
	  </li>
	  <li>
	    The handler should still report an error, but also echo
	    back what you typed into the error handler.
	  </li>
	  <li>
	    Type in the terminal
	    <pre>
ls -l /home/httpd/lonUsers/pcXX/d/o/m/domcc
	    </pre>
	    Notice that there is a workshop.db file and a
	    workshop.hist file.
	  </li>
	  <li>
	    Type in the terminal
	    <pre>
cat /home/httpd/lonUsers/pcXX/d/o/m/workshop.hist
	    </pre>
	    You should see the information that you submitted.
	  </li>
	  <li>
	    In netscape revisit
	    "http://cc313-pc-XX.cl.msu.edu/~domcc/a.workshop". (Do
	    this by hitting return in the URL field of netscape, Don't
	    use the reload button.) Notice that the handler no longer
	    has an error. Also notice that the handler tells you what
	    you said last time.
	  </li>
	  <li>
	    Type something new into the text field and hit submit. The
	    handler should tell you the first submission and the last
	    submission.
	  </li>
	</ol>
      </li>
<!--
      <li>
	Extra credit: convert Example 5 to use store/restore instead
	of the get/put. You will need to publish a .workshop file and
	include it into a map. (Note that violin.sequence is the
	toplevel map for you course.
      </li>
      <li>
	Extra credit: Use Apache::lonxml::xmlparse to properly process the html file.
	Use &lt;window&gt;&lt;/window&gt; in your example .workshop file.
      </li>
-->
    </ol>
    <h2>Helpful Notes</h2>
    <ul>
      <li>
	Remember that Apache::lonnet::put and Apache::lonnet::get
	store data that is user wide. I use them for simplicity sake
	here. Every .workshop file will read and write to the same
	data location in the last example. Use store/restore if you
	want to have data stored per unique resource instance in a
	specific course. However this means that store/restore will
	throw errors if you attempt to use them in a context in which
	a resource isn't published or isn't uniquely identified
	(i.e. browsing resources.)
      </li>
    </ul>
    <hr />
    <address><a href="mailto:albertel@msu.edu">Guy Albertelli</a></address>
<!-- Created: Wed May 23 02:34:54 EDT 2001 -->
<!-- hhmts start -->
Last modified: Tue Jun 11 14:18:30 EDT 2002
<!-- hhmts end -->
  </body>
</html>

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>