Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

service_mgr add callback parameter, obsolate file parameter

  • Loading branch information...
commit 782e1ffecc838c13fa766f271e4a0333a6a652ef 1 parent e4d2b33
@nakagami authored
Showing with 35 additions and 22 deletions.
  1. +23 −16 firebirdsql/fbcore.py
  2. +5 −2 firebirdsql/tests.py
  3. +7 −4 misc/trace.py
View
39 firebirdsql/fbcore.py
@@ -1242,13 +1242,13 @@ def __init__(self, dsn=None, user=None, password=None, host=None,
(h, oid, buf) = self._op_response()
self.db_handle = h
- def backup_database(self, backup_filename, file=None):
+ def backup_database(self, backup_filename, callback=None):
spb = bs([isc_action_svc_backup])
s = self.str_to_bytes(self.filename)
spb += bs([isc_spb_dbname]) + int_to_bytes(len(s), 2) + s
s = self.str_to_bytes(backup_filename)
spb += bs([isc_spb_bkp_file]) + int_to_bytes(len(s), 2) + s
- if file:
+ if callback:
spb += bs([isc_spb_verbose])
self._op_service_start(spb)
(h, oid, buf) = self._op_response()
@@ -1259,15 +1259,16 @@ def backup_database(self, backup_filename, file=None):
if buf[:4] == bs([0x3e,0x00,0x00,0x01]):
break
ln = bytes_to_int(buf[1:2])
- (file if file else sys.stdout).write(self.bytes_to_str(buf[3:3+ln]))
+ if callback:
+ callback(self.bytes_to_str(buf[3:3+ln]))
- def restore_database(self, restore_filename, file=None):
+ def restore_database(self, restore_filename, callback=None):
spb = bs([isc_action_svc_restore])
s = self.str_to_bytes(restore_filename)
spb += bs([isc_spb_bkp_file]) + int_to_bytes(len(s), 2) + s
s = self.str_to_bytes(self.filename)
spb += bs([isc_spb_dbname]) + int_to_bytes(len(s), 2) + s
- if file:
+ if callback:
spb += bs([isc_spb_verbose])
spb += bs([isc_spb_res_buffers,0x00,0x08,0x00,0x00,isc_spb_res_page_size,0x00,0x10,0x00,0x00,isc_spb_options,0x00,0x30,0x00,0x00])
self._op_service_start(spb)
@@ -1279,9 +1280,10 @@ def restore_database(self, restore_filename, file=None):
if buf[:4] == bs([0x3e,0x00,0x00,0x01]):
break
ln = bytes_to_int(buf[1:2])
- (file if file else sys.stdout).write(self.bytes_to_str(buf[3:3+ln]))
+ if callback:
+ callback(self.bytes_to_str(buf[3:3+ln]))
- def trace_start(self, name=None, cfg=None, file=None):
+ def trace_start(self, name=None, cfg=None, callback=None):
spb = bs([isc_action_svc_trace_start])
if name:
s = self.str_to_bytes(name)
@@ -1298,9 +1300,10 @@ def trace_start(self, name=None, cfg=None, file=None):
if buf[:4] == bs([0x3e,0x00,0x00,0x01]):
break
ln = bytes_to_int(buf[1:2])
- (file if file else sys.stdout).write(self.bytes_to_str(buf[3:3+ln]))
+ if callback:
+ callback(self.bytes_to_str(buf[3:3+ln]))
- def trace_stop(self, id, file=None):
+ def trace_stop(self, id, callback=None):
id = int(id)
spb = bs([isc_action_svc_trace_stop])
spb += bs([isc_spb_trc_id]) + int_to_bytes(id, 4)
@@ -1311,9 +1314,10 @@ def trace_stop(self, id, file=None):
self._op_service_info(bs([0x02]), bs([0x3e]))
(h, oid, buf) = self._op_response()
ln = bytes_to_int(buf[1:2])
- (file if file else sys.stdout).write(self.bytes_to_str(buf[3:3+ln]))
+ if callback:
+ callback(self.bytes_to_str(buf[3:3+ln]))
- def trace_suspend(self, id, file=None):
+ def trace_suspend(self, id, callback=None):
id = int(id)
spb = bs([isc_action_svc_trace_suspend])
spb += bs([isc_spb_trc_id]) + int_to_bytes(id, 4)
@@ -1324,9 +1328,10 @@ def trace_suspend(self, id, file=None):
self._op_service_info(bs([0x02]), bs([0x3e]))
(h, oid, buf) = self._op_response()
ln = bytes_to_int(buf[1:2])
- (file if file else sys.stdout).write(self.bytes_to_str(buf[3:3+ln]))
+ if callback:
+ callback(self.bytes_to_str(buf[3:3+ln]))
- def trace_resume(self, id, file=None):
+ def trace_resume(self, id, callback=None):
id = int(id)
spb = bs([isc_action_svc_trace_resume])
spb += bs([isc_spb_trc_id]) + int_to_bytes(id, 4)
@@ -1337,9 +1342,10 @@ def trace_resume(self, id, file=None):
self._op_service_info(bs([0x02]), bs([0x3e]))
(h, oid, buf) = self._op_response()
ln = bytes_to_int(buf[1:2])
- (file if file else sys.stdout).write(self.bytes_to_str(buf[3:3+ln]))
+ if callback:
+ callback(self.bytes_to_str(buf[3:3+ln]))
- def trace_list(self, file=None):
+ def trace_list(self, callback=None):
spb = bs([isc_action_svc_trace_list])
self._op_service_start(spb)
(h, oid, buf) = self._op_response()
@@ -1350,7 +1356,8 @@ def trace_list(self, file=None):
if buf[:4] == bs([0x3e,0x00,0x00,0x01]):
break
ln = bytes_to_int(buf[1:2])
- (file if file else sys.stdout).write(self.bytes_to_str(buf[3:3+ln]))
+ if callback:
+ callback(self.bytes_to_str(buf[3:3+ln]))
def close(self):
if not hasattr(self, "db_handle"):
View
7 firebirdsql/tests.py
@@ -11,6 +11,9 @@
sys.path.append('./../')
import firebirdsql
+def debug_print(msg):
+ print(msg)
+
if __name__ == '__main__':
if sys.platform in ('win32', 'darwin'):
fbase = os.path.abspath('.') + '/test'
@@ -88,10 +91,10 @@
print('backup database')
svc = firebirdsql.service_mgr(dsn=TEST_DSN, user=TEST_USER,
password=TEST_PASS, port=3050)
- svc.backup_database(TEST_BACKUP_FILE, sys.stdout)
+ svc.backup_database(TEST_BACKUP_FILE, callback=debug_print)
svc.close()
print('restore database')
svc = firebirdsql.service_mgr(dsn=TEST_RESTORE_DSN, user=TEST_USER,
password=TEST_PASS, port=3050)
- svc.restore_database(TEST_BACKUP_FILE, sys.stdout)
+ svc.restore_database(TEST_BACKUP_FILE, callback=debug_print)
svc.close()
View
11 misc/trace.py
@@ -15,6 +15,9 @@
USER = 'sysdba'
PASS = 'masterkey'
+def debug_print(msg):
+ print(msg)
+
def print_usage():
print(sys.argv[0] +
' start|stop <trc_id>|suspend <trc_id>|resume <trc_id>|list')
@@ -26,13 +29,13 @@ def print_usage():
svc = firebirdsql.service_mgr(host=HOST, user=USER, password=PASS)
if sys.argv[1] == 'start':
cfg = open('/opt/firebird/fbtrace.conf').read()
- svc.trace_start(cfg=cfg, file=sys.stdout)
+ svc.trace_start(cfg=cfg, callback=debug_print)
elif sys.argv[1] == 'stop':
- svc.trace_stop(id=sys.argv[2], file=sys.stdout)
+ svc.trace_stop(id=sys.argv[2], callback=debug_print)
elif sys.argv[1] == 'suspend':
- svc.trace_suspend(id=sys.argv[2], file=sys.stdout)
+ svc.trace_suspend(id=sys.argv[2], callback=debug_print)
elif sys.argv[1] == 'resume':
- svc.trace_resume(id=sys.argv[2], file=sys.stdout)
+ svc.trace_resume(id=sys.argv[2], callback=debug_print)
elif sys.argv[1] == 'list':
svc.trace_list()
svc.close()
Please sign in to comment.
Something went wrong with that request. Please try again.