From 0d3ff34e5ec30605b3e2ce0b90aed0a2906e1b4e Mon Sep 17 00:00:00 2001 From: Razvan Deaconescu Date: Wed, 28 Oct 2009 09:50:03 +0200 Subject: [PATCH] added comments to python source files --- auto/db/DatabaseAccess.py | 39 +++++++++++++----------------------- auto/db/DatabaseCommander.py | 16 +++++++++++++++ 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/auto/db/DatabaseAccess.py b/auto/db/DatabaseAccess.py index fc45588..3ec8188 100644 --- a/auto/db/DatabaseAccess.py +++ b/auto/db/DatabaseAccess.py @@ -7,6 +7,12 @@ class DatabaseAccess: """ Low-level class for database access: insert, update, delete, select operations + Basic operations on each table in P2P logging database: swarms, + btclients, client_sessions, status_messages, verbose_messages + Insert methods have dual options: + insert_swarms_row - inserts a row as an array + insert_swarms - row fields to be added are passed as separate + arguments """ def __init__ (self, dbname): @@ -27,6 +33,9 @@ class DatabaseAccess: return self.conn def get_status(self): + """ + Select rows in all tables + """ tables = ['swarms', 'btclients', 'client_sessions', 'status_messages', 'verbose_messages'] for t in tables: try: @@ -224,11 +233,12 @@ class DatabaseAccess: print("[status_messages]An error ocurred: ", e.args[0]) -""" -Test case -""" - def main(): + + """ + Test case + """ + dba = DatabaseAccess("p2p-next.db") dba.connect() @@ -268,27 +278,6 @@ def main(): dba.disconnect() - """ - for t in [('1', 'mumu', '1024', 'ceva', 'URL'), - ('2', 'gugu', '1024', 'ceva', 'URL'), - ('3', 'gaga', '1024', 'ceva', 'URL'), - ]: - insert_swarms(t) - - for t in [('1', 'tribler', 'python', 1, 0), - ]: - insert_btclients(t) - - for t in [('1', '1', '2', 'Linux', '2.6.30', '256', '1833', '0.0.0.0', '6969', '256', '96', '123131.1231') - ]: - insert_client_sessions(t) - - tables = ['swarms', 'btclients', 'swarms', 'client_sessions', 'status_messages', 'verbose_messages'] - for t in tables: - curs.execute("select * from '%s'" %t) - for row in curs: - print row - """ if __name__ == "__main__": sys.exit(main()) diff --git a/auto/db/DatabaseCommander.py b/auto/db/DatabaseCommander.py index 372b67c..411d39a 100644 --- a/auto/db/DatabaseCommander.py +++ b/auto/db/DatabaseCommander.py @@ -7,6 +7,11 @@ from julian import datetimeToJulian from DatabaseAccess import DatabaseAccess class DatabaseCommander: + """ + swarms and client_sessions table handling methods + Wrappers around DatabaseAccess class methods + """ + def __init__ (self, dbname): self.dbname = dbname self.dba = DatabaseAccess(dbname) @@ -47,6 +52,7 @@ class DatabaseCommander: client_id = self.dba.select_btclient_id_by_name(client_name) self.dba.delete_client_sessions_by_swarm(swarm_id, client_id) + def usage(): print "Usage: python DatabaseTorrentSessionHandler.py action target [-i|--id id] [options] database" print "action:" @@ -75,6 +81,15 @@ def usage(): def main(): + """ + Command line interface for database handling. Allows insertion, + deletion and selection of rows in swarms and client_sessions tables. + If id == -1, all rows in target table are deleted/selected. + Uses getopt for command line parsing. + Last argument must be a database file. + Please check README for details and running examples. + """ + try: opts, args = getopt.getopt(sys.argv[1:], "ha:l:d:s:c:i:", ["help", "add=", "list=", "delete=", "swarm=", "client=", "id="]) @@ -121,6 +136,7 @@ def main(): else: assert False, "unhandled option" + # no database file passed as argument if len(args) != 1: print "Error: no database file passed as argument." sys.exit(2) -- 2.20.1