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/24 19:54] – add bit about raw sql vs. django models morten | devel:hacking [2014/11/05 10:57] (current) – morten | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | :!: **This information is currently being updated, check back often.** | ||
| ====== Hacker' | ====== Hacker' | ||
| - | If you are contributing code to Network Administration Visualized, | + | This document has moved to https:// |
| - | please read this first. | + | |
| - | + | ||
| - | + | ||
| - | ====== Contributing to NAV ====== | + | |
| - | 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 truly free | + | |
| - | software system. | + | |
| - | + | ||
| - | While UNINETT and NTNU are still the main contributors to NAV, | + | |
| - | developing NAV to support the needs of the Norwegian higher education | + | |
| - | community, contributions from third parties is highly appreciated. | + | |
| - | + | ||
| - | We communicate mainly through mailing lists, | + | |
| - | [[https:// | + | |
| - | repositories hosted at http:// | + | |
| - | also arranges workshops and gatherings for its customers: Norwegian | + | |
| - | universities, | + | |
| - | + | ||
| - | To contribute: | + | |
| - | + | ||
| - | Go to http:// | + | |
| - | + | ||
| - | * Join the mailing lists. | + | |
| - | particular is for discussing NAV development. | + | |
| - | low traffic list. We can only hope this will change ;-) | + | |
| - | * Get a copy of the latest development sources by cloning the | + | |
| - | Mercurial repository at http:// | + | |
| - | Most new development takes place on this branch. | + | |
| - | * Take a look at the [[: | + | |
| - | 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. | + | |
| - | some of the oldest 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 (here for historic reasons). | | + | |
| - | | subsystem/ | Source code to the rest of NAV - most of it Python. | + | |
| - | | subsystem/ | + | |
| - | | subsystem/ | + | |
| - | | subsystem/ | + | |
| - | + | ||
| - | + | ||
| - | ====== Development languages and frameworks ====== | + | |
| - | For historic reasons, different parts of NAV are written in different | + | |
| - | programming languages (Perl, Java, PHP and Python). | + | |
| - | unfortunate in may ways, not at least for the sake of consistency and | + | |
| - | maintenance, | + | |
| - | number of languages and dependencies. | + | |
| - | a significant amount of time rewriting parts that were written in Perl | + | |
| - | and PHP to Python, which is the language we are currently gravitating | + | |
| - | towards. | + | |
| - | + | ||
| - | Currently (as of February 2009), major parts of NAV are written in | + | |
| - | Python and Java, while only a single Perl program remains | + | |
| - | ('' | + | |
| - | + | ||
| - | * 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 and Django. | + | |
| - | directly with '' | + | |
| - | Anything written in 2008 and later uses Django. | + | |
| - | [[devel: | + | |
| - | applications with the legacy web code]]. | + | |
| - | - If your subsystem is a new back-end tool/ | + | |
| - | Python. | + | |
| - | other languages, and you will receive a lot for free. | + | |
| - | + | ||
| - | If these rules are not followed, your patches will not be accepted | + | |
| - | into NAV (but if they are really good, we will consider including them | + | |
| - | in the //contrib// directory). | + | |
| - | + | ||
| - | If **YOU** are willing to invest in porting some of the existing | + | |
| - | Java/Perl code to Python, then you will be celebrated as a NAV hero! | + | |
| - | + | ||
| - | + | ||
| - | ====== Coding style ====== | + | |
| - | Much of the legacy NAV code was written without using any coding style | + | |
| - | guidelines. | + | |
| - | which we hope to reduce in the future. | + | |
| - | these 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:// | + | |
| - | + | ||
| - | FIXME Add info about header guidelines for Python files. | + | |
| - | + | ||
| - | If you see violations of these guidelines, don't hesitate to 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 ====== | + | |
| - | NAV uses PostgreSQL as its database backend. | + | |
| - | employed to logically group tables and relations. | + | |
| - | to 3.5 employed separate PostgreSQL databases instead of namespaces. | + | |
| - | + | ||
| - | The namespaces currently in use are: | + | |
| - | + | ||
| - | | '' | + | |
| - | | '' | + | |
| - | | '' | + | |
| - | | '' | + | |
| - | + | ||
| - | **NOTE**: The following is Python-specific, | + | |
| - | the other languages used in NAV. | + | |
| - | + | ||
| - | + | ||
| - | ===== Raw SQL ===== | + | |
| - | + | ||
| - | To obtain a connection to the NAV database, use the API accordingly, | + | |
| - | e.g.: | + | |
| - | + | ||
| - | <code python> | + | |
| - | import nav.db | + | |
| - | # Get a connection to the NAV database | + | |
| - | connection = nav.db.getConnection(' | + | |
| - | </ | + | |
| - | + | ||
| - | The above code will open a connection to NAV's database, or, if a | + | |
| - | previous connection with these parameters is already open, returns the | + | |
| - | already existing connection from a connection cache. | + | |
| - | + | ||
| - | The '' | + | |
| - | the name of a subsystem. | + | |
| - | separate database users for each subsystem (known as a '' | + | |
| - | '' | + | |
| - | database user for a subsystem called '' | + | |
| - | the same database user for all known subsystem names. | + | |
| - | using a subsystem name that is not configured in '' | + | |
| - | raise an exception in '' | + | |
| - | + | ||
| - | ===== Django models ===== | + | |
| - | NAV 3.5 and on includes Django models for the most widely used database tables. | + | |
| - | + | ||
| - | + | ||
| - | ====== Legacy web code ====== | + | |
| - | When making changes to NAV's legacy web code, a few special | + | |
| - | considerations need to be made. | + | |
| - | + | ||
| - | Legacy web code interfaces directly with | + | |
| - | [[http:// | + | |
| - | [[http:// | + | |
| - | + | ||
| - | ===== Cheetah templates ===== | + | |
| - | Global Cheetah templates are found in | + | |
| - | '' | + | |
| - | located in the subdirectories of their respective subsystems. | + | |
| - | Python modules compiled from Cheetah templates should be installed in the | + | |
| - | '' | + | |
| - | + | ||
| - | + | ||
| - | ===== Database connections ===== | + | |
| - | Use the '' | + | |
| - | existing database connection. | + | |
| - | interpreter and namespace per Apache process, which also means that | + | |
| - | database connections will be shared between the modules running in | + | |
| - | each process. | + | |
| - | connections obtained from '' | + | |
| - | + | ||
| - | * **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. | + | |
| - | * **The obtained connections will use an isolation level of //read | + | |
| - | committed// | + | |
| - | current transaction if you modify any data. A mod_python | + | |
| - | cleanuphandler will try to automatically commit all open | + | |
| - | transactions as the request cycle ends, but this may change | + | |
| - | in the future, so you must not rely on it. | + | |
| - | * **Do not change the isolation level of a connection** without | + | |
| - | restoring it to its original value before the end of the request | + | |
| - | cycle. | + | |
| - | + | ||
| - | ====== Writing new web code ====== | + | |
| - | If you are writing a new web application / tool for NAV, please use | + | |
| - | the Django framework. | + | |
| - | primer]]. | + | |
devel/hacking.1235505274.txt.gz · Last modified: by morten
