lib/knj/cmd_parser.rb in knjrbfw-0.0.21 vs lib/knj/cmd_parser.rb in knjrbfw-0.0.22
- old
+ new
@@ -2,19 +2,41 @@
def self.lsl(str, args = {})
ret = []
str.lines.each do |line|
next if line.match(/^total ([\d\.,]+)(M|k|G|)$/)
- match = line.match(/^(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)\s+(\d+)\s+(.+)\s+([^\W].+?)\s+([\d\.,]+)(M|k|G|K|)\s+((\d+)-(\d+)-(\d+)|(([A-z]{3})\s+(\d+)))\s+(\d+):(\d+)\s+(.+)$/)
+ match = line.match(/^(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)\s+(\d+)\s+(.+)\s+([^\W].+?)\s+([\d\.,]+)(M|k|G|K|)\s+((\d+)-(\d+)-(\d+)|(([A-z]{3})\s+(\d+)))\s+((\d+):(\d+)|(\d{4}))\s+(.+)$/)
raise "Could not match: '#{line}'." if !match
+ year = nil
+
+ if match[17].to_i > 0
+ year = match[17].to_i
+ elsif match[26].to_i > 0
+ year = match[26].to_i
+ end
+
+ hour = match[24].to_i
+ min = match[25].to_i
+
if match[17] and match[18] and match[19]
- time = Time.local(match[17].to_i, match[18].to_i, match[19].to_i, match[23].to_i, match[24].to_i)
+ month = match[18].to_i
+ date = match[19].to_i
elsif match[20] and match[21] and match[22]
- time = Time.local(Time.now.year, match[21], match[22].to_i, match[23].to_i, match[24].to_i)
+ month = Knj::Datet.month_str_to_no(match[21])
+ date = match[22].to_i
end
+ if !year
+ if month > Time.now.month
+ year = Time.now.year - 1
+ else
+ year = Time.now.year
+ end
+ end
+
+ time = Time.local(year, month, date, hour, min)
bytes = match[14].gsub(",", ".").to_f
size_match = match[15]
if size_match == ""
#bytes - dont touch
@@ -48,10 +70,10 @@
},
:usr => match[12],
:grp => match[13],
:size => bytes.to_i,
:time => time,
- :file => match[25]
+ :file => match[27]
}
end
return ret
end
\ No newline at end of file