Application » History » Version 4
Elmer de Looff, 2013-03-21 14:05
router adding / removing explained
1 | 1 | Elmer de Looff | h1. Application |
---|---|---|---|
2 | 1 | Elmer de Looff | |
3 | 2 | Elmer de Looff | Provided with µWeb is a script named @uweb@ which when [[Installation|installed]] using @pip@ will be located on your path, i.e. globally executable. With this application you can create and manage µWeb projects and webservers for testing purposes. |
4 | 1 | Elmer de Looff | |
5 | 2 | Elmer de Looff | h2. Creating new µWeb projects |
6 | 1 | Elmer de Looff | |
7 | 2 | Elmer de Looff | New µWeb projects can be created (initialized) by running the @uweb init@ command. With this, you have to specify the name of your project, as follows: |
8 | 1 | Elmer de Looff | |
9 | 2 | Elmer de Looff | <pre><code class="bash"> |
10 | 2 | Elmer de Looff | uweb init boondoggle |
11 | 2 | Elmer de Looff | </code></pre> |
12 | 1 | Elmer de Looff | |
13 | 2 | Elmer de Looff | This creates a µWeb project named @boondoggle@ in the current directory. All the necessary files are copied to this directory and a router configuration entry is made (more about that later). What's important now is picking the right name for your project (of course, you can change it, but a good name gets you going). The script will do its thing and tell you when it's done: |
14 | 1 | Elmer de Looff | |
15 | 1 | Elmer de Looff | <pre> |
16 | 3 | Elmer de Looff | elmer@Penrose:~$ uweb init boondoggle |
17 | 2 | Elmer de Looff | +--------------------------------------------------------------+ |
18 | 2 | Elmer de Looff | | initializing new uWeb project 'boondoggle' | |
19 | 2 | Elmer de Looff | +--------------------------------------------------------------+ |
20 | 2 | Elmer de Looff | * copying uWeb base project directory |
21 | 2 | Elmer de Looff | * setting up router |
22 | 2 | Elmer de Looff | * setting up apache config |
23 | 2 | Elmer de Looff | +--------------------------------------------------------------+ |
24 | 2 | Elmer de Looff | | initialization complete - have fun with uWeb | |
25 | 2 | Elmer de Looff | +--------------------------------------------------------------+ |
26 | 1 | Elmer de Looff | </pre> |
27 | 1 | Elmer de Looff | |
28 | 2 | Elmer de Looff | h3. Error: Target already exists |
29 | 1 | Elmer de Looff | |
30 | 2 | Elmer de Looff | Sometimes you end up using the same really good name twice. µWeb will warn you that there's already a directory with the given name, it won't readily use this directory and destroy its contents. You can use the @-f@ flag to force the initialization in that directory. |
31 | 1 | Elmer de Looff | |
32 | 2 | Elmer de Looff | *N.B.*: This will delete any and all existing data in the target directory. It will not _merge_ the µWeb project. |
33 | 1 | Elmer de Looff | |
34 | 4 | Elmer de Looff | h2. Controlling the development webserver |
35 | 1 | Elmer de Looff | |
36 | 4 | Elmer de Looff | The uweb script can also be used to list all projects, control and configure development webserver. All the information used here is stored in the @sites.json@ file, stored in the @.uweb@ directory in your homedir. |
37 | 1 | Elmer de Looff | |
38 | 2 | Elmer de Looff | h3. Listing µWeb projects |
39 | 1 | Elmer de Looff | |
40 | 2 | Elmer de Looff | µWeb comes preloaded with a set of two example projects, and now our project is listed as well: |
41 | 1 | Elmer de Looff | |
42 | 1 | Elmer de Looff | <pre> |
43 | 2 | Elmer de Looff | elmer@Penrose:~$ uweb list |
44 | 2 | Elmer de Looff | Overview of active sites: |
45 | 1 | Elmer de Looff | |
46 | 2 | Elmer de Looff | +------------+---------------------------------+-------------+ |
47 | 2 | Elmer de Looff | | Name | Router | Working dir | |
48 | 2 | Elmer de Looff | +------------+---------------------------------+-------------+ |
49 | 2 | Elmer de Looff | | boondoggle | boondoggle.router.boondoggle | /home/elmer | |
50 | 2 | Elmer de Looff | | logviewer | uweb.logviewer.router.logging | / | |
51 | 2 | Elmer de Looff | | uweb_info | uweb.uweb_info.router.uweb_info | / | |
52 | 2 | Elmer de Looff | +------------+---------------------------------+-------------+ |
53 | 1 | Elmer de Looff | </pre> |
54 | 1 | Elmer de Looff | |
55 | 2 | Elmer de Looff | We can see three projects here: |
56 | 2 | Elmer de Looff | * Our newly initialized @boondoggle@ project, aspiring to be the new social media synergy machine. |
57 | 2 | Elmer de Looff | * @logviewer@, which is a handy viewer for µWeb's SQLite logfiles |
58 | 2 | Elmer de Looff | * @uweb_info@, a demonstration project for various µWeb functionalities and abstractions. |
59 | 1 | Elmer de Looff | |
60 | 2 | Elmer de Looff | h3. Starting and stopping µWeb projects |
61 | 1 | Elmer de Looff | |
62 | 2 | Elmer de Looff | µWeb projects by default run on port 8082 (and bind to all IP addresses on the machine, so they're also reachable by other people on the network). This can be configured by changing the configuration files for [[Standalone]], and in fact the two projects that come with µWeb run on different ports: |
63 | 1 | Elmer de Looff | |
64 | 2 | Elmer de Looff | * The @logviewer@ runs on port 8001 |
65 | 2 | Elmer de Looff | * @uweb_info@ runs on port 8000 |
66 | 1 | Elmer de Looff | |
67 | 2 | Elmer de Looff | Starting a µWeb project using the @uweb@ application is simple enough: |
68 | 1 | Elmer de Looff | |
69 | 1 | Elmer de Looff | <pre> |
70 | 2 | Elmer de Looff | uweb start boondoggle |
71 | 1 | Elmer de Looff | </pre> |
72 | 1 | Elmer de Looff | |
73 | 2 | Elmer de Looff | You can then point your webbrowser to http://localhost:8082/ and you'll be greeted with a basic HTML page welcoming you to your new project. |
74 | 1 | Elmer de Looff | |
75 | 2 | Elmer de Looff | The development server can be stopped or restarted using the @stop@ and @restart@ commands: |
76 | 1 | Elmer de Looff | |
77 | 1 | Elmer de Looff | <pre> |
78 | 2 | Elmer de Looff | uweb stop boondoggle |
79 | 1 | Elmer de Looff | </pre> |
80 | 1 | Elmer de Looff | |
81 | 4 | Elmer de Looff | h3. Removing routers |
82 | 4 | Elmer de Looff | |
83 | 4 | Elmer de Looff | If you need to remove a project from the project list (because you no longer need to test it locally, or any other reason) you can remove it from the list using @uweb remove@: |
84 | 4 | Elmer de Looff | |
85 | 4 | Elmer de Looff | <pre> |
86 | 4 | Elmer de Looff | uweb remove boondoggle |
87 | 4 | Elmer de Looff | </pre> |
88 | 4 | Elmer de Looff | |
89 | 4 | Elmer de Looff | If this executes successfully, no feedback will be given, it will simply be removed from the internal list of sites, and no longer displayed upon new @uweb list@ commands. This will *not* remove the project's directory from disk, and if you feel the need, you can re-add the project to the list again, as explained in the next portion. |
90 | 4 | Elmer de Looff | |
91 | 4 | Elmer de Looff | h3. Adding / updating routers |
92 | 4 | Elmer de Looff | |
93 | 4 | Elmer de Looff | If you join in on an existing µWeb project, or you need to re-add a previously existing router to the project list, @uweb add@ does exactly that. In it's basic form it maps a router module to a name: |
94 | 4 | Elmer de Looff | |
95 | 4 | Elmer de Looff | <pre> |
96 | 4 | Elmer de Looff | uweb add boondoggle boondoggle.router.boondoggle |
97 | 4 | Elmer de Looff | </pre> |
98 | 4 | Elmer de Looff | |
99 | 4 | Elmer de Looff | The dots are important because the µWeb project is meant to work as a Python package. This means that the [[router]] in boondoggle can go 'up' in the package and find its [[pagemaker]]. This also means that the boondoggle directory must be on your PYTHONPATH. |
100 | 4 | Elmer de Looff | |
101 | 4 | Elmer de Looff | If the project's main directory is not on your path, you can provide the directory where it does reside with the @--directory@ option: |
102 | 4 | Elmer de Looff | |
103 | 4 | Elmer de Looff | <pre> |
104 | 4 | Elmer de Looff | uweb add boondoggle boondoggle.router.boondoggle --directory /home/elmer |
105 | 4 | Elmer de Looff | </pre> |
106 | 4 | Elmer de Looff | |
107 | 4 | Elmer de Looff | This way, the router will first change the working directory to @/home/elmer@ and from there it will try to import the @boondoggle@ package. This means that you can have multiple packages with the same name and as long as you keep them in separate working directories, you can run them all in µWeb. |
108 | 4 | Elmer de Looff | |
109 | 4 | Elmer de Looff | By default, @uweb add@ will not overwrite (or update) existing information. If we want our new boondoggle working directory to work, we need to provide the @--update@ flag, as follows: |
110 | 4 | Elmer de Looff | |
111 | 4 | Elmer de Looff | <pre> |
112 | 4 | Elmer de Looff | uweb add boondoggle boondoggle.router.boondoggle --directory /home/elmer --update |
113 | 4 | Elmer de Looff | </pre> |
114 | 1 | Elmer de Looff | |
115 | 2 | Elmer de Looff | h3. Creating Apache configurations |