|
| 1 | +# coding: utf-8 |
| 2 | + |
| 3 | +importsix |
| 4 | + |
| 5 | + |
| 6 | +classTestgresException(Exception): |
| 7 | +pass |
| 8 | + |
| 9 | + |
| 10 | +classPortForException(TestgresException): |
| 11 | +pass |
| 12 | + |
| 13 | + |
| 14 | +@six.python_2_unicode_compatible |
| 15 | +classExecUtilException(TestgresException): |
| 16 | +def__init__(self,message=None,command=None,exit_code=0,out=None,error=None): |
| 17 | +super(ExecUtilException,self).__init__(message) |
| 18 | + |
| 19 | +self.message=message |
| 20 | +self.command=command |
| 21 | +self.exit_code=exit_code |
| 22 | +self.out=out |
| 23 | +self.error=error |
| 24 | + |
| 25 | +def__str__(self): |
| 26 | +msg= [] |
| 27 | + |
| 28 | +ifself.message: |
| 29 | +msg.append(self.message) |
| 30 | + |
| 31 | +ifself.command: |
| 32 | +command_s=' '.join(self.command)ifisinstance(self.command,list)elseself.command |
| 33 | +msg.append(u'Command: {}'.format(command_s)) |
| 34 | + |
| 35 | +ifself.exit_code: |
| 36 | +msg.append(u'Exit code: {}'.format(self.exit_code)) |
| 37 | + |
| 38 | +ifself.error: |
| 39 | +msg.append(u'---- Error:\n{}'.format(self.error)) |
| 40 | + |
| 41 | +ifself.out: |
| 42 | +msg.append(u'---- Out:\n{}'.format(self.out)) |
| 43 | + |
| 44 | +returnself.convert_and_join(msg) |
| 45 | + |
| 46 | +@staticmethod |
| 47 | +defconvert_and_join(msg_list): |
| 48 | +# Convert each byte element in the list to str |
| 49 | +str_list= [six.text_type(item,'utf-8')ifisinstance(item,bytes)elsesix.text_type(item)foritemin |
| 50 | +msg_list] |
| 51 | + |
| 52 | +# Join the list into a single string with the specified delimiter |
| 53 | +returnsix.text_type('\n').join(str_list) |
| 54 | + |
| 55 | + |
| 56 | +@six.python_2_unicode_compatible |
| 57 | +classQueryException(TestgresException): |
| 58 | +def__init__(self,message=None,query=None): |
| 59 | +super(QueryException,self).__init__(message) |
| 60 | + |
| 61 | +self.message=message |
| 62 | +self.query=query |
| 63 | + |
| 64 | +def__str__(self): |
| 65 | +msg= [] |
| 66 | + |
| 67 | +ifself.message: |
| 68 | +msg.append(self.message) |
| 69 | + |
| 70 | +ifself.query: |
| 71 | +msg.append(u'Query: {}'.format(self.query)) |
| 72 | + |
| 73 | +returnsix.text_type('\n').join(msg) |
| 74 | + |
| 75 | + |
| 76 | +classTimeoutException(QueryException): |
| 77 | +pass |
| 78 | + |
| 79 | + |
| 80 | +classCatchUpException(QueryException): |
| 81 | +pass |
| 82 | + |
| 83 | + |
| 84 | +@six.python_2_unicode_compatible |
| 85 | +classStartNodeException(TestgresException): |
| 86 | +def__init__(self,message=None,files=None): |
| 87 | +super(StartNodeException,self).__init__(message) |
| 88 | + |
| 89 | +self.message=message |
| 90 | +self.files=files |
| 91 | + |
| 92 | +def__str__(self): |
| 93 | +msg= [] |
| 94 | + |
| 95 | +ifself.message: |
| 96 | +msg.append(self.message) |
| 97 | + |
| 98 | +forf,linesinself.filesor []: |
| 99 | +msg.append(u'{}\n----\n{}\n'.format(f,lines)) |
| 100 | + |
| 101 | +returnsix.text_type('\n').join(msg) |
| 102 | + |
| 103 | + |
| 104 | +classInitNodeException(TestgresException): |
| 105 | +pass |
| 106 | + |
| 107 | + |
| 108 | +classBackupException(TestgresException): |
| 109 | +pass |
| 110 | + |
| 111 | + |
| 112 | +classInvalidOperationException(TestgresException): |
| 113 | +pass |