PageRenderTime 41ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/nxother/trunk/ForceSFV.tcl

http://nxscripts.googlecode.com/
TCL | 129 lines | 63 code | 16 blank | 50 comment | 20 complexity | 966d254dac84e74091f1202632199679 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause
  1. ################################################################################
  2. # ForceSFV - Force SFV Files First #
  3. ################################################################################
  4. # Author : neoxed #
  5. # Date : 16/05/2004 #
  6. # Version : 1.0.2 #
  7. ################################################################################
  8. #
  9. # Installation:
  10. #
  11. # 1. Copy the ForceSFV.itcl file to x:\ioFTPD\scripts
  12. # 2. Configure the script options.
  13. # 3. Add the following to the ioFTPD.ini
  14. #
  15. # [FTP_Pre-Command_Events]
  16. # stor = TCL ..\scripts\ForceSFV.itcl
  17. #
  18. # 4. Good luck! ;)
  19. #
  20. # Change Log:
  21. #
  22. # v1.0.2 - Added user, group, and flag excemptions.
  23. # v1.0.1 - Fixed a few spelling errors and updated the config comments.
  24. # v1.0.0 - Initial release.
  25. #
  26. ################################################################################
  27. ## Extensions to Ignore
  28. # - List of extensions not to check, include the preceeding period.
  29. # - It's recommended to leave .nfo and .sfv in the ignore list.
  30. # - Wildcards may be used if needed.
  31. set IgnoreExts ".nfo .sfv .log .txt .jpg"
  32. ## No Extension
  33. # - Block files with no extension? (ex. README)
  34. # - 1 = Block / 0 = Allow
  35. set BlockNoExt 0
  36. ## Paths to Ignore
  37. # - Virtual paths to ignore for the SFV check (case insensitive).
  38. # - Include the trailing forward slash.
  39. set IgnorePaths "*/codec/ */cover/ */covers/ */extra/ */sample/ */subs/ */extras/ */vobsub/ */vobsubs/"
  40. ## Paths to Check
  41. # - Virtual paths to force for the SFV first (case sensitive).
  42. # - Wildcards may be used if needed.
  43. set CheckPaths "/APPS/* /DVDR/* /GAMES/* /MP3/* /SVCD/* /TV/* /VCD/* /XVID/* /XXX/*"
  44. ## Exempt Users/Groups/Flags
  45. # - Exempt certain users based on usernames, groups or flags.
  46. # - To disable exempts, set to "".
  47. set ExemptUsers "someuser someguy"
  48. set ExemptGroups "FRiENDS STAFF"
  49. set ExemptFlags "M1"
  50. ## End of Settings
  51. ################################################################################
  52. proc ArgRange {list start end} {
  53. regsub -all {[\s]+} $list { } list
  54. return [join [lrange [split [string trim $list] { }] $start $end] { }]
  55. }
  56. proc GetPath {path workingPath} {
  57. ## Absolute path or relative path.
  58. if {[string index $path 0] ne "/"} {
  59. set path "$workingPath/$path"
  60. }
  61. set path [string trim $path "/\\"]
  62. ## Resolve the "." and ".." path components.
  63. set components [list]
  64. foreach component [SplitPath $path] {
  65. if {$component eq ".."} {
  66. set components [lreplace $components end end]
  67. } elseif {$component ne "."} {
  68. lappend components $component
  69. }
  70. }
  71. return "/[join $components /]"
  72. }
  73. proc SplitPath {path} {
  74. regsub -all -- {[\\/]+} $path {/} path
  75. return [file split [string trim $path "/"]]
  76. }
  77. if {[info exists args] && ![string equal "" $args]} {
  78. ## Set file and directory paths
  79. set checksfv 0
  80. set fpath [GetPath [ArgRange $args 1 end] $pwd]
  81. set mpath [string range $fpath 0 [string last "/" $fpath]]
  82. set filext [file extension $fpath]
  83. ## Check if file has extension
  84. if {[string equal "" $filext] && $BlockNoExt == 1} {
  85. iputs -noprefix "553-.-\[NoExt\]---------------------------------------."
  86. iputs -noprefix "553-| No extension found, file not allowed. |"
  87. iputs -noprefix "553 '-----------------------------------------------'"
  88. set ioerror 1; return 1
  89. }
  90. ## Check for exempts/ignores
  91. if {[lsearch $ExemptUsers $user] != -1 || [lsearch $ExemptGroups $group] != -1} {return 0}
  92. if {![string equal "" $ExemptFlags] && [regexp "\[$ExemptFlags\]" $flags]} {return 0}
  93. foreach ignore $IgnoreExts {
  94. if {[string match -nocase $ignore $filext]} {return 0}
  95. }
  96. foreach ignore $IgnorePaths {
  97. if {[string match -nocase $ignore $mpath]} {return 0}
  98. }
  99. ## Do we check this path?
  100. foreach check $CheckPaths {
  101. if {[string match $check $mpath]} {set checksfv 1; break}
  102. }
  103. if {$checksfv == 1} {
  104. set realpath [resolve pwd $mpath]
  105. set sfvfiles [glob -nocomplain -types f -directory $realpath {*.[sS][fF][vV]}]
  106. if {[llength $sfvfiles] == 0} {
  107. iputs -noprefix "553-.-\[NoSFV\]---------------------------------------."
  108. iputs -noprefix "553-| You must upload the SFV first. |"
  109. iputs -noprefix "553 '-----------------------------------------------'"
  110. set ioerror 1; return 1
  111. }
  112. }
  113. }