lib/jss/api_object/package.rb in ruby-jss-0.7.0 vs lib/jss/api_object/package.rb in ruby-jss-0.8.1

- old
+ new

@@ -46,10 +46,11 @@ class Package < JSS::APIObject ### Mix-Ins ##################################### + include JSS::Categorizable include JSS::Creatable include JSS::Updatable ### Class Methods ##################################### @@ -125,13 +126,10 @@ attr_reader :switch_with_package ### @return [Boolean] can this item be uninstalled? Some, e.g. OS Updates, can't attr_reader :allow_uninstalled - ### @return [String] the category of this pkg, stored in the JSS as the id number from the categories table - attr_reader :category - ### @return [String] the info field for this pkg - stores d3's basename & swupdate values attr_reader :info ### @return [String] the notes field for this pkg attr_reader :notes @@ -154,12 +152,10 @@ super ### now we have pkg_data with something in it, so fill out the instance vars @allow_uninstalled = @init_data[:allow_uninstalled] @boot_volume_required = @init_data[:boot_volume_required] - @category = JSS::APIObject.get_name(@init_data[:category]) - @category = nil if @category.to_s.casecmp('No category assigned').zero? @filename = @init_data[:filename] || @init_data[:name] @fill_existing_users = @init_data[:fill_existing_users] @fill_user_template = @init_data[:fill_user_template] @info = @init_data[:info] @install_if_reported_available = @init_data[:install_if_reported_available] @@ -212,25 +208,10 @@ raise JSS::InvalidDataError, 'install_if_reported_available must be boolean true or false' unless JSS::TRUE_FALSE.include? new_val @boot_volume_required = new_val @need_to_update = true end - ### Change the category in the JSS - ### - ### @param new_val[String] must be one listed by 'JSS::Category.all_names' - ### - ### @return [void] - ### - def category=(new_val) - return nil if new_val == @category - new_val = nil if new_val == '' - new_val ||= JSS::Category::DEFAULT_CATEGORY - raise JSS::InvalidDataError, "Category #{new_val} is not known to the JSS" unless JSS::Category.all_names.include? new_val - @category = new_val - @need_to_update = true - end - ### Change the package filename. ### Setting it to nil or empty will make it match the display name ### ### @param new_val[String] ### @@ -457,12 +438,15 @@ @receipt.file? end ### Upload a locally-readable file to the master distribution point. ### If the file is a directory (like a bundle .pk/.mpkg) it will be zipped before - ### uploading and the @filename will be adjusted accordingly + ### uploading and the @filename will be adjusted accordingly by adding a .zip extension ### + ### The name of the local file doesn't matter, the file on the dist. point will + ### use the @filename (possibly with .zip) + ### ### If you'll be uploading several files you can specify unmount as false, and do it manually when all ### are finished with JSS::DistributionPoint.master_distribution_point.unmount ### ### @param local_file_path[String,Pathname] the local path to the file to be uploaded ### @@ -483,38 +467,41 @@ raise JSS::NoSuchItemError, "Local file '#{@local_file}' doesn't exist" unless local_path.exist? ### should we zip it? if local_path.directory? begin - zipdir = Pathname.new "/tmp/jssgemtmp-#{Time.new.strftime '%Y%m%d%H%M%S'}-#{$PROCESS_ID}" - zipdir.mkpath - zipdir.chmod 0o700 - zipfile = zipdir + (local_path.basename.to_s + '.zip') - ### go to the same dir as the local file wd = Dir.pwd Dir.chdir local_path.parent ### the contents of the zip file have to have the same name as the zip file itself (minus the .zip) ### so temporarily rename the source - local_path.rename(local_path.parent + @filename) - raise 'There was a problem zipping the pkg bundle' unless system "/usr/bin/zip -qr '#{zipfile}' '#{@filename}'" + local_path_to_upload = local_path.parent + @filename + local_path.rename local_path_to_upload unless local_path_to_upload == local_path + zipdir = Pathname.new "/tmp/rubyjsstmp-#{Time.new.strftime '%Y%m%d%H%M%S'}-#{$PROCESS_ID}" + zipdir.mkpath + zipdir.chmod 0o700 + zipfile = zipdir + (local_path_to_upload.basename.to_s + '.zip') + + raise 'There was a problem zipping the pkg bundle' unless system "/usr/bin/zip -qr '#{zipfile}' '#{local_path_to_upload}'" + ensure ### rename the source to the original name - (local_path.parent + @filename).rename local_path if (local_path.parent + @filename).exist? + local_path_to_upload.rename local_path if local_path_to_upload.exist? && local_path_to_upload != local_path ### go back where we started Dir.chdir wd end # begin ### update our info local_path = zipfile - - self.filename = zipfile.basename.to_s - + destination = destination.to_s + '.zip' + @filename = zipfile.basename.to_s + @need_to_update = true + update end # if directory - update + FileUtils.copy_entry local_path, destination mdp.unmount if unmount end # upload @@ -794,11 +781,10 @@ def rest_xml doc = REXML::Document.new APIConnection::XML_HEADER pkg = doc.add_element 'package' pkg.add_element('allow_uninstalled').text = @allow_uninstalled pkg.add_element('boot_volume_required').text = @boot_volume_required - pkg.add_element('category').text = @category.to_s.casecmp('No category assigned').zero? ? '' : @category pkg.add_element('filename').text = @filename pkg.add_element('fill_existing_users').text = @fill_existing_users pkg.add_element('fill_user_template').text = @fill_user_template pkg.add_element('info').text = @info pkg.add_element('install_if_reported_available').text = @install_if_reported_available @@ -808,9 +794,10 @@ pkg.add_element('priority').text = @priority pkg.add_element('reboot_required').text = @reboot_required pkg.add_element('required_processor').text = @required_processor.to_s.empty? ? 'None' : @required_processor pkg.add_element('send_notification').text = @send_notification pkg.add_element('switch_with_package').text = @switch_with_package + add_category_to_xml(doc) doc.to_s end # rest xml end # class Package