<commit_before>
package require sdx 1.0

package provide tloona::starkit 1.0

namespace eval ::Tloona::Fs {}

## Extracts the application name from ReleaseNotes file, if present.
# Reads the ReleaseNotes.txt file in baseDir and returns the string 
# in ApplicationName : <appname>. This is useful for deployment
proc ::Tloona::Fs::getStarkitApplicationName {baseDir} {
    set appName [file tail [file root $baseDir]]
    set fh [open [file join $baseDir ReleaseNotes.txt] r]
    while {[gets $fh line] >= 0} {
        if {[regexp ^ApplicationName $line] && [llength [split $line]] >= 3} {
            set appName [lindex [split $line] 2]
            break
        }
    }
    close $fh
    return $appName
}

## Read the version from ReleaseNotes file. 
#
# This requires that there is an entry with the most recent 
# version with the form "Release <version>", where <version> is
# extracted and set as the global version. The first of these
# entries is taken, others are ignored, as well as comments 
# starting with a #
proc ::Tloona::Fs::getStarkitVersion {baseDir} {
    set version ""
    set fh [open [file join $baseDir ReleaseNotes.txt] r]
    while {[gets $fh line] >= 0} {
        if {[regexp ^Release $line] && [llength [split $line]] >= 2} {
            set version [lindex [split $line] 1]
            break
        }
    }
    close $fh
    return $version
}

## Recursively copy a directory, excluding certain patterns
proc ::Tloona::Fs::copyFiles {src dest exclude} {
    foreach {f} [glob [file join $src *]] {
        if {[apply $exclude [file tail $f]]} {
            continue
        }
        if {[file isdir $f]} {
            set newDest [file join $dest [file tail $f]]
            file mkdir $newDest
            copyFiles $f $newDest $exclude
        } else {
            file copy -force $f $dest
        }
        
    }
}

## Copies a starkit directory, excluding .svn, build/ and the like files
proc ::Tloona::Fs::copyForDeployment {src dest appName ver} {
    set rootDir [expr {
        ( $appName == "" ) ? [file tail [file rootname $src]] : $appName
    }]
    if {$ver != ""} {
        append rootDir - $ver
    }
    append rootDir [file ext $src]
    set baseDir [file join $dest $rootDir]<commit_msg>annoying glob bug fixed<commit_after>
package require sdx 1.0

package provide tloona::starkit 1.0

namespace eval ::Tloona::Fs {}

## Extracts the application name from ReleaseNotes file, if present.
# Reads the ReleaseNotes.txt file in baseDir and returns the string 
# in ApplicationName : <appname>. This is useful for deployment
proc ::Tloona::Fs::getStarkitApplicationName {baseDir} {
    set appName [file tail [file root $baseDir]]
    set fh [open [file join $baseDir ReleaseNotes.txt] r]
    while {[gets $fh line] >= 0} {
        if {[regexp ^ApplicationName $line] && [llength [split $line]] >= 3} {
            set appName [lindex [split $line] 2]
            break
        }
    }
    close $fh
    return $appName
}

## Read the version from ReleaseNotes file. 
#
# This requires that there is an entry with the most recent 
# version with the form "Release <version>", where <version> is
# extracted and set as the global version. The first of these
# entries is taken, others are ignored, as well as comments 
# starting with a #
proc ::Tloona::Fs::getStarkitVersion {baseDir} {
    set version ""
    set fh [open [file join $baseDir ReleaseNotes.txt] r]
    while {[gets $fh line] >= 0} {
        if {[regexp ^Release $line] && [llength [split $line]] >= 2} {
            set version [lindex [split $line] 1]
            break
        }
    }
    close $fh
    return $version
}

## Recursively copy a directory, excluding certain patterns
proc ::Tloona::Fs::copyFiles {src dest exclude} {
    foreach {f} [glob -nocomplain [file join $src *]] {
        if {[apply $exclude [file tail $f]]} {
            continue
        }
        if {[file isdir $f]} {
            set newDest [file join $dest [file tail $f]]
            file mkdir $newDest
            copyFiles $f $newDest $exclude
        } else {
            file copy -force $f $dest
        }
        
    }
}

## Copies a starkit directory, excluding .svn, build/ and the like files
proc ::Tloona::Fs::copyForDeployment {src dest appName ver} {
    set rootDir [expr {
        ( $appName == "" ) ? [file tail [file rootname $src]] : $appName
    }]
    if {$ver != ""} {
        append rootDir - $ver
    }
    append rootDir [file ext $src]
    set baseDir [file join $dest $rootDir]
{'fraction_non_alphanumeric': 0.113898756660746, 'fraction_numerical': 0.004440497335701598, 'mean_word_length': 2.5753968253968256, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2920415', 'n_tokens_mistral': 1427, 'n_tokens_neox': 1382, 'n_words': 525}