diff --git a/README.md b/README.md index 3547b1b..851d444 100644 --- a/README.md +++ b/README.md @@ -12,13 +12,13 @@ This updated version implements some cool new things: * Support for macOS 10.14, 10.15, 11 and 12 * Usage of the Munki-included Python3 -* Enables usage of Microsoft Excel to edit the CSV file – **this required switching the separator from comma to semicolon**, you may need to update your files accordingly +* Enhances usage of Microsoft Excel to edit the CSV file: for regions which use the comma as the decimal separator, Microsoft Excel expects a semicolon as separator in CSV files. The script will distinguish between both variants. * The order of the csv columns do not have to be preserved, but **keep the names of the 1st row**. * Sanity checks for the csv fields * Option to setup printers using AirPrint provided PPDs, using [airprint-ppd](https://github.com/wycomco/airprint-ppd) * Option to define a path to Munki repo and an optional subdirectory * Option to define a separate name for the Munki pkginfo item -* Besides switching to semicolons as csv separator: **This script should preserve backward compatibility!** +* **This script should preserve backward compatibility!** ## Caveats diff --git a/Template.csv b/Template.csv index 8f74bca..8522630 100644 --- a/Template.csv +++ b/Template.csv @@ -1,3 +1,3 @@ -Printer Name;Location;Display Name;Address;Driver;Description;Options;Version;Requires;Icon;Catalogs;Subdirectory;Munki Name -MyPrinterQueue;Tech Office;My Printer Queue;10.0.0.1;HP officejet 5500 series.ppd.gz;Black and white printer in Tech Office;HPOptionDuplexer=True OutputMode=normal;5.0;HPPrinterDriver;HP LaserJet 4250.icns;testing;scripts/printers/hp/;PrinterSetup_Office -BrotherPrinter;Home Office;Printer at home;ipp://brother9022.local;airprint-ppd;A simple AirPrint printer at home;;1.0;airprint_ppd;;testing;scripts/printers/brother/;PrinterSetup_Brother \ No newline at end of file +Printer Name,Location,Display Name,Address,Driver,Description,Options,Version,Requires,Icon,Catalogs,Subdirectory,Munki Name +MyPrinterQueue,Tech Office,My Printer Queue,10.0.0.1,HP officejet 5500 series.ppd.gz,Black and white printer in Tech Office,HPOptionDuplexer=True OutputMode=normal,5.0,HPPrinterDriver,HP LaserJet 4250.icns,testing,scripts/printers/hp/,PrinterSetup_Office +BrotherPrinter,Home Office,Printer at home,ipp://brother9022.local,airprint-ppd,A simple AirPrint printer at home,,1.0,airprint_ppd,,testing,scripts/printers/brother/,PrinterSetup_Brother \ No newline at end of file diff --git a/Template_with_semicolons.csv b/Template_with_semicolons.csv new file mode 100644 index 0000000..8f74bca --- /dev/null +++ b/Template_with_semicolons.csv @@ -0,0 +1,3 @@ +Printer Name;Location;Display Name;Address;Driver;Description;Options;Version;Requires;Icon;Catalogs;Subdirectory;Munki Name +MyPrinterQueue;Tech Office;My Printer Queue;10.0.0.1;HP officejet 5500 series.ppd.gz;Black and white printer in Tech Office;HPOptionDuplexer=True OutputMode=normal;5.0;HPPrinterDriver;HP LaserJet 4250.icns;testing;scripts/printers/hp/;PrinterSetup_Office +BrotherPrinter;Home Office;Printer at home;ipp://brother9022.local;airprint-ppd;A simple AirPrint printer at home;;1.0;airprint_ppd;;testing;scripts/printers/brother/;PrinterSetup_Brother \ No newline at end of file diff --git a/print_generator.py b/print_generator.py index 10e6932..782d132 100755 --- a/print_generator.py +++ b/print_generator.py @@ -14,7 +14,7 @@ from plistlib import dump as dump_plist -# Preference hanlding copied from Munki: +# Preference handling copied from Munki: # https://github.com/munki/munki/blob/e8ccc5f53e8f69b59fbc153a783158a34ca6d1ea/code/client/munkilib/cliutils.py#L55 BUNDLE_ID = 'com.googlecode.munki.munkiimport' @@ -116,6 +116,13 @@ def throwError(message='Unknown error',exitcode=1,show_usage=True): templatePlist = load_plist(f) f.close() +# Identify the delimiter of a given CSV file, props to https://stackoverflow.com/questions/69817054/python-detection-of-delimiter-separator-in-a-csv-file +def find_delimiter(filename): + sniffer = csv.Sniffer() + with open(filename) as fp: + delimiter = sniffer.sniff(fp.read(5000)).delimiter + return delimiter + def createPlist( printer_name: str, address: str, @@ -225,7 +232,7 @@ def createPlist( if args.csv: # A CSV was found, use that for all data. with open(args.csv, mode='r') as infile: - reader = csv.DictReader(infile, delimiter=';') + reader = csv.DictReader(infile, delimiter=find_delimiter(args.csv)) for row in reader: