Module: CfrubyRuntime
- Included in:
- Cfruby::Parser
- Defined in:
- lib/libcfenjin/cfrubyruntime.rb
Defined Under Namespace
Classes: EditFile, ExitScript, PackageNotInstalledError
Constant Summary
Constants included from Cfruby::Cfp_MapOptions
Cfruby::Cfp_MapOptions::COPY_OPT, Cfruby::Cfp_MapOptions::DIR_OPT, Cfruby::Cfp_MapOptions::EMPTY_OPT, Cfruby::Cfp_MapOptions::FILES_OPT, Cfruby::Cfp_MapOptions::FILE_OPT, Cfruby::Cfp_MapOptions::MAP, Cfruby::Cfp_MapOptions::SYNONYM
Instance Method Summary collapse
- #copy(src, dest = nil, attrib = {}) ⇒ Object
- #directories(dirname, attrib = {}) ⇒ Object
- #exit_script(msg = '') ⇒ Object
-
#files(filename, attrib = {}) ⇒ Object
The mother of ‘files’ in Cfruby.
-
#haspackage?(pkgname) ⇒ Boolean
Checks for a package (non-disruptive).
-
#hasuser?(username) ⇒ Boolean
Checks for a user.
-
#link(fn, linkname) ⇒ Object
Create a symbolic link from
linkname
tofn
. -
#needpackage(*args) ⇒ Object
This method checks whether a package is installed - if not it will try and install it (nyi) FIXME.
-
#package(*args) ⇒ Object
This method is called from Cfruby script to make sure a package has been installed.
- #tidy(target, attrib = {}) ⇒ Object
Methods included from Cfruby::Cfp_MapOptions
#expand_synonyms, #map, #pop_options, #synonym
Methods included from Cfruby::Cfp_ClassAccessor
#assign, #cfgroup, #dump_classlist, #init_classlist, #isa, #isa?
Methods included from Cfruby::Cfp_ParserLogic
#conditional?, #embed_exec_into_informer, #form_conditional, #form_control, #form_copy, #form_directories, #form_editfiles, #form_files, #form_groups, #form_links, #form_shellcommands, #form_tidy
Instance Method Details
#copy(src, dest = nil, attrib = {}) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/libcfenjin/cfrubyruntime.rb', line 107 def copy src,dest=nil,attrib={} if has_attrib? src eval(send('form_copy',src)) else if dest.is_a? Hash # Move dest from attrib to string 'dest' d = dest['dest'] attrib = dest attrib.delete('dest') dest = d end if File.exist? src # p sprintf("1 %o\n",File.stat(dest).mode) # p (File.stat(dest).mode&0200) # p (File.stat(dest).mode&0400) if (File.exist?(dest) && ((File.stat(dest).mode & 0200)!=0200)) # ---- File in place disallows writing File.chmod((0200|File.stat(dest).mode),dest) end Cfruby::FileOps.copy src,dest,map('copy',attrib) else Cfruby.controller.inform('verbose', "Failed to copy non-existing file #{src}") raise "Failed to copy #{src}" if @cf.strict end end end |
#directories(dirname, attrib = {}) ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/libcfenjin/cfrubyruntime.rb', line 84 def directories dirname,attrib={} if has_attrib? dirname eval(send('form_directories',dirname)) else Cfruby::FileOps.mkdir dirname,map('directories',attrib) end end |
#exit_script(msg = '') ⇒ Object
30 31 32 |
# File 'lib/libcfenjin/cfrubyruntime.rb', line 30 def exit_script msg='' raise ExitScript,'exit_script '+msg end |
#files(filename, attrib = {}) ⇒ Object
The mother of ‘files’ in Cfruby
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/libcfenjin/cfrubyruntime.rb', line 93 def files filename,attrib={} if has_attrib? filename eval(send('form_files',filename)) else = map('files',attrib) (owner,group,mode) = (,:owner,:group,:mode) begin Cfruby::FileOps.chown_mod filename,owner,group,mode, rescue Cfruby::FileFind::FileExistError Cfruby.controller.inform('verbose', "Can not chmod on non-existing file #{filename}") end end end |
#haspackage?(pkgname) ⇒ Boolean
Checks for a package (non-disruptive)
53 54 55 56 57 58 59 |
# File 'lib/libcfenjin/cfrubyruntime.rb', line 53 def haspackage? pkgname if @cf.packagelist return @cf.packagelist[pkgname] end # ---- check for direct name of binary using the path `which #{pkgname}` =~ /#{pkgname}/ end |
#hasuser?(username) ⇒ Boolean
Checks for a user
62 63 64 |
# File 'lib/libcfenjin/cfrubyruntime.rb', line 62 def hasuser? username @cf.usermanager.user? username end |
#link(fn, linkname) ⇒ Object
Create a symbolic link from linkname
to fn
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/libcfenjin/cfrubyruntime.rb', line 67 def link fn,linkname if File.symlink?(linkname) and !Cfruby::FileOps::SymlinkHandler.points_to?(linkname,fn) Cfruby.controller.inform('verbose', "Existing #{linkname} is not pointing to #{fn}") print "Existing #{linkname} is not pointing to #{fn}\n" Cfruby::FileOps.delete linkname end if @cf.strict Cfruby::FileOps.link fn,linkname else begin Cfruby::FileOps.link fn,linkname rescue Cfruby.controller.inform('verbose', "Problem linking #{linkname} -> #{fn}") end end end |
#needpackage(*args) ⇒ Object
This method checks whether a package is installed - if not it will try and install it (nyi) FIXME
48 49 50 |
# File 'lib/libcfenjin/cfrubyruntime.rb', line 48 def needpackage *args package *args end |
#package(*args) ⇒ Object
This method is called from Cfruby script to make sure a package has been installed. If it is not on the system the rest of the script should not be executed.
38 39 40 41 42 43 44 |
# File 'lib/libcfenjin/cfrubyruntime.rb', line 38 def package *args args.each do | name | return if haspackage? name end @cf.cfp_logger.notify VERBOSE_MAJOR,"Skipping - package #{args.join(',')} not installed" raise PackageNotInstalledError,'Package '+args.join(",")+' not installed' end |
#tidy(target, attrib = {}) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/libcfenjin/cfrubyruntime.rb', line 135 def tidy target, attrib={} if has_attrib? target eval(send('form_tidy',target)) else = {} if attrib['recurse'] != nil if attrib['recurse'] != /^[Ff]/ if attrib['recurse'].to_s =~ /\d+/ [:depth] = attrib['recurse'].to_i else [:recursive] = true end end end if attrib['pattern'] != nil [:glob] = attrib['pattern'] end if attrib['rmdirs']=~/^t/ [:force] = true else [:filesonly] = true end if attrib['age'] != nil days = attrib['age'].to_i [:olderthan] = Time.now - days*24*3600 end # p [target,attrib,options] Cfruby::FileOps.delete target, end end |