mirror of
https://github.com/munki/munki.git
synced 2026-05-18 20:28:30 -05:00
SwiftFormat formatting
This commit is contained in:
@@ -12,36 +12,36 @@ struct DisplayOptions {
|
||||
// a Singleton struct to hold shared config values
|
||||
// this might eventually be replaced by a more encompassing struct
|
||||
static let shared = DisplayOptions()
|
||||
|
||||
|
||||
var verbose: Int
|
||||
var munkistatusoutput: Bool
|
||||
|
||||
|
||||
private init(verbose: Int = 1, munkistatusoutput: Bool = false) {
|
||||
self.verbose = verbose
|
||||
self.munkistatusoutput = munkistatusoutput
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func displayPercentDone(current: Int, maximum: Int) {
|
||||
// displays percent-done info
|
||||
var percentDone = 0
|
||||
if current >= maximum {
|
||||
percentDone = 100
|
||||
} else {
|
||||
percentDone = Int(Double(current)/Double(maximum) * 100)
|
||||
percentDone = Int(Double(current) / Double(maximum) * 100)
|
||||
}
|
||||
|
||||
|
||||
if DisplayOptions.shared.munkistatusoutput {
|
||||
// TODO: implement munkistatus stuff
|
||||
// munkistatusPercentDone(percentDone)
|
||||
}
|
||||
|
||||
|
||||
if DisplayOptions.shared.verbose > 0 {
|
||||
let step = [0, 7, 13, 20, 27, 33, 40, 47, 53, 60, 67, 73, 80, 87, 93, 100]
|
||||
let indicator = ["\t0", ".", ".", "20", ".", ".", "40", ".", ".",
|
||||
"60", ".", ".", "80", ".", ".", "100\n"]
|
||||
var output = ""
|
||||
for i in 0...15 {
|
||||
for i in 0 ... 15 {
|
||||
if percentDone >= step[i] {
|
||||
output += indicator[i]
|
||||
}
|
||||
@@ -56,7 +56,7 @@ func displayPercentDone(current: Int, maximum: Int) {
|
||||
func displayMajorStatus(_ message: String) {
|
||||
// Displays major status messages, formatting as needed
|
||||
// for verbose/non-verbose and munkistatus-style output.
|
||||
|
||||
|
||||
munkiLog(message)
|
||||
if DisplayOptions.shared.munkistatusoutput {
|
||||
// TODO: implement munkistatus stuff
|
||||
@@ -77,7 +77,7 @@ func displayMajorStatus(_ message: String) {
|
||||
func displayMinorStatus(_ message: String) {
|
||||
// Displays minor status messages, formatting as needed
|
||||
// for verbose/non-verbose and munkistatus-style output.
|
||||
|
||||
|
||||
munkiLog(" \(message)")
|
||||
if DisplayOptions.shared.munkistatusoutput {
|
||||
// TODO: implement munkistatus stuff
|
||||
@@ -96,7 +96,7 @@ func displayMinorStatus(_ message: String) {
|
||||
func displayInfo(_ message: String) {
|
||||
// Displays info messages.
|
||||
// Not displayed in MunkiStatus.
|
||||
|
||||
|
||||
munkiLog(" \(message)")
|
||||
if DisplayOptions.shared.verbose > 0 {
|
||||
print(" \(message)")
|
||||
@@ -148,7 +148,7 @@ func displayWarning(_ message: String, addToReport: Bool = true) {
|
||||
}
|
||||
munkiLog(warning)
|
||||
munkiLog(warning, logFile: "warnings.log")
|
||||
|
||||
|
||||
if addToReport {
|
||||
Report.shared.add(warning, to: "Warnings")
|
||||
}
|
||||
@@ -162,13 +162,8 @@ func displayError(_ message: String, addToReport: Bool = true) {
|
||||
}
|
||||
munkiLog(errorMsg)
|
||||
munkiLog(errorMsg, logFile: "errors.log")
|
||||
|
||||
|
||||
if addToReport {
|
||||
Report.shared.add(errorMsg, to: "Errors")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -35,7 +35,6 @@ func dmgImageInfo(_ dmgPath: String) -> PlistDict {
|
||||
return hdiutilData(arguments: ["imageinfo", dmgPath])
|
||||
}
|
||||
|
||||
|
||||
func dmgIsWritable(_ dmgPath: String) -> Bool {
|
||||
// Attempts to determine if the given disk image is writable
|
||||
let imageInfo = dmgImageInfo(dmgPath)
|
||||
@@ -47,7 +46,6 @@ func dmgIsWritable(_ dmgPath: String) -> Bool {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
func dmgHasSLA(_ dmgPath: String) -> Bool {
|
||||
// Returns true if dmg has a Software License Agreement.
|
||||
// These dmgs normally cannot be attached without user intervention
|
||||
@@ -60,13 +58,11 @@ func dmgHasSLA(_ dmgPath: String) -> Bool {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
func hdiutilInfo() -> PlistDict {
|
||||
// runs hdiutil info on a dmg and returns a plist data structure
|
||||
return hdiutilData(arguments: ["info"])
|
||||
}
|
||||
|
||||
|
||||
func pathIsVolumeMountPoint(_ path: String) -> Bool {
|
||||
// Returns a boolean to indicate if path is a mountpoint for a disk image
|
||||
let info = hdiutilInfo()
|
||||
@@ -90,7 +86,6 @@ func pathIsVolumeMountPoint(_ path: String) -> Bool {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
func diskImageForMountPoint(_ path: String) -> String? {
|
||||
// Attempts to find the path to a dmg for a given mount point
|
||||
let info = hdiutilInfo()
|
||||
@@ -142,7 +137,6 @@ func mountPointForDiskImage(_ dmgPath: String) -> String? {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
func diskImageIsMounted(_ dmgPath: String) -> Bool {
|
||||
// Returns true if the given disk image is currently mounted
|
||||
if mountPointForDiskImage(dmgPath) != nil {
|
||||
@@ -151,24 +145,24 @@ func diskImageIsMounted(_ dmgPath: String) -> Bool {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
func mountdmg(_ dmgPath: String,
|
||||
useShadow: Bool = false,
|
||||
useExistingMounts: Bool = false,
|
||||
randomMountpoint: Bool = true,
|
||||
skipVerification: Bool = false) -> String? {
|
||||
skipVerification: Bool = false) -> String?
|
||||
{
|
||||
// Attempts to mount the dmg at dmgpath
|
||||
// and returns the first item in the list of mountpoints
|
||||
// If use_shadow is true, mount image with shadow file
|
||||
// If random_mountpoint, mount at random dir under /tmp
|
||||
let dmgName = (dmgPath as NSString).lastPathComponent
|
||||
|
||||
|
||||
if useExistingMounts {
|
||||
if diskImageIsMounted(dmgPath) {
|
||||
return mountPointForDiskImage(dmgPath)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// attempt to mount the dmg
|
||||
var stdIn = ""
|
||||
if dmgHasSLA(dmgPath) {
|
||||
@@ -213,4 +207,3 @@ func unmountdmg(_ mountpoint: String) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user