def WriteMD5(stage_dir, parent=None): CMD_md5sum = GetExecutable(u'md5sum') # Show an error if the 'md5sum' command does not exist # This is only a failsafe & should never actually occur if not CMD_md5sum: if not parent: parent = GetMainWindow() md5_label = GetField(pgid.BUILD, chkid.MD5).GetLabel() err_msg1 = GT(u'The "md5sum" command was not found on the system.') err_msg2 = GT(u'Uncheck the "{}" box.').format(md5_label) err_msg3 = GT( u'Please report this error to one of the following addresses:') err_url1 = u'https://github.com/AntumDeluge/debreate/issues' err_url2 = u'https://sourceforge.net/p/debreate/bugs/' Logger.Error( __name__, u'{} {} {}\n\t{}\n\t{}'.format(err_msg1, err_msg2, err_msg3, err_url1, err_url2)) md5_error = ErrorDialog(parent, text=u'{}\n{}\n\n{}'.format( err_msg1, err_msg2, err_msg3)) md5_error.AddURL(err_url1) md5_error.AddURL(err_url2) md5_error.ShowModal() return None temp_list = [] md5_list = [] # Final list used to write the md5sum file for ROOT, DIRS, FILES in os.walk(stage_dir): # Ignore the 'DEBIAN' directory if os.path.basename(ROOT) == u'DEBIAN': continue for F in FILES: F = u'{}/{}'.format(ROOT, F) md5 = GetCommandOutput(CMD_md5sum, (u'-t', F)) Logger.Debug(__name__, u'WriteMD5: GetCommandOutput: {}'.format(md5)) temp_list.append(md5) for item in temp_list: # Remove [stage_dir] from the path name in the md5sum so that it has a # true unix path # e.g., instead of "/myfolder_temp/usr/local/bin", "/usr/local/bin" sum_split = item.split(u'{}/'.format(stage_dir)) sum_join = u''.join(sum_split) md5_list.append(sum_join) # Create the md5sums file in the "DEBIAN" directory return WriteFile(u'{}/DEBIAN/md5sums'.format(stage_dir), u'{}\n'.format(u'\n'.join(md5_list)))
def Export(self, out_dir, executable=True, build=False): if not os.path.isdir(out_dir): Logger.Error(__name__, GT(u'Directory not available: {}'.format(out_dir))) return (ERR_DIR_NOT_AVAILABLE, __name__) if build: absolute_filename = ConcatPaths((out_dir, self.FileName)) else: filename = u'{}-{}'.format(page_ids[self.Parent.GetId()].upper(), self.FileName) absolute_filename = ConcatPaths((out_dir, filename)) script_text = u'{}\n\n{}'.format(self.GetShebang(), self.ScriptBody.GetValue()) WriteFile(absolute_filename, script_text) if not os.path.isfile(absolute_filename): Logger.Error(__name__, GT(u'Could not write to file: {}'.format(absolute_filename))) return (ERR_FILE_WRITE, __name__) if executable: os.chmod(absolute_filename, 0755) return (0, None)
def ExportDeprecated(self, outDir, outName=wx.EmptyString): if not os.path.isdir(outDir): Logger.Debug(__name__, u'Directory does not exist: {}'.format(outDir)) return ERR_DIR_NOT_AVAILABLE if outName == wx.EmptyString: outName = page_ids[self.GetId()].upper() page_info = self.Get() if not page_info: return 0 if not outName: outName = self.Name if TextIsEmpty(page_info): return 0 absolute_filename = u'{}/{}'.format(outDir, outName) Logger.Debug(outName, u'Exporting: {}'.format(absolute_filename)) WriteFile(absolute_filename, page_info) return 0
def OnSave(self, event=None): # Get data to write to control file control = self.GetCtrlInfo() save_dialog = GetFileSaveDialog(GetMainWindow(), GT(u'Save Control Information')) save_dialog.SetFilename(u'control') if ShowDialog(save_dialog): # Be sure not to strip trailing newline (dpkg is picky) WriteFile(save_dialog.GetPath(), control, noStrip=u'\n')
def UpdateDistNamesCache(unstable=True, obsolete=False, generic=False): global FILE_distnames debian_distnames = _get_debian_distnames(unstable, obsolete, generic) ubuntu_distnames = _get_ubuntu_distnames(unstable, obsolete) mint_distnames = _get_mint_distnames() section_debian = u'[DEBIAN]\n{}'.format(u'\n'.join(debian_distnames)) section_ubuntu = u'[UBUNTU]\n{}'.format(u'\n'.join(ubuntu_distnames)) section_mint = u'[LINUX MINT]\n{}'.format(u'\n'.join(mint_distnames)) return WriteFile( FILE_distnames, u'\n\n'.join( (section_debian, section_ubuntu, section_mint)))
def ExportBuild(self, target, installedSize=0): self.Export(target, u'control') absolute_filename = ConcatPaths((target, u'control')) if not os.path.isfile(absolute_filename): return GT(u'Control file was not created') if installedSize: control_data = ReadFile(absolute_filename, split=True, convert=list) size_line = u'Installed-Size: {}'.format(installedSize) if len(control_data) > 3: control_data.insert(3, size_line) else: control_data.append(size_line) # Be sure not to strip trailing newline (dpkg is picky) WriteFile(absolute_filename, control_data, noStrip=u'\n') return GT(u'Control file created: {}').format(absolute_filename)
def WriteConfig(k_name, k_value, conf=default_config, sectLabel=None): conf_dir = os.path.dirname(conf) if not os.path.isdir(conf_dir): if os.path.exists(conf_dir): print(u'{}: {}: {}'.format( GT(u'Error'), GT(u'Cannot create config directory, file exists'), conf_dir)) return ConfCode.ERR_WRITE os.makedirs(conf_dir) # Only write pre-defined keys if k_name not in default_config_values: print(u'{}: {}: {}'.format(GT(u'Error'), GT(u'Configuration key not found'), k_name)) return ConfCode.KEY_NOT_DEFINED # Make sure we are writing the correct type k_value = default_config_values[k_name][0](k_value) if k_value == None: print(u'{}: {}: {}'.format( GT(u'Error'), GT(u'Wrong value type for configuration key'), k_name)) return ConfCode.WRONG_TYPE # tuple is the only type we need to format if isinstance(k_value, tuple): k_value = u'{},{}'.format(GS(k_value[0]), GS(k_value[1])) else: k_value = GS(k_value) conf_text = wx.EmptyString # Save current config to buffer if os.path.exists(conf): if not os.path.isfile(conf): print(u'{}: {}: {}'.format( GT(u'Error'), GT(u'Cannot open config for writing, directory exists'), conf)) return ConfCode.ERR_WRITE conf_text = ReadFile(conf) # FIXME: ReadFile returns None type if config file exists but is empty if conf_text == None: conf_text = u'' else: conf_text = u'[CONFIG-{}.{}]'.format(GS(config_version[0]), GS(config_version[1])) conf_lines = conf_text.split(u'\n') key_exists = False for L in conf_lines: l_index = conf_lines.index(L) if u'=' in L: key = L.split(u'=')[0] if k_name == key: key_exists = True conf_lines[l_index] = u'{}={}'.format(k_name, k_value) if not key_exists: conf_lines.append(u'{}={}'.format(k_name, k_value)) conf_text = u'\n'.join(conf_lines) if TextIsEmpty(conf_text): print(u'{}: {}'.format(GT(u'Warning'), GT(u'Not writing empty text to configuration'))) return ConfCode.ERR_WRITE # Actual writing to configuration WriteFile(conf, conf_text) if os.path.isfile(conf): return ConfCode.SUCCESS return ConfCode.ERR_WRITE
def Export(self, target): page_data = self.Get() return WriteFile(target, page_data)
def ExportToFile(self, target, executable=False): launcher = self.GetLauncherInfo() WriteFile(target, launcher) return SetFileExecutable(target)