From ef9615aebb8a7b504c3b5cd2610e3c8f5bb4de58 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 15 Dec 2015 13:38:57 +0200 Subject: Various cleanups and improvements, INSTALL-DEV instructions --- brep/module | 2 +- brep/module.cxx | 2 +- brep/options.cli | 88 ++++++++++++++++++++++++++++++++++------ brep/package-details.cxx | 6 +-- brep/package-search.cxx | 4 +- brep/package-version-details.cxx | 8 ++-- brep/repository-details.cxx | 2 +- brep/shared-database | 4 +- brep/shared-database.cxx | 14 +++++-- 9 files changed, 103 insertions(+), 27 deletions(-) (limited to 'brep') diff --git a/brep/module b/brep/module index 4ac6023..80a0a56 100644 --- a/brep/module +++ b/brep/module @@ -81,7 +81,7 @@ namespace brep // // While uint8 is more than enough, use uint16 for the ease of printing. // - uint16_t verb_ {0}; + uint16_t verb_ = 0; template void level1 (const F& f) const {if (verb_ >= 1) f ();} template void level2 (const F& f) const {if (verb_ >= 2) f ();} diff --git a/brep/module.cxx b/brep/module.cxx index 253d807..d3ffcb4 100644 --- a/brep/module.cxx +++ b/brep/module.cxx @@ -207,7 +207,7 @@ namespace brep name_value_scanner s (mo); options::module o (s, unknown_mode::fail, unknown_mode::fail); - verb_ = o.log_verbosity (); + verb_ = o.verbosity (); loaded_ = true; } catch (const server_error& e) diff --git a/brep/options.cli b/brep/options.cli index d5041c8..aaf0092 100644 --- a/brep/options.cli +++ b/brep/options.cli @@ -16,43 +16,107 @@ namespace brep // class module { - uint16_t log-verbosity; - dir_path root = "/"; + dir_path root = "/" + { + "" + "Repository root. That is, this is the part of the URL from the host + name and until the start of the repository. For example, root value + '\cb{/pkg/}' means the repository URL is http://example.org/pkg/. + Specify '\cb{/}' to use the web server root (http://example.org/)." + } + + uint16_t verbosity = 0 + { + "", + "Trace verbosity level. Level 0 disables tracing, which is also the + default." + } }; class db { - string db-host = "localhost"; - uint16_t db-port = 5432; + string db-user + { + "", + "Database user name. If not specified, then operating system (login) + name is used." + } + + string db-password + { + "", + "Database password. If not specified, then login without password is + expected to work." + } + + string db-name = "brep" + { + "", + "Database name. If not specified, then '\cb{brep}' is used by default." + } + + string db-host + { + "", + "Database host name, address, or socket. If not specified, then connect + to \cb{localhost} using the operating system-default mechanism + (Unix-domain socket, etc)." + } + + uint16_t db-port = 0 + { + "", + "Database port number. If not specified, the default port is used." + } }; class search { - uint16_t search-results = 10; - uint16_t pager-pages = 5; + uint16_t search-results = 10 + { + "", + "Number of results per page. The default is 10." + } + + uint16_t search-pages = 5 + { + "", + "Number of pages in navigation (pager). The default is 5." + } }; class package { - uint16_t description-len = 500; // ~ 80 chars x 6 lines. - uint16_t changes-len = 5000; // ~ 80 chars x 60 lines. + uint16_t package-description = 500 + { + "", + "Number of package description characters to display in brief pages. + The default is 500 (~ 80 characters * 6 lines)." + } + + uint16_t package-changes = 5000; + { + "", + "Number of package changes characters to display in brief pages. The + default is 5000 (~ 80 chars x 60 lines)." + } }; // Module options. // - class package_search: module, db, search + class package_search: search, db, module { }; - class package_details: module, db, search, package + class package_details: package, search, db, module { }; - class package_version_details: module, db, package + class package_version_details: package, db, module { }; - class repository_details: module, db + class repository_details: db, module { }; diff --git a/brep/package-details.cxx b/brep/package-details.cxx index 30e185e..a10f668 100644 --- a/brep/package-details.cxx +++ b/brep/package-details.cxx @@ -37,7 +37,7 @@ init (scanner& s) if (options_->root ().empty ()) options_->root (dir_path ("/")); - db_ = shared_database (options_->db_host (), options_->db_port ()); + db_ = shared_database (*options_); } template @@ -160,7 +160,7 @@ handle (request& rq, response& rs) if (const auto& d = pkg->description) s << (full ? P_DESCRIPTION (*d, id) - : P_DESCRIPTION (*d, options_->description_len (), + : P_DESCRIPTION (*d, options_->package_description (), url (!full, squery, page, id))); s << TABLE(CLASS="proplist", ID="package") @@ -232,7 +232,7 @@ handle (request& rq, response& rs) t.commit (); - s << DIV_PAGER (page, pkg_count, res_page, options_->pager_pages (), + s << DIV_PAGER (page, pkg_count, res_page, options_->search_pages (), url (full, squery)) << ~DIV << ~BODY diff --git a/brep/package-search.cxx b/brep/package-search.cxx index 62b162b..448a915 100644 --- a/brep/package-search.cxx +++ b/brep/package-search.cxx @@ -37,7 +37,7 @@ init (scanner& s) if (options_->root ().empty ()) options_->root (dir_path ("/")); - db_ = shared_database (options_->db_host (), options_->db_port ()); + db_ = shared_database (*options_); } template @@ -138,7 +138,7 @@ handle (request& rq, response& rs) t.commit (); - s << DIV_PAGER (page, pkg_count, res_page, options_->pager_pages (), + s << DIV_PAGER (page, pkg_count, res_page, options_->search_pages (), root.string () + squery_param) << ~DIV << ~BODY diff --git a/brep/package-version-details.cxx b/brep/package-version-details.cxx index 8f6cd7d..9bc06f6 100644 --- a/brep/package-version-details.cxx +++ b/brep/package-version-details.cxx @@ -40,7 +40,7 @@ init (scanner& s) if (options_->root ().empty ()) options_->root (dir_path ("/")); - db_ = shared_database (options_->db_host (), options_->db_port ()); + db_ = shared_database (*options_); } bool brep::package_version_details:: @@ -152,7 +152,7 @@ handle (request& rq, response& rs) if (const auto& d = pkg->description) s << (full ? P_DESCRIPTION (*d, id) - : P_DESCRIPTION (*d, options_->description_len (), + : P_DESCRIPTION (*d, options_->package_description (), url (!full, id))); assert (pkg->location); @@ -302,7 +302,9 @@ handle (request& rq, response& rs) s << H3 << "Changes" << ~H3 << (full ? PRE_CHANGES (ch) - : PRE_CHANGES (ch, options_->changes_len (), url (!full, "changes"))); + : PRE_CHANGES (ch, + options_->package_changes (), + url (!full, "changes"))); s << ~DIV << ~BODY diff --git a/brep/repository-details.cxx b/brep/repository-details.cxx index ee34dc2..0d71ac8 100644 --- a/brep/repository-details.cxx +++ b/brep/repository-details.cxx @@ -36,7 +36,7 @@ init (scanner& s) if (options_->root ().empty ()) options_->root (dir_path ("/")); - db_ = shared_database (options_->db_host (), options_->db_port ()); + db_ = shared_database (*options_); } bool brep::repository_details:: diff --git a/brep/shared-database b/brep/shared-database index 4d8186d..b445cc1 100644 --- a/brep/shared-database +++ b/brep/shared-database @@ -9,6 +9,8 @@ #include +#include + namespace brep { // Returns pointer to the shared database instance, creating one on the @@ -17,7 +19,7 @@ namespace brep // otherwise. Is not thread-safe. // shared_ptr - shared_database (const string& host, unsigned int port); + shared_database (const options::db&); } #endif // BREP_SHARED_DATABASE diff --git a/brep/shared-database.cxx b/brep/shared-database.cxx index db6b811..1389dab 100644 --- a/brep/shared-database.cxx +++ b/brep/shared-database.cxx @@ -14,7 +14,7 @@ namespace brep { shared_ptr - shared_database (const string& h, unsigned int p) + shared_database (const options::db& o) { using odb::pgsql::database; static weak_ptr db; @@ -25,14 +25,22 @@ namespace brep // if (shared_ptr d = db.lock ()) { - if (h != d->host () || p != d->port ()) + if (o.db_user () != d->user () || + o.db_password () != d->password () || + o.db_name () != d->db () || + o.db_host () != d->host () || + o.db_port () != d->port ()) throw std::runtime_error ("shared database host/port mismatch"); return d; } else { - d = make_shared ("", "", "brep", h, p); + d = make_shared (o.db_user (), + o.db_password (), + o.db_name (), + o.db_host (), + o.db_port ()); db = d; return d; } -- cgit v1.1