IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 5, 2008, 12:41:58 PM (18 years ago)
Author:
bills
Message:

Get configuration dump file name from command line option. If no file
is provided, no dump is created

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/config/pmConfigDump.c

    r19047 r19399  
    106106
    107107
    108 bool pmConfigDump(const pmConfig *config, const pmFPA *source, const char *outroot)
     108bool pmConfigDump(const pmConfig *config, const pmFPA *source, const char *filename)
    109109{
    110110    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);
    179112
    180113    psString resolved = pmConfigConvertFilename(filename, config, true, false); // Resolved filename
     
    182115    if (!psMetadataConfigWrite(config->user, resolved)) {
    183116        psError(PS_ERR_IO, false, "Unable to dump configuration to %s", filename);
    184         psFree(filename);
    185117        psFree(resolved);
    186118        return false;
    187119    }
    188120
    189     psFree(filename);
    190121    psFree(resolved);
    191122
Note: See TracChangeset for help on using the changeset viewer.