def _export_data_func(self, data, suffix=''): base_dir = gr.exported_data_folder dm = data.get_data_model() if dm: file_extension = dm.file_extension dm_name = dm.name else: file_extension = 'bin' dm_name = '__unknown_data_model' now = datetime.datetime.now() current_export_date = now.strftime("%Y_%m_%d_%H%M%S") if current_export_date != self.__prev_export_date: self.__prev_export_date = current_export_date self.__export_cpt = 0 else: self.__export_cpt += 1 export_fname = '{date:s}_{cpt:0>2d}{suff:s}.{ext:s}'.format(date=current_export_date, cpt=self.__export_cpt, ext=file_extension, suff=suffix) export_full_fn = os.path.join(base_dir, dm_name, export_fname) ensure_dir(export_full_fn) fd = open(export_full_fn, 'wb') fd.write(data.to_bytes()) fd.close() return export_full_fn
def _export_data_func(self, data, suffix=''): base_dir = os.path.join(app_folder, 'exported_data') dm = data.get_data_model() if dm: file_extension = dm.file_extension dm_name = dm.name else: file_extension = 'bin' dm_name = '__unknown_data_model' now = datetime.datetime.now() current_export_date = now.strftime("%Y_%m_%d_%H%M%S") if current_export_date != self.__prev_export_date: self.__prev_export_date = current_export_date self.__export_cpt = 0 else: self.__export_cpt += 1 export_fname = '{date:s}_{cpt:0>2d}{suff:s}.{ext:s}'.format(date=current_export_date, cpt=self.__export_cpt, ext=file_extension, suff=suffix) export_full_fn = os.path.join(base_dir, dm_name, export_fname) ensure_dir(export_full_fn) fd = open(export_full_fn, 'wb') fd.write(data.to_bytes()) fd.close() return export_full_fn
def export_data(self, first, last=None, colorized=True): colorize = self._get_color_function(colorized) if last is not None: records = self.execute_sql_statement( "SELECT ID, TYPE, DM_NAME, SENT_DATE, CONTENT FROM DATA " "WHERE {start:d} <= ID and ID <= {end:d};".format(start=first, end=last)) else: records = self.execute_sql_statement( "SELECT ID, TYPE, DM_NAME, SENT_DATE, CONTENT FROM DATA " "WHERE ID == {data_id:d};".format(data_id=first)) if records: base_dir = gr.exported_data_folder prev_export_date = None export_cpt = 0 for rec in records: data_id, data_type, dm_name, sent_date, content = rec file_extension = dm_name if sent_date is None: current_export_date = datetime.now().strftime( "%Y-%m-%d-%H%M%S") else: current_export_date = sent_date.strftime("%Y-%m-%d-%H%M%S") if current_export_date != prev_export_date: prev_export_date = current_export_date export_cpt = 0 else: export_cpt += 1 export_fname = '{typ:s}_{date:s}_{cpt:0>2d}.{ext:s}'.format( date=current_export_date, cpt=export_cpt, ext=file_extension, typ=data_type) export_full_fn = os.path.join(base_dir, dm_name, export_fname) ensure_dir(export_full_fn) with open(export_full_fn, 'wb') as fd: fd.write(content) print( colorize("Data ID #{:d} --> {:s}".format( data_id, export_full_fn), rgb=Color.FMKINFO)) else: print( colorize("*** ERROR: The provided DATA IDs do not exist ***", rgb=Color.ERROR))
def export_data(self, first, last=None, colorized=True): colorize = self._get_color_function(colorized) if last is not None: records = self.execute_sql_statement( "SELECT ID, TYPE, DM_NAME, SENT_DATE, CONTENT FROM DATA " "WHERE {start:d} <= ID and ID <= {end:d};".format(start=first, end=last) ) else: records = self.execute_sql_statement( "SELECT ID, TYPE, DM_NAME, SENT_DATE, CONTENT FROM DATA " "WHERE ID == {data_id:d};".format(data_id=first) ) if records: base_dir = gr.exported_data_folder prev_export_date = None export_cpt = 0 for rec in records: data_id, data_type, dm_name, sent_date, content = rec file_extension = dm_name if sent_date is None: current_export_date = datetime.now().strftime("%Y-%m-%d-%H%M%S") else: current_export_date = sent_date.strftime("%Y-%m-%d-%H%M%S") if current_export_date != prev_export_date: prev_export_date = current_export_date export_cpt = 0 else: export_cpt += 1 export_fname = '{typ:s}_{date:s}_{cpt:0>2d}.{ext:s}'.format( date=current_export_date, cpt=export_cpt, ext=file_extension, typ=data_type) export_full_fn = os.path.join(base_dir, dm_name, export_fname) ensure_dir(export_full_fn) with open(export_full_fn, 'wb') as fd: fd.write(content) print(colorize("Data ID #{:d} --> {:s}".format(data_id, export_full_fn), rgb=Color.FMKINFO)) else: print(colorize("*** ERROR: The provided DATA IDs do not exist ***", rgb=Color.ERROR))
fuddly_version = '0.25.2' framework_folder = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) # framework_folder = os.path.dirname(framework.__file__) framework_folder = '.' if framework_folder == '' else framework_folder app_folder = os.path.dirname(framework_folder) app_folder = '.' if app_folder == '' else app_folder projects_folder = app_folder + os.sep + 'projects' + os.sep data_models_folder = app_folder + os.sep + 'data_models' + os.sep fuddly_data_folder = os.path.expanduser('~' + os.sep + 'fuddly_data' + os.sep) if not os.path.exists(fuddly_data_folder): new_fuddly_data_folder = True ensure_dir(fuddly_data_folder) exported_data_folder = fuddly_data_folder + 'exported_data' + os.sep ensure_dir(exported_data_folder) imported_data_folder = fuddly_data_folder + 'imported_data' + os.sep ensure_dir(imported_data_folder) logs_folder = fuddly_data_folder + 'logs' + os.sep ensure_dir(logs_folder) workspace_folder = fuddly_data_folder + 'workspace' + os.sep ensure_dir(workspace_folder) external_libs_folder = fuddly_data_folder + 'external_libs' + os.sep ensure_dir(external_libs_folder) external_tools_folder = fuddly_data_folder + 'external_tools' + os.sep ensure_dir(external_tools_folder) user_projects_folder = fuddly_data_folder + 'user_projects' + os.sep
current_export_date = sent_date.strftime("%Y-%m-%d-%H%M%S") if current_export_date != prev_export_date: prev_export_date = current_export_date export_cpt = 0 else: export_cpt += 1 export_fname = '{typ:s}_{date:s}_{cpt:0>2d}.{ext:s}'.format( date=current_export_date, cpt=export_cpt, ext=file_extension, typ=data_type) export_full_fn = os.path.join(base_dir, dm_name, export_fname) ensure_dir(export_full_fn) with open(export_full_fn, 'wb') as fd: fd.write(content) print( colorize("Data ID #{:d} --> {:s}".format( data_id, export_full_fn), rgb=Color.FMKINFO)) else: print( colorize("*** ERROR: The provided DATA IDs do not exist ***", rgb=Color.ERROR)) elif remove_data is not None:
current_export_date = sent_date.strftime("%Y-%m-%d-%H%M%S") if current_export_date != prev_export_date: prev_export_date = current_export_date export_cpt = 0 else: export_cpt += 1 export_fname = '{typ:s}_{date:s}_{cpt:0>2d}.{ext:s}'.format(date=current_export_date, cpt=export_cpt, ext=file_extension, typ=data_type) export_full_fn = os.path.join(base_dir, dm_name, export_fname) ensure_dir(export_full_fn) with open(export_full_fn, 'wb') as fd: fd.write(content) print(colorize("Data ID #{:d} --> {:s}".format(data_id, export_full_fn), rgb=Color.FMKINFO)) else: print(colorize("*** ERROR: The provided DATA IDs do not exist ***", rgb=Color.ERROR)) elif remove_data is not None: data_id = remove_data data = handle_data_existence(data_id)