ó ]ýhc@s{ddlmZyddlZWnek r?ddlZnXddlZddlZddlZddlZddl Z d„Z ddd„ƒYZ dZ de Z id d6d d6d d6d d 6d d 6Zddd„ƒYZd„Zd„Zd„Zed„Zd„Zd„Zedkrwyee jƒWqwek rsZedede jƒe jdƒqwXndS(iÿÿÿÿ(tprint_functionNcGs*|r||}nt|dtjƒdS(Ntfile(tprinttsyststderr(tmsgtargs((s7/home/andy/git/oils-for-unix/oils/web/table/csv2html.pytlog2s t NullSchemacBs>eZd„Zd„Zd„Zd„Zd„Zd„ZRS(cCsdS(N((tselft col_names((s7/home/andy/git/oils-for-unix/oils/web/table/csv2html.pytVerifyColumnNames9scCstS(N(tFalse(R tcol_name((s7/home/andy/git/oils-for-unix/oils/web/table/csv2html.pyt IsNumeric<scCstS(N(R (R tindex((s7/home/andy/git/oils-for-unix/oils/web/table/csv2html.pytColumnIndexIsNumeric?scCstS(N(R (R R((s7/home/andy/git/oils-for-unix/oils/web/table/csv2html.pytColumnIndexIsIntegerBscCstS(N(R (R R((s7/home/andy/git/oils-for-unix/oils/web/table/csv2html.pytColumnIndexHasHrefEscCstS(N(R (R ((s7/home/andy/git/oils-for-unix/oils/web/table/csv2html.pytHasCssClassColumnHs(t__name__t __module__R RRRRR(((s7/home/andy/git/oils-for-unix/oils/web/table/csv2html.pyR8s      tintegertdoubletfloattnumbertINTEGERtREALtTEXTtstringtSchemacBskeZd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z d „Z RS( cCsR|d}d|ks"t|ƒ‚d|ks:t|ƒ‚i}g|d}x5t|ƒD]'\}}||}||j|ƒq†WqsWtd„t|d|dƒDƒƒ|_td„t|d|dƒDƒƒ|_td „t|d|dƒDƒƒ|_d|_ d|_ ||_ dS( Nit column_namettypet precisiontstrftimeicss!|]\}}||fVqdS(N((t.0tnamett((s7/home/andy/git/oils-for-unix/oils/web/table/csv2html.pys oscss!|]\}}||fVqdS(N((R#R$tp((s7/home/andy/git/oils-for-unix/oils/web/table/csv2html.pys tscss!|]\}}||fVqdS(N((R#R$R&((s7/home/andy/git/oils-for-unix/oils/web/table/csv2html.pys xs( tAssertionErrort enumeratetappendtdicttzipt type_lookuptprecision_lookuptstrftime_lookuptNoneR t col_has_hrefts_cols(R trowstschema_col_namesR1trowtitcellR$((s7/home/andy/git/oils-for-unix/oils/web/table/csv2html.pyt__init__^s0      !!!  cCst|jd}|jd}g}xDt||ƒD]3\}}t|jƒ}|jd||fƒq0Wdj|ƒS(NRR s %s %ss, (R1R+t SQL_TYPEStlowerR)tjoin(R RttyptcolstnR%t sqlite_type((s7/home/andy/git/oils-for-unix/oils/web/table/csv2html.pytToSqlite„s  cCs}t|ƒ}tg||_xQt|dƒD]?}||||d}}|d|kr-t|j|tnums{:,}RJiÿÿÿÿ(tdatetimetisos{0:,.{precision}f}R!tNAtnas tends s%sss N(RJRO(tsplitR/tretcompileRARR)tsearchR:RRCRtintt ValueErrortformatRRRLRQt fromtimestampt isoformatR"RItstripthtmltescapeR(R4tschematcss_class_patternt row_class_pattrt cell_regexR5R=t row_classesR6tht css_classestcell_strtcell_intt cell_floattfmtRQR%R!tsthref((s7/home/andy/git/oils-for-unix/oils/web/table/csv2html.pytPrintRowÂsz               %  ( cCs¬tdƒx‘t|ƒD]ƒ\}}|dkrA|jƒrAqn|jdƒrVqn|j|ƒr~|j|ƒ r~d}nd}tdj||ƒƒqWtdƒdS( s9Print HTML colgroup element, used for JavaScript sorting.s iR@Rscase-insensitives s N(RR(RtendswithRRKR\(R RbR5tcolt css_class((s7/home/andy/git/oils-for-unix/oils/web/table/csv2html.pyt PrintColGroup*s  c CsZtd|ƒtdƒtdƒx–t|ƒD]ˆ\}}|dkrY|jƒrYq/n|jdƒrnq/ntj|jddƒƒ}|j|ƒr©td|ƒq/td |ƒq/Wtd ƒx.t|j ƒD]}t ||||j ƒqÕWtd ƒtd ƒx(||j D]}t |||j ƒqWtd ƒt ||ƒtdƒdS(Nss s iR@t_RNs s s s s s s
%s%s
( RR(RRqR`RatreplaceRRBt thead_offsetRpRcRt( tcss_idRbR R2toptsR5Rrt heading_strR4((s7/home/andy/git/oils-for-unix/oils/web/table/csv2html.pyt PrintTable>s,       cCs”|r-tj|dddtdtjƒ}ntj|ƒ}g}g}x?t|ƒD]1\}}|dkry|}qUn|j|ƒqUW||fS(s7Read the CSV file, returning the column names and rows.t delimiters t doublequotetquotingi(tcsvtreaderR t QUOTE_NONER(R)(tfttsvtcR R2R5R4((s7/home/andy/git/oils-for-unix/oils/web/table/csv2html.pytReadFile^s c Csžtjƒ}|jddddddddd ƒ|jd dd d td dddƒ|jdddddddƒ|jdddd dddddƒ|S(Ns--schematdestRbtmetavartPATHR tstrthelpsPath to the schema.s--tsvRƒtdefaulttactiont store_truesRead input in TSV formats--css-class-patternRcs„A string of the form CSS_CLASS:PATTERN. If the cell contents matches the pattern, then apply the given CSS class. Example: osh:^oshs--thead-offsetRwiRZs.Put more rows in the data in the thead section(toptparset OptionParsert add_optionR (R&((s7/home/andy/git/oils-for-unix/oils/web/table/csv2html.pytCreateOptionsParserrs cCsôtƒj|dƒ\}}y|d}Wntk rItdƒ‚nXd}|jr•yt|jƒ}Wqtk r‘}td|ƒ‚qXn~|jdƒr¹|j ddƒ}n0|jdƒrÝ|j ddƒ}n t |ƒ‚yt|ƒ}Wntk rd}nX|rm|j rIt j |d d d td t jƒ}nt j |ƒ}tt|ƒƒ}n tƒ}t|ƒ}t||j ƒ\} } WdQX|j| ƒtjj|ƒ} tjj| ƒ\} } t| || | |ƒdS( NiisExpected CSV filename.sError opening schema: %ss.csvs .schema.csvs.tsvs .schema.tsvR|s R}R~(R‘t parse_argst IndexErrort RuntimeErrorR/RbtopentIOErrorRqRvR'RƒRR€R RRtlistRR…R tostpathtbasenametsplitextR{(targvRytcsv_pathRbtschema_ftet schema_pathReR‚R R2tfilenameRxRu((s7/home/andy/git/oils-for-unix/oils/web/table/csv2html.pytmainˆsB        t__main__s FATAL: %sRi((R(RRR((t __future__RR`t ImportErrortcgiRRŽR˜RWRRRRGRFR8RRpRtR{R R…R‘R¢RRœR”RŸRRtexit(((s7/home/andy/git/oils-for-unix/oils/web/table/csv2html.pyts@%         e h    4