Module: Pa::ClassMethods::Cmd
- Included in:
- Pa
- Defined in:
- lib/tagen/core/pa/cmd.rb
Instance Method Summary collapse
-
#chroot(path) ⇒ nil
chroot.
-
#cp(src_s, dest, o = {}, &blk) ⇒ Object
copy.
-
#home(user = nil) ⇒ Object
def mktmpdir.
-
#mkdir(*paths, o = {}) ⇒ nil
make a directory.
-
#mkdir_f(*paths, o = {}) ⇒ nil
mkdir force.
-
#mktmpdir(o = {}, &blk) ⇒ String
make temp directory.
-
#mktmpfile(o = {}, &blk) ⇒ String
make temp file.
-
#mv(src_s, dest, o = {}, &blk) ⇒ nil
move, use rename for same device.
-
#rm(*paths) ⇒ nil
rm file only.
-
#rm_if(*paths) {|path| ... } ⇒ nil
rm_r(path) if condition is true.
-
#rm_r(*paths) ⇒ nil
rm recusive, rm both file and directory.
-
#rmdir(*paths) ⇒ nil
rm directory only.
-
#touch(*paths, o = {}) ⇒ nil
touch a blank file.
-
#touch_f(*paths, o = {}) ⇒ nil
touch force.
Instance Method Details
#chroot(path) ⇒ nil
chroot
19 |
# File 'lib/tagen/core/pa/cmd.rb', line 19 def chroot(path) Dir.chroot(get(path)) end |
#cp(src_s, dest, o) ⇒ nil #cp(src_s, dest, o) {|src, dest, o| ... } ⇒ nil
copy
cp file dir
cp 'a', 'dir' #=> dir/a
cp 'a', 'dir/a' #=> dir/a
cp file1 file2 .. dir
cp ['a','b'], 'dir' #=> dir/a dir/b
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/tagen/core/pa/cmd.rb', line 239 def cp(src_s, dest, o={}, &blk) srcs = glob(*Array.wrap(src_s)).map{|v| v.path} dest = Pa.get(dest) if o[:mkdir] and (not File.exists?(dest)) Pa.mkdir dest end # cp file1 file2 .. dir if srcs.size>1 and (not File.directory?(dest)) raise Errno::ENOTDIR, "dest not a directory when cp more than one src -- #{dest}" end srcs.each do |src| dest1 = File.directory?(dest) ? File.join(dest, File.basename(src)) : dest if blk blk.call src, dest1, o, proc{_copy(src, dest1, o)} else _copy src, dest1, o end end end |
#home(user = nil) ⇒ Object
def mktmpdir
113 |
# File 'lib/tagen/core/pa/cmd.rb', line 113 def home(user=nil) Dir.home end |
#mkdir(*paths, o = {}) ⇒ nil
make a directory
67 |
# File 'lib/tagen/core/pa/cmd.rb', line 67 def mkdir(*args) paths, o = args.; _mkdir(paths, o) end |
#mkdir_f(*paths, o = {}) ⇒ nil
mkdir force
74 |
# File 'lib/tagen/core/pa/cmd.rb', line 74 def mkdir_f(*args) paths, o = args.; o[:force]=true; _mkdir(*paths, o) end |
#mktmpdir(o = {}, &blk) ⇒ String
make temp directory
106 107 108 109 110 111 |
# File 'lib/tagen/core/pa/cmd.rb', line 106 def mktmpdir(o={}, &blk) p = _mktmpname(o) File.mkdir(p) begin blk.call(p) ensure Dir.delete(p) end if blk p end |
#mktmpfile(o = {}, &blk) ⇒ String
make temp file
120 121 122 123 124 |
# File 'lib/tagen/core/pa/cmd.rb', line 120 def mktmpfile(o={}, &blk) p = _mktmpname(o) begin blk.call(p) ensure File.delete(p) end if blk p end |
#mv(src_s, dest, o = {}, &blk) ⇒ nil
move, use rename for same device. and cp for cross device.
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
# File 'lib/tagen/core/pa/cmd.rb', line 323 def mv(src_s, dest, o={}, &blk) srcs = glob(*Array.wrap(src_s)).map{|v| get(v)} dest = get(dest) if o[:mkdir] and (not File.exists?(dest)) mkdir dest end # mv file1 file2 .. dir if srcs.size>1 and (not File.directory?(dest)) raise Errno::ENOTDIR, "dest not a directory when mv more than one src -- #{dest}" end srcs.each do |src| dest1 = File.directory?(dest) ? File.join(dest, File.basename(src)) : dest if blk blk.call src, dest1, o, proc{_move(src, dest1, o)} else _move src, dest1, o end end end |
#rm(*paths) ⇒ nil
rm file only
152 153 154 155 156 157 |
# File 'lib/tagen/core/pa/cmd.rb', line 152 def rm(*paths) glob(*paths) { |pa| next if not File.exists?(pa.p) File.delete(pa.p) } end |
#rm_if(*paths) {|path| ... } ⇒ nil
rm_r(path) if condition is true
193 194 195 196 197 |
# File 'lib/tagen/core/pa/cmd.rb', line 193 def rm_if(*paths, &blk) glob(*paths) do |pa| rm_r pa if blk.call(pa) end end |
#rm_r(*paths) ⇒ nil
rm recusive, rm both file and directory
174 175 176 177 178 179 |
# File 'lib/tagen/core/pa/cmd.rb', line 174 def rm_r(*paths) glob(*paths){ |pa| next if not File.exists?(pa.p) File.directory?(pa.p) ? _rmdir(pa) : File.delete(pa.p) } end |
#rmdir(*paths) ⇒ nil
rm directory only. still remove if directory is not empty.
163 164 165 166 167 168 |
# File 'lib/tagen/core/pa/cmd.rb', line 163 def rmdir *paths glob(*paths) { |pa| raise Errno::ENOTDIR, "-- #{pa}" if not File.directory?(pa.p) _rmdir(pa) } end |
#touch(*paths, o = {}) ⇒ nil
touch a blank file
30 |
# File 'lib/tagen/core/pa/cmd.rb', line 30 def touch(*args) paths, o = args.; _touch(*paths, o) end |
#touch_f(*paths, o = {}) ⇒ nil
touch force
37 |
# File 'lib/tagen/core/pa/cmd.rb', line 37 def touch_f(*args) paths, o = args.; o[:force]=true; _touch(*paths, o) end |