Changeset 3119
- Timestamp:
- 01/21/08 13:36:51 (1 year ago)
- Files:
-
- timingandestimationplugin/branches/trac0.10/setup.py (modified) (1 diff)
- timingandestimationplugin/branches/trac0.10/timingandestimationplugin/api.py (modified) (8 diffs)
- timingandestimationplugin/branches/trac0.10/timingandestimationplugin/dbhelper.py (modified) (8 diffs)
- timingandestimationplugin/branches/trac0.10/timingandestimationplugin/webui.py (modified) (2 diffs)
- timingandestimationplugin/branches/trac0.11/setup.py (modified) (1 diff)
- timingandestimationplugin/branches/trac0.11/timingandestimationplugin/api.py (modified) (11 diffs)
- timingandestimationplugin/branches/trac0.11/timingandestimationplugin/dbhelper.py (modified) (8 diffs)
- timingandestimationplugin/branches/trac0.11/timingandestimationplugin/statuses.py (modified) (1 diff)
- timingandestimationplugin/branches/trac0.11/timingandestimationplugin/webui.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
timingandestimationplugin/branches/trac0.10/setup.py
r2824 r3119 8 8 description='Plugin to make Trac support time estimation and tracking', 9 9 keywords='trac plugin estimation timetracking', 10 version='0.5. 2',10 version='0.5.3', 11 11 url='http://www.trac-hacks.org/wiki/TimingAndEstimationPlugin', 12 12 license='http://www.opensource.org/licenses/mit-license.php', timingandestimationplugin/branches/trac0.10/timingandestimationplugin/api.py
r2824 r3119 49 49 # Setup logging 50 50 dbhelper.mylog = self.log 51 dbhelper.env = self.env 51 52 self.db_version_key = 'TimingAndEstimationPlugin_Db_Version' 52 53 self.db_version = 6 … … 78 79 # Legacy support hack (supports upgrades from 0.1.6 to 0.1.7) 79 80 if self.db_installed_version == 0: 80 bill_date = dbhelper.db_table_exists( self.env.get_db_cnx(),'bill_date');81 report_version = dbhelper.db_table_exists( self.env.get_db_cnx(),'report_version');81 bill_date = dbhelper.db_table_exists('bill_date'); 82 report_version = dbhelper.db_table_exists('report_version'); 82 83 if bill_date and report_version: 83 84 self.db_installed_version = 1 … … 94 95 ); 95 96 """ 96 dbhelper.execute_non_query( self.env.get_db_cnx(),sql)97 dbhelper.execute_non_query( sql) 97 98 98 99 print "Creating report_version table" … … 104 105 ); 105 106 """ 106 dbhelper.execute_non_query(s elf.env.get_db_cnx(), sql)107 dbhelper.execute_non_query(sql) 107 108 108 109 if self.db_installed_version < 4: … … 111 112 ALTER TABLE report_version ADD COLUMN tags varchar(1024) null; 112 113 """ 113 dbhelper.execute_non_query(s elf.env.get_db_cnx(), sql)114 dbhelper.execute_non_query(sql) 114 115 115 116 if self.db_installed_version < 5: … … 120 121 sql = "DELETE FROM report " \ 121 122 "WHERE author=%s AND id IN (SELECT report FROM report_version)" 122 dbhelper.execute_non_query( self.env.get_db_cnx(),sql, 'Timing and Estimation Plugin')123 dbhelper.execute_non_query( sql, 'Timing and Estimation Plugin') 123 124 124 125 sql = "DROP TABLE report_version" 125 dbhelper.execute_non_query( self.env.get_db_cnx(),sql)126 dbhelper.execute_non_query( sql) 126 127 127 128 128 129 # This statement block always goes at the end this method 129 dbhelper.set_system_value(self. env, self.db_version_key, self.db_version)130 dbhelper.set_system_value(self.db_version_key, self.db_version) 130 131 self.db_installed_version = self.db_version 131 132 … … 192 193 193 194 def needs_user_man(self): 194 maxversion = dbhelper.get_scalar(self.env.get_db_cnx(), 195 "SELECT MAX(version) FROM wiki WHERE name like %s", 0, 195 maxversion = dbhelper.get_scalar("SELECT MAX(version) FROM wiki WHERE name like %s", 0, 196 196 user_manual_wiki_title) 197 197 if (not maxversion) or maxversion < user_manual_version: … … 206 206 VALUES ( %s, %s, %s, 'Timing and Estimation Plugin', '127.0.0.1', %s,'',0) 207 207 """ 208 dbhelper.execute_non_query(s elf.env.get_db_cnx(),sql,208 dbhelper.execute_non_query(sql, 209 209 user_manual_wiki_title, 210 210 user_manual_version, timingandestimationplugin/branches/trac0.10/timingandestimationplugin/dbhelper.py
r2824 r3119 1 1 mylog = None; 2 env = None; 2 3 3 4 def get_all(db, sql, *params): 4 def get_all(sql, *params): 5 5 """Executes the query and returns the (description, data)""" 6 db = env.get_db_cnx() 6 7 cur = db.cursor() 7 8 desc = None … … 23 24 return (desc, data) 24 25 25 def execute_non_query( db,sql, *params):26 def execute_non_query( sql, *params): 26 27 """Executes the query on the given project""" 28 db = env.get_db_cnx() 27 29 cur = db.cursor() 28 30 try: … … 38 40 pass 39 41 40 def get_first_row( db,sql,*params):42 def get_first_row( sql,*params): 41 43 """ Returns the first row of the query results as a tuple of values (or None)""" 44 db = env.get_db_cnx() 42 45 cur = db.cursor() 43 46 data = None; … … 56 59 return data; 57 60 58 def get_scalar( db,sql, col=0, *params):61 def get_scalar(sql, col=0, *params): 59 62 """ Gets a single value (in the specified column) from the result set of the query""" 60 data = get_first_row( db,sql, *params);63 data = get_first_row(sql, *params); 61 64 if data: 62 65 return data[col] … … 64 67 return None; 65 68 66 def execute_in_trans( db,*args):67 success = True69 def execute_in_trans(*args): 70 db = env.get_db_cnx() 68 71 cur = db.cursor() 72 result = True 69 73 try: 70 74 for sql, params in args: … … 75 79 with parameters:%s\nException:%s'%(sql, params, e)); 76 80 db.rollback(); 77 success = False81 result = e 78 82 try: 79 83 db.close() 80 84 except: 81 85 pass 82 return success86 return result 83 87 84 def db_table_exists(db, table): 88 def db_table_exists( table): 89 db = env.get_db_cnx() 85 90 sql = "SELECT * FROM %s LIMIT 1" % table; 86 91 cur = db.cursor() … … 99 104 return has_table 100 105 101 def get_column_as_list(db, sql, col=0, *params): 102 return [valueList[col] for valueList in get_all(db, sql, *params)[1]] 106 def get_column_as_list(sql, col=0, *params): 107 data = get_all(sql, *params)[1] or () 108 return [valueList[col] for valueList in data] 103 109 104 def get_system_value( db,key):105 return get_scalar( db,"SELECT value FROM system WHERE name=%s", 0, key)110 def get_system_value(key): 111 return get_scalar("SELECT value FROM system WHERE name=%s", 0, key) 106 112 107 def set_system_value( env,key, value):108 if get_system_value( env.get_db_cnx(),key):109 execute_non_query( env.get_db_cnx(),"UPDATE system SET value=%s WHERE name=%s", value, key)113 def set_system_value(key, value): 114 if get_system_value(key): 115 execute_non_query("UPDATE system SET value=%s WHERE name=%s", value, key) 110 116 else: 111 execute_non_query( env.get_db_cnx(),"INSERT INTO system (value, name) VALUES (%s, %s)",117 execute_non_query("INSERT INTO system (value, name) VALUES (%s, %s)", 112 118 value, key) 113 119 114 120 115 def get_result_set( db,sql, *params):121 def get_result_set(sql, *params): 116 122 """Executes the query and returns a Result Set""" 117 return ResultSet(get_all(db, sql, *params)) 123 tpl = get_all(sql, *params); 124 if tpl and tpl[0] and tpl[1]: 125 return ResultSet(tpl) 126 else: 127 return None 118 128 119 129 … … 156 166 print ("rs.value Type Failed col:%s row:%s" % (type(col), type(row))) 157 167 168 def json_out(self): 169 json = "[%s]" % ',\r\n'. join( 170 [("{%s}" % ','.join( 171 ["'%s':'%s'" % 172 (key, str(self.value(val, row)). 173 replace("'","\\'"). 174 replace('"','\\"'). 175 replace('\r','\\r'). 176 replace('\n','\\n')) 177 for (key, val) in self.columnMap.items()])) 178 for row in self.rows]) 179 #mylog.debug('serializing to json : %s'% json) 180 return json timingandestimationplugin/branches/trac0.10/timingandestimationplugin/webui.py
r2390 r3119 34 34 VALUES (%s, %s, %s) 35 35 """ 36 dbhelper.execute_non_query(s elf.env.get_db_cnx(), sql, when, now, strwhen)36 dbhelper.execute_non_query(sql, when, now, strwhen) 37 37 38 38 … … 59 59 FROM bill_date 60 60 """ 61 rs = dbhelper.get_result_set(self.env.get_db_cnx(), billing_time_sql) 62 for (value, text) in rs.rows: 63 billing_info = {'text':text , 'value':value} 64 billing_dates.extend([billing_info]) 61 rs = dbhelper.get_result_set(billing_time_sql) 62 if rs: 63 for (value, text) in rs.rows: 64 billing_info = {'text':text , 'value':value} 65 billing_dates.extend([billing_info]) 65 66 #self.log.debug("bill-dates: %s"%billing_dates) 66 67 req.hdf['billing_info.billdates'] = billing_dates timingandestimationplugin/branches/trac0.11/setup.py
r2948 r3119 8 8 description='Plugin to make Trac support time estimation and tracking', 9 9 keywords='trac plugin estimation timetracking', 10 version='0. 5.9',10 version='0.6.0', 11 11 url='http://www.trac-hacks.org/wiki/TimingAndEstimationPlugin', 12 12 license='http://www.opensource.org/licenses/mit-license.php', timingandestimationplugin/branches/trac0.11/timingandestimationplugin/api.py
r2823 r3119 53 53 # Setup logging 54 54 dbhelper.mylog = self.log 55 dbhelper.env = self.env 55 56 self.statuses_key = 'T&E-statuses' 56 57 self.db_version_key = 'TimingAndEstimationPlugin_Db_Version' … … 58 59 # Initialise database schema version tracking. 59 60 self.db_installed_version = dbhelper.get_system_value(\ 60 self. env.get_db_cnx(),self.db_version_key) or 061 self.db_version_key) or 0 61 62 62 63 def environment_created(self): … … 72 73 # Legacy support hack (supports upgrades from 0.1.6 to 0.1.7) 73 74 if self.db_installed_version == 0: 74 bill_date = dbhelper.db_table_exists( self.env.get_db_cnx(),'bill_date');75 report_version = dbhelper.db_table_exists( self.env.get_db_cnx(),'report_version');75 bill_date = dbhelper.db_table_exists('bill_date'); 76 report_version = dbhelper.db_table_exists('report_version'); 76 77 if bill_date and report_version: 77 78 self.db_installed_version = 1 … … 88 89 ); 89 90 """ 90 dbhelper.execute_non_query( self.env.get_db_cnx(),sql)91 dbhelper.execute_non_query( sql) 91 92 92 93 … … 99 100 ); 100 101 """ 101 dbhelper.execute_non_query(s elf.env.get_db_cnx(), sql)102 dbhelper.execute_non_query(sql) 102 103 103 104 if self.db_installed_version < 4: … … 106 107 ALTER TABLE report_version ADD COLUMN tags varchar(1024) null; 107 108 """ 108 dbhelper.execute_non_query(s elf.env.get_db_cnx(), sql)109 dbhelper.execute_non_query(sql) 109 110 110 111 if self.db_installed_version < 5: … … 115 116 sql = "DELETE FROM report " \ 116 117 "WHERE author=%s AND id IN (SELECT report FROM report_version)" 117 dbhelper.execute_non_query(s elf.env.get_db_cnx(), sql, 'Timing and Estimation Plugin')118 dbhelper.execute_non_query(sql, 'Timing and Estimation Plugin') 118 119 119 120 sql = "DROP TABLE report_version" 120 dbhelper.execute_non_query(s elf.env.get_db_cnx(), sql)121 dbhelper.execute_non_query(sql) 121 122 122 123 #version 6 upgraded reports 123 124 124 125 # This statement block always goes at the end this method 125 dbhelper.set_system_value(self. env, self.db_version_key, self.db_version)126 dbhelper.set_system_value(self.db_version_key, self.db_version) 126 127 self.db_installed_version = self.db_version 127 128 … … 202 203 203 204 def needs_user_man(self): 204 maxversion = dbhelper.get_scalar(self.env.get_db_cnx(), 205 "SELECT MAX(version) FROM wiki WHERE name like %s", 0, 205 maxversion = dbhelper.get_scalar("SELECT MAX(version) FROM wiki WHERE name like %s", 0, 206 206 user_manual_wiki_title) 207 207 if (not maxversion) or maxversion < user_manual_version: … … 216 216 VALUES ( %s, %s, %s, 'Timing and Estimation Plugin', '127.0.0.1', %s,'',0) 217 217 """ 218 dbhelper.execute_non_query(s elf.env.get_db_cnx(),sql,218 dbhelper.execute_non_query(sql, 219 219 user_manual_wiki_title, 220 220 user_manual_version, … … 262 262 stats = get_statuses(self.config, self.env) 263 263 val = ','.join(list(stats)) 264 dbhelper.set_system_value(self. env, self.statuses_key, val)264 dbhelper.set_system_value(self.statuses_key, val) 265 265 266 266 if self.ticket_fields_need_upgrade(): … … 277 277 if we have different ones, throw return true 278 278 """ 279 s = dbhelper.get_system_value(self. env.get_db_cnx(), self.statuses_key)279 s = dbhelper.get_system_value(self.statuses_key) 280 280 if not s: 281 281 return True timingandestimationplugin/branches/trac0.11/timingandestimationplugin/dbhelper.py
r2893 r3119 1 1 mylog = None; 2 env = None; 2 3 3 4 def get_all(db, sql, *params): 4 def get_all(sql, *params): 5 5 """Executes the query and returns the (description, data)""" 6 db = env.get_db_cnx() 6 7 cur = db.cursor() 7 8 desc = None … … 23 24 return (desc, data) 24 25 25 def execute_non_query( db,sql, *params):26 def execute_non_query( sql, *params): 26 27 """Executes the query on the given project""" 28 db = env.get_db_cnx() 27 29 cur = db.cursor() 28 30 try: … … 38 40 pass 39 41 40 def get_first_row( db,sql,*params):42 def get_first_row( sql,*params): 41 43 """ Returns the first row of the query results as a tuple of values (or None)""" 44 db = env.get_db_cnx() 42 45 cur = db.cursor() 43 46 data = None; … … 56 59 return data; 57 60 58 def get_scalar( db,sql, col=0, *params):61 def get_scalar(sql, col=0, *params): 59 62 """ Gets a single value (in the specified column) from the result set of the query""" 60 data = get_first_row( db,sql, *params);63 data = get_first_row(sql, *params); 61 64 if data: 62 65 return data[col] … … 64 67 return None; 65 68 66 def execute_in_trans( db,*args):67 success = True69 def execute_in_trans(*args): 70 db = env.get_db_cnx() 68 71 cur = db.cursor() 72 result = True 69 73 try: 70 74 for sql, params in args: … … 75 79 with parameters:%s\nException:%s'%(sql, params, e)); 76 80 db.rollback(); 77 success = False81 result = e 78 82 try: 79 83 db.close() 80 84 except: 81 85 pass 82 return success86 return result 83 87 84 def db_table_exists(db, table): 88 def db_table_exists( table): 89 db = env.get_db_cnx() 85 90 sql = "SELECT * FROM %s LIMIT 1" % table; 86 91 cur = db.cursor() … … 99 104 return has_table 100 105 101 def get_column_as_list( db,sql, col=0, *params):102 data = get_all( db,sql, *params)[1] or ()106 def get_column_as_list(sql, col=0, *params): 107 data = get_all(sql, *params)[1] or () 103 108 return [valueList[col] for valueList in data] 104 109 105 def get_system_value( db,key):106 return get_scalar( db,"SELECT value FROM system WHERE name=%s", 0, key)110 def get_system_value(key): 111 return get_scalar("SELECT value FROM system WHERE name=%s", 0, key) 107 112 108 def set_system_value( env,key, value):109 if get_system_value( env.get_db_cnx(),key):110 execute_non_query( env.get_db_cnx(),"UPDATE system SET value=%s WHERE name=%s", value, key)113 def set_system_value(key, value): 114 if get_system_value(key): 115 execute_non_query("UPDATE system SET value=%s WHERE name=%s", value, key) 111 116 else: 112 execute_non_query( env.get_db_cnx(),"INSERT INTO system (value, name) VALUES (%s, %s)",117 execute_non_query("INSERT INTO system (value, name) VALUES (%s, %s)", 113 118 value, key) 114 119 115 120 116 def get_result_set( db,sql, *params):121 def get_result_set(sql, *params): 117 122 """Executes the query and returns a Result Set""" 118 return ResultSet(get_all(db, sql, *params)) 123 tpl = get_all(sql, *params); 124 if tpl and tpl[0] and tpl[1]: 125 return ResultSet(tpl) 126 else: 127 return None 119 128 120 129 … … 157 166 print ("rs.value Type Failed col:%s row:%s" % (type(col), type(row))) 158 167 168 def json_out(self): 169 json = "[%s]" % ',\r\n'. join( 170 [("{%s}" % ','.join( 171 ["'%s':'%s'" % 172 (key, str(self.value(val, row)). 173 replace("'","\\'"). 174 replace('"','\\"'). 175 replace('\r','\\r'). 176 replace('\n','\\n')) 177 for (key, val) in self.columnMap.items()])) 178 for row in self.rows]) 179 #mylog.debug('serializing to json : %s'% json) 180 return json timingandestimationplugin/branches/trac0.11/timingandestimationplugin/statuses.py
r2774 r3119 11 11 SELECT DISTINCT status FROM ticket WHERE status <> '' ; 12 12 """ 13 stats |= Set(dbhelper.get_column_as_list( env.get_db_cnx(),status_sql))13 stats |= Set(dbhelper.get_column_as_list(status_sql)) 14 14 stats.difference_update(['', None]) 15 15 return stats timingandestimationplugin/branches/trac0.11/timingandestimationplugin/webui.py
r2774 r3119 37 37 VALUES (%s, %s, %s) 38 38 """ 39 dbhelper.execute_non_query(s elf.env.get_db_cnx(), sql, when, now, strwhen)39 dbhelper.execute_non_query(sql, when, now, strwhen) 40 40 41 41 … … 65 65 FROM bill_date 66 66 """ 67 rs = dbhelper.get_result_set(self.env.get_db_cnx(), billing_time_sql) 68 for (value, text) in rs.rows: 69 billing_info = {'text':text , 'value':value} 70 billing_dates.extend([billing_info]) 67 rs = dbhelper.get_result_set(billing_time_sql) 68 if rs: 69 for (value, text) in rs.rows: 70 billing_info = {'text':text , 'value':value} 71 billing_dates.extend([billing_info]) 71 72 #self.log.debug("bill-dates: %s"%billing_dates) 72 73 data['billing_info']["billdates"] = billing_dates
