Changeset 19399 for trunk/psModules
- Timestamp:
- Sep 5, 2008, 12:41:58 PM (18 years ago)
- Location:
- trunk/psModules/src/config
- Files:
-
- 2 edited
-
pmConfigDump.c (modified) (2 diffs)
-
pmConfigDump.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/config/pmConfigDump.c
r19047 r19399 106 106 107 107 108 bool pmConfigDump(const pmConfig *config, const pmFPA *source, const char * outroot)108 bool pmConfigDump(const pmConfig *config, const pmFPA *source, const char *filename) 109 109 { 110 110 PS_ASSERT_PTR_NON_NULL(config, false); 111 PS_ASSERT_STRING_NON_EMPTY(outroot, false); 112 113 pmFPAview *view = source ? pmFPAviewTop(source) : pmFPAviewAlloc(0);// View to top level 114 if (!view) { 115 psError(PS_ERR_UNKNOWN, false, "Unable to determine top view for FPA."); 116 return false; 117 } 118 119 pmFPALevel level = pmFPAviewLevel(view); // Level for view 120 const char *levelString; // String for level 121 switch (level) { 122 case PM_FPA_LEVEL_FPA: 123 levelString = "FPA"; 124 break; 125 case PM_FPA_LEVEL_CHIP: 126 levelString = "CHIP"; 127 break; 128 case PM_FPA_LEVEL_CELL: 129 levelString = "CELL"; 130 break; 131 default: 132 psError(PS_ERR_UNKNOWN, false, "Bad FPA level: %x", level); 133 psFree(view); 134 return false; 135 } 136 137 psMetadata *dumpRules = psMetadataLookupMetadata(NULL, config->system, "CONFIG.DUMP"); // Name rules 138 if (!dumpRules) { 139 psError(PS_ERR_UNKNOWN, false, "Unable to find CONFIG.DUMP in system configuration"); 140 psFree(view); 141 return false; 142 } 143 144 const char *rule = psMetadataLookupStr(NULL, dumpRules, levelString); // Rule for output file name 145 if (!rule) { 146 psError(PS_ERR_UNKNOWN, false, "Unable to find %s in CONFIG.DUMP in system configuration", 147 levelString); 148 psFree(view); 149 return false; 150 } 151 152 psString ruleCopy = psStringCopy(rule); // Copy of rule, so we can have our way with it 153 154 psStringSubstitute(&ruleCopy, outroot, "{OUTPUT}"); 155 156 if (strstr(ruleCopy, "{PROGRAM}")) { 157 // basename() is allowed to muck with the values, so need to copy 158 psString program = psStringCopy(config->program); // Copy of program name 159 const char *progName = basename(program); // Basename of program 160 psStringSubstitute(&ruleCopy, progName, "{PROGRAM}"); 161 psFree(program); 162 } 163 164 if (strstr(ruleCopy, "{TIMESTAMP}")) { 165 psTime *time = psTimeGetNow(PS_TIME_UTC); // Current time 166 psString timeString = psTimeToISO(time); // ISO-formatted time 167 psFree(time); 168 psStringSubstitute(&ruleCopy, timeString, "{TIMESTAMP}"); 169 psFree(timeString); 170 } 171 172 psString filename = pmFPANameFromRule(ruleCopy, source, view); // Filename for dump 173 psFree(ruleCopy); 174 psFree(view); 175 if (!filename) { 176 psError(PS_ERR_UNKNOWN, false, "Unable to determine dump filename"); 177 return false; 178 } 111 PS_ASSERT_STRING_NON_EMPTY(filename, false); 179 112 180 113 psString resolved = pmConfigConvertFilename(filename, config, true, false); // Resolved filename … … 182 115 if (!psMetadataConfigWrite(config->user, resolved)) { 183 116 psError(PS_ERR_IO, false, "Unable to dump configuration to %s", filename); 184 psFree(filename);185 117 psFree(resolved); 186 118 return false; 187 119 } 188 120 189 psFree(filename);190 121 psFree(resolved); 191 122 -
trunk/psModules/src/config/pmConfigDump.h
r19042 r19399 4 4 * @author Paul Price, IfA 5 5 * 6 * @version $Revision: 1. 2$ $Name: not supported by cvs2svn $7 * @date $Date: 2008-0 8-13 02:32:35$6 * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $ 7 * @date $Date: 2008-09-05 22:41:58 $ 8 8 * Copyright 2005-2006 Institute for Astronomy, University of Hawaii 9 9 */ … … 30 30 /// Dump the configuration to a file 31 31 /// 32 /// The output file is designated by the CONFIG.DUMP metadata in the system configuration, keyed by the FPA33 /// level of the supplied source. In addition to the standard concept interpolation, additional34 /// interpolations are defined: "{PROGRAM}" is interpolated to the program name, "{TIMESTAMP}" is interpolated35 /// to the current time (ISO format).36 32 bool pmConfigDump(const pmConfig *config, ///< Configuration to dump 37 const pmFPA *source, ///< Source FPA, defines the level for the file rule38 const char * outroot ///< Output rootname33 const pmFPA *source, ///< Source FPA, defines the level for the file rule 34 const char *filename ///< Output file name 39 35 ); 40 36
Note:
See TracChangeset
for help on using the changeset viewer.
