Class: FileManager
Constant Summary
Constants inherited
from Zarchitect
Zarchitect::ASSETDIR, Zarchitect::ASSETSDIR, Zarchitect::BUILDIR, Zarchitect::CONFIGDIR, Zarchitect::DEBUGSDIR, Zarchitect::DRAFTDIR, Zarchitect::FILEDIR, Zarchitect::FILESDIR, Zarchitect::HTMLDIR, Zarchitect::LAYOUTDIR, Zarchitect::NODEDIR, Zarchitect::SHARESDIR, Zarchitect::VERSION
Instance Method Summary
collapse
Methods inherited from Zarchitect
#main, #rss
Constructor Details
Returns a new instance of FileManager.
3
4
5
6
7
8
9
10
11
|
# File 'lib/zarchitect/file_manager.rb', line 3
def initialize
@from = FILEDIR
@to = File.join(HTMLDIR, FILESDIR)
@img = Array.new
@audio = Array.new
@video = Array.new
@misc = Array.new
end
|
Instance Method Details
#clean ⇒ Object
81
82
83
84
|
# File 'lib/zarchitect/file_manager.rb', line 81
def clean
%x{rm -r _html/files/*}
end
|
#copy(from, to) ⇒ Object
72
73
74
75
76
77
78
79
|
# File 'lib/zarchitect/file_manager.rb', line 72
def copy(from, to)
cmd = "cp #{from} #{to}"
GPI.print cmd, GPI::CLU.check_option('v')
unless system(cmd)
GPI.print "failed to copy '#{from}' to '#{to}'"
GPI.quit
end
end
|
#run ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/zarchitect/file_manager.rb', line 13
def run
Dir.glob(File.join(@from, '**', '*'), File::FNM_DOTMATCH).reject do |fullpath|
path = fullpath[(@from.length)..-1]
next if path[-1] == '.'
realpath = File.join(@to, path)
Util.mkdir(realpath) if File.directory?(fullpath)
next if File.directory?(fullpath)
rrealpath = File.join(Dir.getwd, fullpath)
if Image.is_valid?(fullpath)
GPI.print "processing #{fullpath} as image file",
GPI::CLU.check_option('v')
@img.push ImageSet.new(path, fullpath, realpath)
elsif Audio.is_valid?(fullpath)
GPI.print "processing #{fullpath} as audio file",
GPI::CLU.check_option('v')
@audio.push Audio.new(fullpath)
elsif Video.is_valid?(fullpath)
GPI.print "processing #{fullpath} as video file",
GPI::CLU.check_option('v')
@video.push Video.new(fullpath)
else
GPI.print "processing #{fullpath} as any file",
GPI::CLU.check_option('v')
@misc.push MiscFile.new(fullpath)
end
unless File.exist?(realpath)
if Zarchitect.conf.symlink_files
symlink(rrealpath, realpath)
else
copy(rrealpath, realpath)
end
else
if File.stat(rrealpath).mtime > File.stat(realpath).mtime
if Zarchitect.conf.symlink_files
symlink(rrealpath, realpath)
else
copy(rrealpath, realpath)
end
end
end
end
end
|
#symlink(from, to) ⇒ Object
64
65
66
67
68
69
70
|
# File 'lib/zarchitect/file_manager.rb', line 64
def symlink(from, to)
GPI.print "creating symlink #{to} ~> #{from}",
GPI::CLU.check_option('v')
File.symlink(from, to)
GPI.print "created symlink #{to} ~> #{from}",
GPI::CLU.check_option('v')
end
|