• Publicity: Public Only All

package-procs.tcl

Definition of package procs for xolirc Integration for displaying eggdrop ( log2thml ) logs

Location:
packages/xolirc/tcl/package-procs.tcl
Created:
2009-10-05
Author:
Victor Guerra <vguerra@vguerra.net>
CVS Identification:
$Id$

Procedures in this file

Detailed information

xolirc::Package proc create-page-from-log (public)

 xolirc::Package[i] create-page-from-log [ -overwrite overwrite ] \
    [ -date date ]
Switches:
-overwrite
(defaults to "1") (optional)
Indicates if the content of the page will be overwritted in case the page exists already.
-date
(optional)
Indicates the date of the log html files to read from.

Partial Call Graph (max 5 caller/called nodes):
%3 apm_package_ids_from_key apm_package_ids_from_key (public) db_dml db_dml (public) parameter::get parameter::get (public) parameter::set_value parameter::set_value (public) xolirc::Package proc create-page-from-log xolirc::Package proc create-page-from-log xolirc::Package proc create-page-from-log->apm_package_ids_from_key xolirc::Package proc create-page-from-log->db_dml xolirc::Package proc create-page-from-log->parameter::get xolirc::Package proc create-page-from-log->parameter::set_value

Testcases:
No testcase defined.

xolirc::Package proc process-all-logs (public)

 xolirc::Package[i] process-all-logs [ -overwrite overwrite ]

Goes through all the log files and creates the respective xowiki Page.

Switches:
-overwrite
(defaults to "1") (optional)
In case that the page exists for the processing date, this parameter if overwrite it (1) or not (0).

Partial Call Graph (max 5 caller/called nodes):
%3

Testcases:
No testcase defined.
[ hide source ] | [ make this the default ]

Content File Source

ad_library {
    
    Definition of package procs for xolirc 
    Integration for displaying eggdrop ( log2thml ) logs
    
    @author Victor Guerra (vguerra@vguerra.net)
    @creation-date 2009-10-05
    @cvs-id $Id$
}

::xo::library require -package xowiki package-procs

namespace eval ::xolirc {
    
    ::xo::PackageMgr create ::xolirc::Package \
    -package_key "xolirc" \
    -pretty_name "IRC Logs displayer based on Xowiki" \
    -superclass ::xowiki::Package 
    
    Package instproc initialize {} {
    my set logs_path "/usr/local/eggdrop/html/"
    }
    
    Package instproc query-actual-log {} {
    }
    
    Package instproc get-html-from-log {{-date ""}} {
    my instvar logs_path
    if {$date eq ""} {
        set date [clock format [clock seconds] -format "%Y%m%d"]
    }
    set content ""
    foreach log [lsort -dictionary [glob -nocomplain -directory $logs_path "openacs${date}*"]] {
        # We get the content of the div with id=mainblock that contains all the html 
        # that we need to fill with the xowiki pages
        set file [open $log]
        set html [read $file] ; close $file
        regexp "<body class=\"l2hLogPage\">(.*)<\/body>" $html body
        set doc [dom parse -html $body]
        set body [$doc documentElement]
        set navtop [$body selectNodes "div/div/div\[@id='navtop'\]"]
        $navtop delete
        append content "[[$body selectNodes div/div\[@id='mainblock'\]] asHTML]"
        $doc delete
    }
    return $content
    }
    
    Package instproc dash-date {{date}} {
    return "[string range $date 0 3]-[string range $date 4 5]-[string range $date 6 7]"
    }
    
    Package ad_proc process-all-logs {
    {-overwrite 1}
    } {
    Goes through all the log files and creates the respective xowiki Page.
    
    @param overwrite In case that the page exists for the processing date, this parameter if overwrite it (1) or not (0).
    } {    
    #my instvar logs_path
    set logs_path "/usr/local/eggdrop/html/"
    foreach log [glob -nocomplain -directory $logs_path "openacs*_pg1.html"] {
        regexp {.*openacs(\d{8})_pg1\.html} $log match date
        ns_log notice "working on $date"
        ::xolirc::Package create-page-from-log -overwrite $overwrite -date $date
        
    }
    }

    Package ad_proc create-page-from-log {
    {-overwrite 1}
    {-date ""}
    } {
    
    @param overwrite Indicates if the content of the page will be overwritted in case the page exists already.
    @param date Indicates the date of the log html files to read from.
    } {
    set package_id [apm_package_ids_from_key -mounted -package_key xolirc]
    ::xolirc::Package initialize \
        -package_id $package_id \
        -init_url 0 -actual_query ""
    
    if {$date ne ""} {
        regsub -all -- "-" $date {} date 
    } else {
        set date [parameter::get -package_id $package_id \
              -parameter "date2process" \
              -default [clock format [clock seconds] -format "%Y%m%d"]]
        #ns_log notice "about to process $date"
        parameter::set_value -package_id $package_id \
        -parameter "date2process" \
        -value [clock format [clock seconds] -format "%Y%m%d"]
    }
    #ns_log notice "vguerra the date is $date"
    set text [$package_id get-html-from-log -date $date]
    if { $text eq "" } {
        ns_log Warning "xolirc: Nothing has been logged yet for the date [$package_id dash-date $date]"
        return ""
    }    
    
    set page [$package_id resolve_page_name "en:$date"]
    if {$page eq ""} {
        set page [::xowiki::Page new \
              -title "Conversation log in #openacs on [$package_id dash-date $date]" \
              -name "en:$date" \
              -package_id $package_id \
              -parent_id [$package_id folder_id] \
              -destroy_on_cleanup \
              -text [list $text]]
        $page initialize_loaded_object
        $page save_new
    } elseif$overwrite } {
        $page set text [list $text]
        $page save
    }
    set creation_date "[$package_id dash-date $date]"
    db_dml update_date "update acs_objects set creation_date = :creation_date where object_id = [$page set revision_id]"
    }
}