def write_headers(self, file, cols): for file_col in cols: if file_col.not_in_db: if file_col.padding_override is not None: utils.write_string(file, file_col.value, default_pad=file_col.padding_override, direction=file_col.direction) else: utils.write_string(file, file_col.value, direction=file_col.direction) else: db_col = file_col.value name = db_col.name # if not file_col.is_desc: if file_col.alt_header_name != "": name = file_col.alt_header_name elif file_col.query_alias != "": name = file_col.query_alias elif db_col.verbose_name is not None: name = db_col.verbose_name name = name.lower() if file_col.repeat is not None: name += str(file_col.repeat) if file_col.is_desc: utils.write_desc_string(file, name) elif file_col.padding_override is not None: utils.write_string(file, name, default_pad=file_col.padding_override, direction=file_col.direction) elif isinstance(db_col, ForeignKeyField): utils.write_string(file, name, direction=file_col.direction) elif isinstance(db_col, IntegerField): utils.write_int(file, name, direction=file_col.direction) elif isinstance(db_col, DoubleField): utils.write_num(file, name, direction=file_col.direction) elif isinstance(db_col, BooleanField): utils.write_code(file, name, direction=file_col.direction) else: utils.write_string(file, name, direction=file_col.direction)
def write_row(self, file, cols): for file_col in cols: string_null = file_col.text_if_null if file_col.text_if_null is not None else utils.NULL_STR num_null = file_col.text_if_null if file_col.text_if_null is not None else utils.NULL_NUM if file_col.is_desc: utils.write_desc_string(file, file_col.value) elif file_col.padding_override is not None: if isinstance(file_col.value, int): utils.write_int(file, file_col.value, default_pad=file_col.padding_override, direction=file_col.direction) elif isinstance(file_col.value, float): utils.write_num(file, file_col.value, default_pad=file_col.padding_override, direction=file_col.direction, text_if_null=num_null, use_non_zero_min=file_col.use_non_zero_min) else: utils.write_string(file, file_col.value, default_pad=file_col.padding_override, direction=file_col.direction, text_if_null=string_null) elif isinstance(file_col.value, int): utils.write_int(file, file_col.value, direction=file_col.direction) elif isinstance(file_col.value, float): utils.write_num(file, file_col.value, direction=file_col.direction, text_if_null=num_null, use_non_zero_min=file_col.use_non_zero_min) elif isinstance(file_col.value, bool): utils.write_bool_yn(file, file_col.value, direction=file_col.direction, text_if_null=num_null) else: utils.write_string(file, file_col.value, direction=file_col.direction, text_if_null=string_null)
def write(self): is_lte = False c = config.Project_config.get_or_none() if c is not None: is_lte = c.is_lte classes = db.File_cio_classification.select().order_by( db.File_cio_classification.id) files = db.File_cio.select().order_by(db.File_cio.order_in_class) query = prefetch(classes, files) null_str = utils.NULL_STR with open(self.file_name, 'w') as file: self.write_meta_line(file) classifications = self.get_classifications(is_lte) for row in query: utils.write_string(file, row.name, direction="left") conditions = classifications.get(row.name, {}) for f in row.files: file_name = f.file_name if conditions.get( f.order_in_class, False) else null_str if file_name is None or file_name == "": file_name = null_str utils.write_string(file, file_name, direction="left") if len(row.files) < 1: utils.write_string(file, null_str, direction="left") file.write("\n")
def write(self): table = db.Print_prt if table.select().count() > 0: row = table.select().first() with open(self.file_name, 'w') as file: self.write_meta_line(file) header_cols = [col(table.nyskip, direction="left", padding_override=10), col(table.day_start, direction="left"), col(table.yrc_start, direction="left"), col(table.day_end, direction="left"), col(table.yrc_end, direction="left"), col(table.interval, direction="left")] self.write_headers(file, header_cols) file.write("\n") row_cols = [col(row.nyskip, direction="left", padding_override=10), col(row.day_start, direction="left"), col(row.yrc_start, direction="left"), col(row.day_end, direction="left"), col(row.yrc_end, direction="left"), col(row.interval, direction="left")] self.write_row(file, row_cols) file.write("\n") aa_int_cnt = len(row.aa_ints) file.write(utils.int_pad("aa_int_cnt", default_pad=10, direction="left")) file.write("\n") file.write(utils.int_pad(aa_int_cnt, default_pad=10, direction="left")) if aa_int_cnt > 0: for aa_int in row.aa_ints: file.write(utils.int_pad(aa_int, direction="left")) file.write("\n") header_cols = [col(table.csvout, direction="left"), col(table.dbout, direction="left"), col(table.cdfout, direction="left")] self.write_headers(file, header_cols) file.write("\n") utils.write_bool_yn(file, row.csvout, direction="left") utils.write_bool_yn(file, row.dbout, direction="left") utils.write_bool_yn(file, row.cdfout, direction="left") file.write("\n") header_cols = [col(table.soilout, direction="left"), col(table.mgtout, direction="left"), col(table.hydcon, direction="left"), col(table.fdcout, direction="left")] self.write_headers(file, header_cols) file.write("\n") utils.write_bool_yn(file, row.soilout, direction="left") utils.write_bool_yn(file, row.mgtout, direction="left") utils.write_bool_yn(file, row.hydcon, direction="left") utils.write_bool_yn(file, row.fdcout, direction="left") file.write("\n") obj_table = db.Print_prt_object header_cols = [col("objects", not_in_db=True, direction="left"), col(obj_table.daily), col(obj_table.monthly), col(obj_table.yearly), col(obj_table.avann)] self.write_headers(file, header_cols) file.write("\n") for obj in row.objects.order_by(obj_table.id): utils.write_string(file, obj.name, direction="left") utils.write_bool_yn(file, obj.daily) utils.write_bool_yn(file, obj.monthly) utils.write_bool_yn(file, obj.yearly) utils.write_bool_yn(file, obj.avann) file.write("\n")