Ejemplo n.º 1
0
def __update_sysctl_file_suse():
  """
  Updates /etc/sysctl.conf file with the HAWQ parameters on SUSE.
  """
  # Backup file
  backup_file_name = hawq_constants.sysctl_backup_file.format(str(int(time.time())))
  try:
    # Generate file with kernel parameters needed by hawq to temp file
    File(hawq_constants.hawq_sysctl_tmp_file, content=__convert_sysctl_dict_to_text(), owner=hawq_constants.hawq_user,
        group=hawq_constants.hawq_group)

    sysctl_file_dict = utils.read_file_to_dict(hawq_constants.sysctl_suse_file)
    sysctl_file_dict_original = sysctl_file_dict.copy()
    hawq_sysctl_dict = utils.read_file_to_dict(hawq_constants.hawq_sysctl_tmp_file)

    # Merge common system file with hawq specific file
    sysctl_file_dict.update(hawq_sysctl_dict)

    if sysctl_file_dict_original != sysctl_file_dict:
      # Backup file
      Execute("cp {0} {1}".format(hawq_constants.sysctl_suse_file, backup_file_name), timeout=hawq_constants.default_exec_timeout)
      # Write merged properties to file
      utils.write_dict_to_file(sysctl_file_dict, hawq_constants.sysctl_suse_file)
      # Reload kernel sysctl parameters from /etc/sysctl.conf
      Execute("sysctl -e -p", timeout=hawq_constants.default_exec_timeout)

  except Exception as e:
    Logger.error("Error occurred while updating sysctl.conf file, reverting the contents" + str(e))
    Execute("cp {0} {1}".format(hawq_constants.sysctl_suse_file, hawq_constants.hawq_sysctl_tmp_file))
    Execute("mv {0} {1}".format(backup_file_name, hawq_constants.sysctl_suse_file), timeout=hawq_constants.default_exec_timeout)
    Logger.error("Please execute `sysctl -e -p` on the command line manually to reload the contents of file {0}".format(
      hawq_constants.hawq_sysctl_tmp_file))
    raise Fail("Failed to update sysctl.conf file ")
Ejemplo n.º 2
0
def __update_sysctl_file_suse():
  """
  Updates /etc/sysctl.conf file with the HAWQ parameters on SUSE.
  """
  # Backup file
  backup_file_name = hawq_constants.sysctl_backup_file.format(str(int(time.time())))
  try:
    # Generate file with kernel parameters needed by hawq to temp file
    File(hawq_constants.hawq_sysctl_tmp_file, content=__convert_sysctl_dict_to_text(), owner=hawq_constants.hawq_user,
        group=hawq_constants.hawq_group)

    sysctl_file_dict = utils.read_file_to_dict(hawq_constants.sysctl_suse_file)
    sysctl_file_dict_original = sysctl_file_dict.copy()
    hawq_sysctl_dict = utils.read_file_to_dict(hawq_constants.hawq_sysctl_tmp_file)

    # Merge common system file with hawq specific file
    sysctl_file_dict.update(hawq_sysctl_dict)

    if sysctl_file_dict_original != sysctl_file_dict:
      # Backup file
      Execute("cp {0} {1}".format(hawq_constants.sysctl_suse_file, backup_file_name), timeout=hawq_constants.default_exec_timeout)
      # Write merged properties to file
      utils.write_dict_to_file(sysctl_file_dict, hawq_constants.sysctl_suse_file)
      # Reload kernel sysctl parameters from /etc/sysctl.conf
      Execute("sysctl -e -p", timeout=hawq_constants.default_exec_timeout)

  except Exception as e:
    Logger.error("Error occurred while updating sysctl.conf file, reverting the contents" + str(e))
    Execute("cp {0} {1}".format(hawq_constants.sysctl_suse_file, hawq_constants.hawq_sysctl_tmp_file))
    Execute("mv {0} {1}".format(backup_file_name, hawq_constants.sysctl_suse_file), timeout=hawq_constants.default_exec_timeout)
    Logger.error("Please execute `sysctl -e -p` on the command line manually to reload the contents of file {0}".format(
      hawq_constants.hawq_sysctl_tmp_file))
    raise Fail("Failed to update sysctl.conf file ")
Ejemplo n.º 3
0
 def create_split_record(self, files, split_name):
     count = 0
     test_filename = os.path.join(self.output_path,
                                  f'{split_name}.tfrecords')
     with tf.python_io.TFRecordWriter(test_filename) as writer:
         for file in files:
             examples = self.reader.read(os.path.join(
                 self.input_path, file))
             count += len(examples)
             for example in examples:
                 writer.write(
                     self.get_tf_example(example).SerializeToString())
     info_filename = os.path.join(self.output_path, split_name)
     write_dict_to_file(info_filename, {'count': count, 'files': files})
Ejemplo n.º 4
0
 def create_record(self):
     count = 0
     test_filename = os.path.join(self.output_path, 'dataset.tfrecords')
     with tf.python_io.TFRecordWriter(test_filename) as writer:
         i = 1
         for file in self.files:
             print(f"{i}/{len(self.files)}", flush=True)
             examples = self.reader.read(os.path.join(
                 self.input_path, file))
             count += len(examples)
             i = i + 1
             for example in examples:
                 writer.write(
                     self.get_tf_example(example).SerializeToString())
     info_filename = os.path.join(self.output_path, 'info.json')
     write_dict_to_file(info_filename, {
         'count': count,
         'files': self.files
     })
Ejemplo n.º 5
0
    def save_state(self, filename=None):
        assert self.loadfile is not None or filename is not None
        if filename is None:
            filename = self.loadfile

        d = {}
        d['on'] = self.on
        d['mode'] = int(self.mode)
        d['h'] = self.h
        d['s'] = self.s
        d['brightness'] = self.brightness
        d['degrees'] = self.degrees
        d['r'] = self.r
        d['g'] = self.g
        d['b'] = self.b
        d['group_name'] = self.group_name
        d['names'] = self.names

        write_dict_to_file(filename, d)