devel:hacking
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| devel:hacking [2009/02/09 11:24] – break list item lines (installed mllist plugin to enable this) morten | devel:hacking [2014/11/05 10:57] (current) – morten | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | :!: **Be warned, this information is becoming very out of date, it is currently being updated** :!: | ||
| ====== Hacker' | ====== Hacker' | ||
| - | If you are contributing code to Network Administration Visualized, | + | This document has moved to https:// |
| - | please read this first. | + | |
| - | + | ||
| - | + | ||
| - | ===== Participating in the community ===== | + | |
| - | Originally, NAV was a closed source project, initiated by the | + | |
| - | Norwegian University of Science and Technology (NTNU), and eventually | + | |
| - | sponsored by UNINETT on behalf of the Norwegian higher education | + | |
| - | community. | + | |
| - | NAV under the GNU General Public License, making it a true open source | + | |
| - | project. | + | |
| - | + | ||
| - | While NTNU and UNINETT still are the main contributors to NAV, | + | |
| - | developing NAV to support the needs of the Norwegian higher education | + | |
| - | community, volunteer work from other interested parties is highly | + | |
| - | appreciated. | + | |
| - | + | ||
| - | The community exists mainly through mailing lists, a wiki and a | + | |
| - | Subversion repository, although UNINETT also arranges seminars and | + | |
| - | gatherings for its target audience: Norwegian universities and | + | |
| - | university colleges. | + | |
| - | + | ||
| - | Go to http:// | + | |
| - | + | ||
| - | * Join the mailing lists. | + | |
| - | for discussing NAV development. | + | |
| - | list. We can only hope this will change ;-) | + | |
| - | * Get a copy of the latest development sources from | + | |
| - | | + | |
| - | always takes place on trunk. Bugfixes, enhancements, | + | |
| - | features are backported from there to the various release | + | |
| - | branches. | + | |
| - | * Take a look at the project reports from previous development | + | |
| - | projects at NTNU (NAVMe, NAVMore, tigaNAV and others) - design | + | |
| - | specifications and other useful bits of historic NAV information | + | |
| - | is mostly to be found in these. | + | |
| - | project documentation is in Norwegian only. Do not hesitate to | + | |
| - | ask for help on the mailing lists. | + | |
| - | + | ||
| - | If you wish to contribute code to the project, please tell us about it | + | |
| - | on the nav-dev mailing list. It is always a good idea to check if | + | |
| - | someone is already working on something similar, and to get some | + | |
| - | helpful tips on how to integrate your code with the rest of the | + | |
| - | project. | + | |
| - | nav-dev and provide a link to the patch so it can be studied for | + | |
| - | possible inclusion into NAV. | + | |
| - | + | ||
| - | + | ||
| - | ===== Directory layout ===== | + | |
| - | A rough guide to the source tree: | + | |
| - | + | ||
| - | | conf/ | Files related to the autoconf build system. | | + | |
| - | | doc/ | User and developer documentation, | + | |
| - | | tools/ | + | |
| - | | contrib/ | + | |
| - | | packages/ | + | |
| - | | src/ | Source code to Java subsystems of NAV (still here for historic reasons). | | + | |
| - | | subsystem/ | Source code to the rest of NAV - a lot of Python. NAV is loosely divided into subsystems, and each one of these has its own subdirectory in here. | | + | |
| - | | subsystem/ | + | |
| - | | subsystem/ | + | |
| - | | subsystem/ | + | |
| - | + | ||
| - | + | ||
| - | ===== Development languages ===== | + | |
| - | For historic reasons, NAV today is made up of several programming | + | |
| - | languages - these are Python, Java and Perl. Although this is | + | |
| - | unfortunate in many ways, no-one has been willing to invest in the | + | |
| - | time needed to rewrite stuff to reduce the number of languages. | + | |
| - | + | ||
| - | When contributing patches to existing code, or plugins to existing | + | |
| - | subsystems, use the language that subsystem was written in. | + | |
| - | + | ||
| - | When writing entirely new subsystems, the following rules apply: | + | |
| - | + | ||
| - | * If your subsystem is a new tool for the web interface, use | + | |
| - | Python. The web interface is built using mod_python. Also, the | + | |
| - | integration with Cricket uses Cricket' | + | |
| - | Perl CGI. | + | |
| - | * If your subsystem is a new back-end tool/ | + | |
| - | Python. The Python API created for NAV is more complete than for | + | |
| - | any of the other languages, and you will receive a lot for free. | + | |
| - | You may use Perl if you absolutely abhor Python, but then you will | + | |
| - | be frowned upon. | + | |
| - | + | ||
| - | If *YOU* are willing to invest in porting some of the existing code to | + | |
| - | Python, then you will be celebrated as a NAV hero! | + | |
| - | + | ||
| - | + | ||
| - | ===== Coding style ===== | + | |
| - | NAV has not previously bothered with having coding style guidelines. | + | |
| - | This has resulted in some chaotic combination of styles, which we hope | + | |
| - | to reduce in the future. | + | |
| - | guidelines: | + | |
| - | + | ||
| - | * For Java code, please refer to SUN's "Code conventions for the | + | |
| - | Java Programming Language": | + | |
| - | * For Python code, please refer to PEP-8, "Style Guide for Python | + | |
| - | Code" http:// | + | |
| - | + | ||
| - | If you see violations of these guidelines, don't hesitate to report | + | |
| - | them and/or fix them :) If you fix file-wide indentation problems | + | |
| - | etc., please submit this as a separate patch to make your other | + | |
| - | patches look clean and readable. | + | |
| - | + | ||
| - | + | ||
| - | ===== Database connections ===== | + | |
| - | NOTE: The following is Python-specific, | + | |
| - | the other languages used in NAV. | + | |
| - | + | ||
| - | The NAV database actually consists of four PostgreSQL databases | + | |
| - | (although there are plans to merge them into a single database using | + | |
| - | PostgreSQL' | + | |
| - | + | ||
| - | | '' | + | |
| - | | '' | + | |
| - | | '' | + | |
| - | | '' | + | |
| - | + | ||
| - | To obtain a connection to the NAV database, use the API accordingly, | + | |
| - | e.g.: | + | |
| - | + | ||
| - | <code python> | + | |
| - | import nav.db | + | |
| - | # Get a connection to the manage database | + | |
| - | connection = nav.db.getConnection(' | + | |
| - | </ | + | |
| - | + | ||
| - | The above code will open a connection to the manage database, or, if | + | |
| - | the connection had already been opened during the lifetime of the | + | |
| - | current process, returns the already existing connection from a | + | |
| - | connection cache. | + | |
| - | + | ||
| - | The ' | + | |
| - | allows one to configure separate database users for each subsystem | + | |
| - | (known as a script in db.conf) of NAV, but it is recommended to use | + | |
| - | only one user for all NAV database connections - hence the default | + | |
| - | " | + | |
| - | + | ||
| - | + | ||
| - | ===== Web interface ===== | + | |
| - | When programming for NAV's web interface, a few special considerations | + | |
| - | need to be made. | + | |
| - | + | ||
| - | ==== Mod_python ==== | + | |
| - | NAV uses mod_python to interface with the Apache web server. | + | |
| - | http:// | + | |
| - | + | ||
| - | ==== Cheetah Templates ==== | + | |
| - | The NAV web interface makes extensive use of Cheetah templates for | + | |
| - | generating its HTML output, see http:// | + | |
| - | + | ||
| - | Most of the existing Cheetah templates are to be found in | + | |
| - | subsystem/ | + | |
| - | store their templates along with their code in their respective subsystem | + | |
| - | subdirectories. The compiled templates should be placed in the | + | |
| - | nav.web.templates package. | + | |
| - | + | ||
| - | If you are making a new web module for NAV, your module' | + | |
| - | template should subclass MainTemplate.tmpl found in | + | |
| - | subsystem/ | + | |
| - | examples of how to inherit from this template. | + | |
| - | + | ||
| - | ==== Database connections in the web interface ==== | + | |
| - | As stated above, use the nav.db.getConnection function to open or | + | |
| - | retrieve an existing database connection. | + | |
| - | the same interpreter and namespace per Apache process, which also | + | |
| - | means that database connections will be shared between the modules | + | |
| - | running in each process. | + | |
| - | for connections obtained from nav.db.getConnection: | + | |
| - | + | ||
| - | * Do not, under any circumstances, | + | |
| - | connection between client requests. | + | |
| - | connection at the start of each request cycle - the API will cache | + | |
| - | connections between requests, and will automagically re-open | + | |
| - | broken connections. | + | |
| - | modules, retained references may be invalid in the next request | + | |
| - | cycle. | + | |
| - | * Do not explicitly close database connections. | + | |
| - | will try to reopen any closed or broken connections, | + | |
| - | extra overhead, and you don't play nice with the other web | + | |
| - | modules. | + | |
| - | * Do not enable/ | + | |
| - | transaction isolation level, unless you make pretty darn sure to | + | |
| - | reset them to their original states at the end of a request cycle. | + | |
| - | * NAV 3.0 makes connections autocommit by default, whereas NAV 3.1 | + | |
| - | will not - make sure to commit your transactions when needed. | + | |
| - | will help unfortunate souls by attempting to commit transactions | + | |
| - | in a mod_python cleanuphandler, | + | |
| - | explicitly call connection.commit to avoid having your | + | |
| - | transactions accidentally rolled back. | + | |
devel/hacking.1234178650.txt.gz · Last modified: by morten
