Module: CfrubyRuntime
- Included in:
- Cfruby::Parser
- Defined in:
- lib/libcfenjin/cfrubyruntime.rb
Defined Under Namespace
Classes: EditFile, ExitScript, PackageNotInstalledError, VersionError
Constant Summary
Constants included from Cfruby::Cfp_MapOptions
Cfruby::Cfp_MapOptions::AGE_OPT, Cfruby::Cfp_MapOptions::COPY, Cfruby::Cfp_MapOptions::DIR, Cfruby::Cfp_MapOptions::EMPTY_OPT, Cfruby::Cfp_MapOptions::FILES, Cfruby::Cfp_MapOptions::FILE_OPT, Cfruby::Cfp_MapOptions::MAP, Cfruby::Cfp_MapOptions::PATTERN_OPT, Cfruby::Cfp_MapOptions::RECURSE_OPT, Cfruby::Cfp_MapOptions::REMOVE_OPT, Cfruby::Cfp_MapOptions::SYNONYM, Cfruby::Cfp_MapOptions::TIDY
Instance Method Summary collapse
- #cfenjin_version(version, dev_version = nil) ⇒ Object
- #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
#check_pattern, #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
#cfenjin_version(version, dev_version = nil) ⇒ Object
41 42 43 44 45 |
# File 'lib/libcfenjin/cfrubyruntime.rb', line 41 def cfenjin_version version, dev_version=nil if (version > @cf.version) or (version == @cf.version and dev_version > @cf.dev_version) raise VersionError,"Cfenjin version #{version}-dev#{dev_version} required!" end end |
#copy(src, dest = nil, attrib = {}) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/libcfenjin/cfrubyruntime.rb', line 126 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('info', "Failed to copy non-existing file #{src}") raise "Failed to copy #{src}" if @cf.strict end end end |
#directories(dirname, attrib = {}) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/libcfenjin/cfrubyruntime.rb', line 97 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
37 38 39 |
# File 'lib/libcfenjin/cfrubyruntime.rb', line 37 def exit_script msg='' raise ExitScript,'exit_script '+msg end |
#files(filename, attrib = {}) ⇒ Object
The mother of ‘files’ in Cfruby
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/libcfenjin/cfrubyruntime.rb', line 106 def files filename,attrib={} if has_attrib? filename eval(send('form_files',filename)) else = map('files',check_pattern(attrib,filename)) (owner,group,mode) = (,:owner,:group,:mode) begin # p [filename,owner,group,mode,options] if [:shell] Cfruby::FileOps.shell_chown_mod filename,owner,group,mode, else Cfruby::FileOps.chown_mod filename,owner,group,mode, end [:shell] = nil 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)
66 67 68 69 70 71 72 |
# File 'lib/libcfenjin/cfrubyruntime.rb', line 66 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
75 76 77 |
# File 'lib/libcfenjin/cfrubyruntime.rb', line 75 def hasuser? username @cf.usermanager.user? username end |
#link(fn, linkname) ⇒ Object
Create a symbolic link from linkname
to fn
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/libcfenjin/cfrubyruntime.rb', line 80 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
61 62 63 |
# File 'lib/libcfenjin/cfrubyruntime.rb', line 61 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.
51 52 53 54 55 56 57 |
# File 'lib/libcfenjin/cfrubyruntime.rb', line 51 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.new('Package '+args.join(",")+' not installed') end |