All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Public Attributes | Private Member Functions | List of all members
DataLoader3.DataLoader Class Reference
Inheritance diagram for DataLoader3.DataLoader:

Public Member Functions

def __init__
 
def addRow
 
def send
 
def clearRows
 
def __str__
 

Public Attributes

 password
 
 group
 
 url
 
 args
 
 urlWithArgs
 
 data
 

Private Member Functions

def __buildReq
 
def __signature
 

Detailed Description

Collects data intended for a hardware database table.  On command, the data
   is sent to a server for loading.

Definition at line 24 of file DataLoader3.py.

Constructor & Destructor Documentation

def DataLoader3.DataLoader.__init__ (   self,
  password,
  url,
  group,
  table 
)
Class constructor.

    Args:
 password - Agreed upon password - for the group.
 url - Http URL to the server used for loading.
 group - Group the table is part of.
 table - Postgresql database table data will be loaded into.

Definition at line 28 of file DataLoader3.py.

28 
29  def __init__(self, password, url, group, table):
30  """ Class constructor.
31 
32  Args:
33  password - Agreed upon password - for the group.
34  url - Http URL to the server used for loading.
35  group - Group the table is part of.
36  table - Postgresql database table data will be loaded into.
37  """
38  self.password = password
39  self.group = group
40  self.url = url
41  self.args = "table=%s" % table
42  self.urlWithArgs = "%s" % self.url
43  self.data = {'table': table.lower(),
44  'rows': []
45  }

Member Function Documentation

def DataLoader3.DataLoader.__buildReq (   self)
private

Definition at line 108 of file DataLoader3.py.

109  def __buildReq(self):
110  return req
def DataLoader3.DataLoader.__signature (   self,
  data,
  salt 
)
private

Definition at line 111 of file DataLoader3.py.

112  def __signature(self, data, salt):
113  m = hashlib.md5()
114  m.update(self.password.encode())
115  m.update(salt.encode())
116  m.update(data.encode())
117  return m.hexdigest()
def DataLoader3.DataLoader.__str__ (   self)

Definition at line 118 of file DataLoader3.py.

119  def __str__(self):
120  retVal = "URL: %s\nURL with Args: %s\nTable:%s\nPassword: XXXXX\nGroup:%s\n" % (
121  self.url, self.urlWithArgs, self.data['table'], self.group
122  )
123  rowCnt = 0
124  rows = self.data['rows']
125  if len(rows) == 0:
126  retVal += "Rows: None\n"
127  else:
128  for row in rows:
129  retVal += "Row %s:\n" % rowCnt
130  for column in list(row.keys()):
131  retVal += " %s: %s\n" % (column, str(row.get(column)))
132  rowCnt += 1
133  return retVal
134 
list
Definition: file_to_url.sh:28
def DataLoader3.DataLoader.addRow (   self,
  row,
  mode = 'insert' 
)
Adds a single row of data to the instance.  This row will be
    inserted or updated in the database.

    Args:
 row - a dictionary containing a name/value pair
       for each required table column.
 mode - insert or update

Definition at line 46 of file DataLoader3.py.

46 
47  def addRow(self, row, mode='insert'):
48  """ Adds a single row of data to the instance. This row will be
49  inserted or updated in the database.
50 
51  Args:
52  row - a dictionary containing a name/value pair
53  for each required table column.
54  mode - insert or update
55  """
56  if isinstance(row, dict) is False:
57  raise Exception("row must be a dictionary")
58  if mode not in ('insert', 'update'):
59  raise Exception("mode must be insert or update")
60  data = {k: (v.name, (lambda f: f.seek(0) or base64.b64encode(f.read()).decode())(v)) if isinstance(v, IOBase) else v for (k, v) in list(row.items())}
61  (self.data['rows']).append((mode, data))
void decode(std::any const &src, Interval< Args...> &iv)
Decodes an interval.
list
Definition: file_to_url.sh:28
def DataLoader3.DataLoader.clearRows (   self)
Deletes all rows from the instance, readying it for
    the next set of data.

Definition at line 102 of file DataLoader3.py.

103  def clearRows(self):
104  """ Deletes all rows from the instance, readying it for
105  the next set of data.
106  """
107  self.data['rows'] = []
def DataLoader3.DataLoader.send (   self,
  echoUrl = False 
)
Sends the data to the server for loading.

   Returns:
      Boolean indicating success and failure of the call.
      A code indicating Html return status.
      Text describing any error which returned.

Definition at line 62 of file DataLoader3.py.

62 
63  def send(self, echoUrl=False):
64  """Sends the data to the server for loading.
65 
66  Returns:
67  Boolean indicating success and failure of the call.
68  A code indicating Html return status.
69  Text describing any error which returned.
70  """
71  # Repeats if there is a collision on the salt.
72  while 1:
73  jdata = json.dumps(self.data)
74  random.seed(time.time())
75  salt = '%s' % (random.random(),)
76  sig = self.__signature(jdata, salt)
77  # The Request call is sending as a POST, not as a GET.
78  req = urllib.request.Request(self.urlWithArgs, jdata.encode(),
79  {'X-Salt': salt,
80  'X-Signature': sig,
81  'X-Group': self.group,
82  'X-Table': self.data['table']
83  })
84  if echoUrl:
85  print("URL: %s\n %s" % (req.get_full_url(), req.header_items()))
86  ssl_cert_file = os.environ.get("SSL_CERT_FILE")
87  try:
88  response = urllib.request.urlopen(req) if ssl_cert_file else urllib.request.urlopen(req, context=ssl.SSLContext())
89  except urllib.error.HTTPError as val:
90  if self.urlWithArgs.lower().startswith("https") and ssl_cert_file:
91  print("\n*** Please verify CA certificate provided with SSL_CERT_FILE environment variable!\n")
92  retValue = False
93  code = "%s %s" % (val.code, val.msg)
94  text = val.read()
95  else:
96  retValue = True
97  code = "%s %s" % (response.getcode(), response.msg)
98  text = response.read()
99  if text != "Signature Error":
100  break
101  return retValue, code, text
do one_file $F done echo for F in find $TOP name CMakeLists txt print

Member Data Documentation

DataLoader3.DataLoader.args

Definition at line 40 of file DataLoader3.py.

DataLoader3.DataLoader.data

Definition at line 42 of file DataLoader3.py.

DataLoader3.DataLoader.group

Definition at line 38 of file DataLoader3.py.

DataLoader3.DataLoader.password

Definition at line 37 of file DataLoader3.py.

DataLoader3.DataLoader.url

Definition at line 39 of file DataLoader3.py.

DataLoader3.DataLoader.urlWithArgs

Definition at line 41 of file DataLoader3.py.


The documentation for this class was generated from the following file: