Ignore:
Timestamp:
Jul 7, 2009, 8:20:59 AM (11 years ago)
Author:
enl@…
Message:

Merge from trunk + little code cleanups

Location:
branches/gsoc09-logging/base
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/gsoc09-logging/base

  • branches/gsoc09-logging/base/portmgr/jobs/PortIndex2MySQL.tcl

    r52218 r53509  
    4949# (which updates the ports tree in use) and by installing the script on cron/launchd to be
    5050# run on a timely schedule (not any more frequent than the run of the PortIndexRegen.sh
    51 # script on that creates a new PortIndex file, which is every twelve hours).
     51# script on that creates a new PortIndex file).
    5252#
    5353# Remaining requirement to successfully run this script is performing the necessary
     
    7373set HEADERS "To: $SPAM_LOVERS\r\nFrom: $FROM\r\nSubject: $SUBJECT\r\n\r\n"
    7474
    75 # We first initialize the runlog with proper mail headers
    76 puts $runlog_fd $HEADERS
     75# handle command line arguments
     76set create_tables false
     77if {[llength $argv]} {
     78    if {[lindex $argv 0] == "--create-tables"} {
     79        set create_tables true
     80    }
     81}
    7782
    7883# House keeping on exit.
     
    96101    cleanup runlog
    97102    exit $exit_status
    98 }
    99 
    100 # Check if there are any stray sibling jobs before moving on, bail in such case.
    101 if {[file exists $lockfile]} {
    102     puts $runlog_fd "PortIndex2MySQL lock file found, is another job running?"
    103     terminate 1
    104 } else {
    105     set lockfile_fd [open $lockfile a]
    106 }
    107 
    108 
    109 # Load macports1.0 so that we can use some of its procs and the portinfo array.
    110 if {[catch { source [file join "@TCL_PACKAGE_DIR@" macports1.0 macports_fastload.tcl] } errstr]} {
    111     puts $runlog_fd "${::errorInfo}"
    112     puts $runlog_fd "Failed to locate the macports1.0 Tcl package file: $errstr"
    113     cleanup lockfile
    114     terminate 1
    115 }
    116 if {[catch { package require macports } errstr]} {
    117     puts $runlog_fd "${::errorInfo}"
    118     puts $runlog_fd "Failed to load the macports1.0 Tcl package: $errstr"
    119     cleanup lockfile
    120     terminate 1
    121103}
    122104
     
    158140}
    159141
     142# Procedure to catch the database password from a protected file.
     143proc getpasswd {passwdfile} {
     144    if {[catch {open $passwdfile r} passwdfile_fd]} {
     145        global lockfile lockfile_fd
     146        ui_error "${::errorCode}: $passwdfile_fd"
     147        cleanup lockfile
     148        terminate 1
     149    }
     150    if {[gets $passwdfile_fd passwd] <= 0} {
     151        global lockfile lockfile_fd
     152        close $passwdfile_fd
     153        ui_error "No password found in password file $passwdfile!"
     154        cleanup lockfile
     155        terminate 1
     156    }
     157    close $passwdfile_fd
     158    return $passwd
     159}
     160
     161# SQL string escaping.
     162proc sql_escape {str} {
     163    regsub -all -- {'} $str {\\'} str
     164    regsub -all -- {"} $str {\\"} str
     165    regsub -all -- {\n} $str {\\n} str
     166    return $str
     167}
     168
     169# We first initialize the runlog with proper mail headers
     170puts $runlog_fd $HEADERS
     171
     172# Check if there are any stray sibling jobs before moving on, bail in such case.
     173if {[file exists $lockfile]} {
     174    puts $runlog_fd "PortIndex2MySQL lock file found, is another job running?"
     175    terminate 1
     176} else {
     177    set lockfile_fd [open $lockfile a]
     178}
     179
     180# Load macports1.0 so that we can use some of its procs and the portinfo array.
     181if {[catch { source [file join "/Library/Tcl" macports1.0 macports_fastload.tcl] } errstr]} {
     182    puts $runlog_fd "${::errorInfo}"
     183    puts $runlog_fd "Failed to locate the macports1.0 Tcl package file: $errstr"
     184    cleanup lockfile
     185    terminate 1
     186}
     187if {[catch { package require macports } errstr]} {
     188    puts $runlog_fd "${::errorInfo}"
     189    puts $runlog_fd "Failed to load the macports1.0 Tcl package: $errstr"
     190    cleanup lockfile
     191    terminate 1
     192}
     193
    160194# Initialize macports1.0 and its UI, in order to find the sources.conf file
    161195# (which is what will point us to the PortIndex we're gonna use) and use
     
    170204
    171205
    172 # Procedure to catch the database password from a protected file.
    173 proc getpasswd {passwdfile} {
    174     if {[catch {open $passwdfile r} passwdfile_fd]} {
    175         global lockfile lockfile_fd
    176         ui_error "${::errorCode}: $passwdfile_fd"
    177         cleanup lockfile
    178         terminate 1
    179     }
    180     if {[gets $passwdfile_fd passwd] <= 0} {
    181         global lockfile lockfile_fd
    182         close $passwdfile_fd
    183         ui_error "No password found in password file $passwdfile!"
    184         cleanup lockfile
    185         terminate 1
    186     }
    187     close $passwdfile_fd
    188     return $passwd
    189 }
    190 
    191206# Database abstraction variables:
    192207set sqlfile "/tmp/portsdb.sql"
     
    223238}
    224239
    225 
    226 # SQL string escaping.
    227 proc sql_escape {str} {
    228     regsub -all -- {'} $str {\\'} str
    229     regsub -all -- {"} $str {\\"} str
    230     regsub -all -- {\n} $str {\\n} str
    231     return $str
    232 }
    233 
    234 # Initial creation of database tables: log, portfiles, categories, maintainers, dependencies, variants and platforms.
    235 # Do we need any other?
    236 puts $sqlfile_fd "DROP TABLE IF EXISTS log;"
    237 puts $sqlfile_fd "CREATE TABLE log (activity VARCHAR(255), activity_time TIMESTAMP(14)) DEFAULT CHARSET=utf8;"
    238 
    239 puts $sqlfile_fd "DROP TABLE IF EXISTS portfiles;"
    240 puts $sqlfile_fd "CREATE TABLE portfiles (name VARCHAR(255) PRIMARY KEY NOT NULL, path VARCHAR(255), version VARCHAR(255),  description TEXT) DEFAULT CHARSET=utf8;"
    241 
    242 puts $sqlfile_fd "DROP TABLE IF EXISTS categories;"
    243 puts $sqlfile_fd "CREATE TABLE categories (portfile VARCHAR(255), category VARCHAR(255), is_primary INTEGER) DEFAULT CHARSET=utf8;"
    244 
    245 puts $sqlfile_fd "DROP TABLE IF EXISTS maintainers;"
    246 puts $sqlfile_fd "CREATE TABLE maintainers (portfile VARCHAR(255), maintainer VARCHAR(255), is_primary INTEGER) DEFAULT CHARSET=utf8;"
    247 
    248 puts $sqlfile_fd "DROP TABLE IF EXISTS dependencies;"
    249 puts $sqlfile_fd "CREATE TABLE dependencies (portfile VARCHAR(255), library VARCHAR(255)) DEFAULT CHARSET=utf8;"
    250 
    251 puts $sqlfile_fd "DROP TABLE IF EXISTS variants;"
    252 puts $sqlfile_fd "CREATE TABLE variants (portfile VARCHAR(255), variant VARCHAR(255)) DEFAULT CHARSET=utf8;"
    253 
    254 puts $sqlfile_fd "DROP TABLE IF EXISTS platforms;"
    255 puts $sqlfile_fd "CREATE TABLE platforms (portfile VARCHAR(255), platform VARCHAR(255)) DEFAULT CHARSET=utf8;"
    256 
    257 
     240if {$create_tables} {
     241    # Initial creation of database tables: log, portfiles, categories, maintainers, dependencies, variants and platforms.
     242    # Do we need any other?
     243    puts $sqlfile_fd "DROP TABLE IF EXISTS log;"
     244    puts $sqlfile_fd "CREATE TABLE log (activity VARCHAR(255), activity_time TIMESTAMP(14)) DEFAULT CHARSET=utf8;"
     245   
     246    puts $sqlfile_fd "DROP TABLE IF EXISTS portfiles;"
     247    puts $sqlfile_fd "CREATE TABLE portfiles (name VARCHAR(255) PRIMARY KEY NOT NULL, path VARCHAR(255), version VARCHAR(255),  description TEXT) DEFAULT CHARSET=utf8;"
     248   
     249    puts $sqlfile_fd "DROP TABLE IF EXISTS categories;"
     250    puts $sqlfile_fd "CREATE TABLE categories (portfile VARCHAR(255), category VARCHAR(255), is_primary INTEGER) DEFAULT CHARSET=utf8;"
     251   
     252    puts $sqlfile_fd "DROP TABLE IF EXISTS maintainers;"
     253    puts $sqlfile_fd "CREATE TABLE maintainers (portfile VARCHAR(255), maintainer VARCHAR(255), is_primary INTEGER) DEFAULT CHARSET=utf8;"
     254   
     255    puts $sqlfile_fd "DROP TABLE IF EXISTS dependencies;"
     256    puts $sqlfile_fd "CREATE TABLE dependencies (portfile VARCHAR(255), library VARCHAR(255)) DEFAULT CHARSET=utf8;"
     257   
     258    puts $sqlfile_fd "DROP TABLE IF EXISTS variants;"
     259    puts $sqlfile_fd "CREATE TABLE variants (portfile VARCHAR(255), variant VARCHAR(255)) DEFAULT CHARSET=utf8;"
     260   
     261    puts $sqlfile_fd "DROP TABLE IF EXISTS platforms;"
     262    puts $sqlfile_fd "CREATE TABLE platforms (portfile VARCHAR(255), platform VARCHAR(255)) DEFAULT CHARSET=utf8;"
     263} else {
     264    # if we are not creating tables from scratch, remove the old data
     265    puts $sqlfile_fd "TRUNCATE log;"
     266    puts $sqlfile_fd "TRUNCATE portfiles;"
     267    puts $sqlfile_fd "TRUNCATE categories;"
     268    puts $sqlfile_fd "TRUNCATE maintainers;"
     269    puts $sqlfile_fd "TRUNCATE dependencies;"
     270    puts $sqlfile_fd "TRUNCATE variants;"
     271    puts $sqlfile_fd "TRUNCATE platforms;"
     272}
     273 
    258274# Iterate over each matching port, extracting its information from the
    259275# portinfo array.
     
    377393puts $sqlfile_fd "INSERT INTO log VALUES ('update', NOW());"
    378394
    379 
    380395# Pipe the contents of the generated sql file to the database command,
    381396# reading from the file descriptor for the raw sql file to assure completeness.
     
    385400    terminate 1
    386401}
     402
    387403if {[catch {exec -- $portsdb_cmd --host=$portsdb_host --user=$portsdb_user --password=$portsdb_passwd --database=$portsdb_name <@ $sqlfile_fd} errstr]} {
    388404    ui_error "${::errorCode}: $errstr"
     
    391407}
    392408
    393 
    394 # And we're done regen'ing the MacPorts dabase! Cleanup and exit successfully.
     409# done regenerating the database. Cleanup and exit successfully.
    395410cleanup sqlfile lockfile
    396411terminate 0
  • branches/gsoc09-logging/base/portmgr/jobs/mirror_macports.sh

    • Property svn:eol-style set to native
    • Property svn:keywords set to Id
  • branches/gsoc09-logging/base/portmgr/jobs/org.macports.PortIndexRegen.plist

    • Property svn:eol-stype deleted
    • Property svn:eol-style set to native
  • branches/gsoc09-logging/base/portmgr/jobs/org.macports.mprsyncup.plist

    • Property svn:eol-stype deleted
    • Property svn:eol-style set to native
  • branches/gsoc09-logging/base/portmgr/jobs/portfile_lint.pl

    • Property svn:eol-style set to native
    • Property svn:keywords set to Id
  • branches/gsoc09-logging/base/portmgr/jobs/portfile_mirror.pl

    • Property svn:eol-style set to native
Note: See TracChangeset for help on using the changeset viewer.