Coverage for src/P4OO/_Base.py: 82%

28 statements  

« prev     ^ index     » next       coverage.py v7.4.1, created at 2024-12-16 19:01 +0000

1###################################################################### 

2# Copyright (c)2011-2012,2024 David L. Armstrong. 

3# Copyright (c)2012, Cisco Systems, Inc. 

4# 

5# P4OO._Base.py 

6# 

7###################################################################### 

8 

9""" 

10Perforce _Base Class 

11 

12 P4OO._Base provides consistent construction and attribute handling 

13methods for all P4OO objects. 

14""" 

15 

16from P4 import P4 

17from dataclasses import dataclass, field 

18import logging 

19 

20 

21@dataclass(unsafe_hash=True) 

22class _P4OOBase: 

23 _p4Conn: P4 = field(default=None, compare=False, repr=False) 

24 p4PythonObj: P4 = field(default=None, compare=False, repr=False) 

25 

26 def _uniqueID(self): 

27 return id(self) 

28 

29 def _initialize(self): 

30 return 1 

31 

32 def _logError(self, *args): 

33 logging.error(args) 

34 

35 def _logWarning(self, *args): 

36 logging.warning(args) 

37 

38 def _logDebug(self, *args): 

39 logging.debug(args) 

40 

41 def _runCommand(self, cmdName, **kwargs): 

42 p4Conn = self._getP4Connection() 

43 

44 return p4Conn.runCommand(cmdName, **kwargs) 

45 

46 def _getP4Connection(self): 

47 from P4OO._P4Python import _P4OOP4Python 

48 

49# print(self.p4PythonObj) 

50 if self._p4Conn is None: 

51# my $p4SQLDbh = $self->_getAttr( 'p4SQLDbh' ); 

52 

53 if self.p4PythonObj is not None: 

54 self._p4Conn = _P4OOP4Python(**{"p4PythonObj": self.p4PythonObj}) 

55# elsif( defined( $p4SQLDbh ) ) 

56# { 

57# require P4::OO::_Connection::P4toDB; 

58# $p4Conn = P4::OO::_Connection::P4toDB->new('p4SQLDbh' => $self->_getAttr('p4SQLDbh')); 

59# } 

60 else: 

61 self._p4Conn = _P4OOP4Python() 

62 

63 return self._p4Conn