IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 29, 2010, 12:36:07 PM (16 years ago)
Author:
bills
Message:

add listing modes -listrun and -destreakedfile modes to magicdstool

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src/magicdstool.c

    r29570 r29611  
    4949static bool tocleanedfileMode(pxConfig *config);
    5050static bool setfiletoupdateMode(pxConfig *config);
     51static bool destreakedfileMode(pxConfig *config);
     52static bool listrunMode(pxConfig *config);
    5153
    5254static bool setmagicDSRunState(pxConfig *config, psS64 magic_id, psString extraSetString, psMetadata *where, const char *state);
     
    8789        MODECASE(MAGICDSTOOL_MODE_TOCLEANEDFILE,       tocleanedfileMode);
    8890        MODECASE(MAGICDSTOOL_MODE_SETFILETOUPDATE,     setfiletoupdateMode);
     91        MODECASE(MAGICDSTOOL_MODE_DESTREAKEDFILE,      destreakedfileMode);
     92        MODECASE(MAGICDSTOOL_MODE_LISTRUN,             listrunMode);
    8993        default:
    9094            psAbort("invalid option (this should not happen)");
     
    17481752
    17491753
     1754static bool destreakedfileMode(pxConfig *config)
     1755{
     1756    PS_ASSERT_PTR_NON_NULL(config, false);
     1757
     1758    psMetadata *where = psMetadataAlloc();
     1759
     1760    PXOPT_COPY_S64(config->args, where, "-magic_ds_id", "magic_ds_id", "==");
     1761    PXOPT_COPY_STR(config->args, where, "-component", "component", "==");
     1762    PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
     1763    PXOPT_COPY_STR(config->args, where, "-stage", "stage", "==");
     1764    PXOPT_COPY_S64(config->args, where, "-stage_id", "stage_id", "==");
     1765    PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "==");
     1766    pxAddLabelSearchArgs (config, where, "-label", "magicDSRun.label", "==");
     1767    PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false);
     1768
     1769    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     1770    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     1771
     1772
     1773    psString query = pxDataGet("magicdstool_destreakedfile.sql");
     1774    if (!query) {
     1775        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     1776        return false;
     1777    }
     1778
     1779    if (psListLength(where->list)) {
     1780        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1781        psStringAppend(&query, "\nWHERE %s", whereClause);
     1782        psFree(whereClause);
     1783    } else {
     1784        psError(PS_ERR_UNKNOWN, true, "search arguments are required");
     1785        return false;
     1786    }
     1787    psFree(where);
     1788
     1789    if (faulted) {
     1790        psStringAppend(&query, " AND magicDSFile.fault > 0");
     1791    }
     1792
     1793    // treat limit == 0 as "no limit"
     1794    if (limit) {
     1795        psString limitString = psDBGenerateLimitSQL(limit);
     1796        psStringAppend(&query, " %s", limitString);
     1797        psFree(limitString);
     1798    }
     1799
     1800    if (!p_psDBRunQuery(config->dbh, query)) {
     1801        psError(PS_ERR_UNKNOWN, false, "database error");
     1802        psFree(query);
     1803        return false;
     1804    }
     1805    psFree(query);
     1806
     1807    psArray *output = p_psDBFetchResult(config->dbh);
     1808    if (!output) {
     1809        psErrorCode err = psErrorCodeLast();
     1810        switch (err) {
     1811            case PS_ERR_DB_CLIENT:
     1812                psError(PXTOOLS_ERR_SYS, false, "database error");
     1813            case PS_ERR_DB_SERVER:
     1814                psError(PXTOOLS_ERR_PROG, false, "database error");
     1815            default:
     1816                psError(PXTOOLS_ERR_PROG, false, "unknown error");
     1817        }
     1818
     1819        return false;
     1820    }
     1821    if (!psArrayLength(output)) {
     1822        psTrace("magicdstool", PS_LOG_INFO, "no rows found");
     1823        psFree(output);
     1824        return true;
     1825    }
     1826
     1827    if (psArrayLength(output)) {
     1828        // negative simple so the default is true
     1829        if (!ippdbPrintMetadatas(stdout, output, "magicDSFile", !simple)) {
     1830            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1831            psFree(output);
     1832            return false;
     1833        }
     1834    }
     1835
     1836    psFree(output);
     1837
     1838    return true;
     1839}
     1840static bool listrunMode(pxConfig *config)
     1841{
     1842    PS_ASSERT_PTR_NON_NULL(config, false);
     1843
     1844    psMetadata *where = psMetadataAlloc();
     1845
     1846    PXOPT_COPY_S64(config->args, where, "-magic_ds_id", "magic_ds_id", "==");
     1847    PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
     1848    PXOPT_COPY_STR(config->args, where, "-stage", "stage", "==");
     1849    PXOPT_COPY_S64(config->args, where, "-stage_id", "stage_id", "==");
     1850    PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "==");
     1851    pxAddLabelSearchArgs (config, where, "-label", "magicDSRun.label", "==");
     1852
     1853    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     1854    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     1855
     1856
     1857    psString query = pxDataGet("magicdstool_listrun.sql");
     1858    if (!query) {
     1859        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     1860        return false;
     1861    }
     1862
     1863    if (psListLength(where->list)) {
     1864        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1865        psStringAppend(&query, "\nWHERE %s", whereClause);
     1866        psFree(whereClause);
     1867    } else {
     1868        psError(PS_ERR_UNKNOWN, true, "search arguments are required");
     1869        return false;
     1870    }
     1871    psFree(where);
     1872
     1873    // treat limit == 0 as "no limit"
     1874    if (limit) {
     1875        psString limitString = psDBGenerateLimitSQL(limit);
     1876        psStringAppend(&query, " %s", limitString);
     1877        psFree(limitString);
     1878    }
     1879
     1880    if (!p_psDBRunQuery(config->dbh, query)) {
     1881        psError(PS_ERR_UNKNOWN, false, "database error");
     1882        psFree(query);
     1883        return false;
     1884    }
     1885    psFree(query);
     1886
     1887    psArray *output = p_psDBFetchResult(config->dbh);
     1888    if (!output) {
     1889        psErrorCode err = psErrorCodeLast();
     1890        switch (err) {
     1891            case PS_ERR_DB_CLIENT:
     1892                psError(PXTOOLS_ERR_SYS, false, "database error");
     1893            case PS_ERR_DB_SERVER:
     1894                psError(PXTOOLS_ERR_PROG, false, "database error");
     1895            default:
     1896                psError(PXTOOLS_ERR_PROG, false, "unknown error");
     1897        }
     1898
     1899        return false;
     1900    }
     1901    if (!psArrayLength(output)) {
     1902        psTrace("magicdstool", PS_LOG_INFO, "no rows found");
     1903        psFree(output);
     1904        return true;
     1905    }
     1906
     1907    if (psArrayLength(output)) {
     1908        // negative simple so the default is true
     1909        if (!ippdbPrintMetadatas(stdout, output, "magicDSRun", !simple)) {
     1910            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1911            psFree(output);
     1912            return false;
     1913        }
     1914    }
     1915
     1916    psFree(output);
     1917
     1918    return true;
     1919}
Note: See TracChangeset for help on using the changeset viewer.