From c4a4b1e8b0b2ccf64bd8eb1b05af5810fe6b7f07 Mon Sep 17 00:00:00 2001 From: Graham R Pugh Date: Fri, 6 Mar 2020 22:39:07 +0100 Subject: [PATCH] reconfigure as a package --- CHANGELOG.md | 9 +++++ Makefile | 35 +++++++++++++++++++ README.md | 16 +++++---- pkg/plistyamlplist/.gitignore | 8 +++++ pkg/plistyamlplist/Bom.txt | 5 +++ pkg/plistyamlplist/build-info.plist | 22 ++++++++++++ plistyamlplist.py | 19 +++++----- plistyamlplist_lib/__init__.py | 0 .../plist_yaml.py | 1 - .../yaml_plist.py | 5 +-- 10 files changed, 102 insertions(+), 18 deletions(-) create mode 100644 CHANGELOG.md create mode 100644 Makefile create mode 100644 pkg/plistyamlplist/.gitignore create mode 100644 pkg/plistyamlplist/Bom.txt create mode 100644 pkg/plistyamlplist/build-info.plist create mode 100644 plistyamlplist_lib/__init__.py rename plist_yaml.py => plistyamlplist_lib/plist_yaml.py (98%) rename yaml_plist.py => plistyamlplist_lib/yaml_plist.py (94%) diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..94b3fee --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,9 @@ +# plistyamlplist Change Log + +All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). + + +## v0.1 - 2020-03-06 - v0.1 + +- Initial Release (though the tool has been around for some time). + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..20fe3d0 --- /dev/null +++ b/Makefile @@ -0,0 +1,35 @@ +CURDIR := $(shell pwd) +MUNKIPKG := /usr/local/bin/munkipkg +PKG_ROOT := $(CURDIR)/pkg/plistyamlplist/payload +PKG_BUILD := $(CURDIR)/pkg/plistyamlplist/build +PKG_VERSION := $(shell defaults read $(CURDIR)/pkg/jss_helper/build-info.plist version) + +objects = $(PKG_ROOT)/usr/local/bin/plistyamlplist \ + $(PKG_ROOT)/usr/local/bin/plistyamlplist_lib + + +default : $(PKG_BUILD)/plistyamlplist-$(PKG_VERSION).pkg + @echo "Building plistyamlplist pkg" + + +$(PKG_BUILD)/plistyamlplist-$(PKG_VERSION).pkg: $(objects) + cd $(CURDIR)/pkg && $(MUNKIPKG) plistyamlplist + + +$(PKG_ROOT)/usr/local/bin/plistyamlplist: + @echo "Copying plistyamlplist into /usr/local/bin" + mkdir -p "$(PKG_ROOT)/usr/local/bin" + cp "$(CURDIR)/plistyamlplist.py" "$(PKG_ROOT)/usr/local/bin/plistyamlplist" + chmod 755 "$(PKG_ROOT)/usr/local/bin/plistyamlplist" + + +$(PKG_ROOT)/usr/local/bin/plistyamlplist_lib: + @echo "Copying plistyamlplist_lib into /usr/local/bin" + cp -Rf "$(CURDIR)/plistyamlplist_lib" "$(PKG_ROOT)/usr/local/bin/plistyamlplist_lib" + +.PHONY : clean +clean : + @echo "Cleaning up package root" + rm "$(PKG_ROOT)/usr/local/bin/plistyamlplist" ||: + rm -rf "$(PKG_ROOT)/usr/local/bin/plistyamlplist_lib" ||: + rm $(CURDIR)/pkg/plistyamlplist/build/*.pkg ||: diff --git a/README.md b/README.md index 19fd34c..40cf7eb 100644 --- a/README.md +++ b/README.md @@ -14,10 +14,10 @@ pip install pyyaml # Usage -If all three files are in the same folder, a single command can be used to convert in either direction: +A single command can be used to convert from plist to yaml or from yaml to plist. This depends on the file suffices being predictable: ```bash -./plistyamlplist.py -h +plistyamlplist -h Usage: ./plistyamlplist.py [] ``` @@ -69,17 +69,21 @@ $ ./plistyamlplist.py ~/Downloads/com.something.plist.yaml ## YAML folder -If you have a folder named `YAML` in your path, and you do not supply a destination, the script will determine if a -corresponding folder exists in the path without 'YAML'. For example, consider the following file: +If you have a folder named `YAML` in your path, and you do not supply a destination, the script +will determine if a corresponding folder exists in the path without 'YAML'. For example, consider the following file: /Users/myuser/gitrepo/YAML/product/com.something.plist.yaml If the folder `/Users/myuser/gitrepo/product` exists, the converted file will be created/overwritten at: /Users/myuser/gitrepo/product/com.something.plist + +If the above folder does not exist, you will be prompted to create it. -If there is no `YAML` folder in the path, the converted file will be placed in the same folder +If there is no `YAML` folder in the path, the converted file will be placed in the same folder. # Credits -Elements of these scripts come from [chaimleib/ppl](https://github.com/chaimleib/ppl) and [asciidoctor/sublimetext-asciidoc](https://github.com/asciidoctor/sublimetext-asciidoc) +Elements of these scripts come from: +* [chaimleib/ppl](https://github.com/chaimleib/ppl) +* [asciidoctor/sublimetext-asciidoc](https://github.com/asciidoctor/sublimetext-asciidoc) diff --git a/pkg/plistyamlplist/.gitignore b/pkg/plistyamlplist/.gitignore new file mode 100644 index 0000000..90ac035 --- /dev/null +++ b/pkg/plistyamlplist/.gitignore @@ -0,0 +1,8 @@ +# .DS_Store files! +.DS_Store + +# our build directory +build/ + +# package products +payload/usr/local/bin/* diff --git a/pkg/plistyamlplist/Bom.txt b/pkg/plistyamlplist/Bom.txt new file mode 100644 index 0000000..5afeab4 --- /dev/null +++ b/pkg/plistyamlplist/Bom.txt @@ -0,0 +1,5 @@ +. 40755 0/0 +./usr 41775 0/80 +./usr/local 40755 0/80 +./usr/local/bin 40755 0/80 +./usr/local/bin/plistyamlplist_lib 40755 0/80 diff --git a/pkg/plistyamlplist/build-info.plist b/pkg/plistyamlplist/build-info.plist new file mode 100644 index 0000000..da475cc --- /dev/null +++ b/pkg/plistyamlplist/build-info.plist @@ -0,0 +1,22 @@ + + + + + distribution_style + + identifier + com.github.grahampugh.plistyamlplist + install_location + / + name + plistyamlplist-${version}.pkg + ownership + recommended + postinstall_action + none + suppress_bundle_relocation + + version + 0.1 + + diff --git a/plistyamlplist.py b/plistyamlplist.py index cf6d507..7f3f3bc 100755 --- a/plistyamlplist.py +++ b/plistyamlplist.py @@ -12,9 +12,10 @@ """ import sys -from os import path -from plist_yaml import plist_yaml -from yaml_plist import yaml_plist +import os.path + +from plistyamlplist_lib.plist_yaml import plist_yaml +from plistyamlplist_lib.yaml_plist import yaml_plist def usage(): @@ -47,12 +48,12 @@ def check_for_yaml_folder(check_path): folder if it exists, e.g. /path/to/YAML/folder/subfolder/my.plist.yaml ==> /path/to/folder/subfolder/my.plist Note there is no reverse option at this time""" - check_abspath = path.abspath(check_path) + check_abspath = os.path.abspath(check_path) if 'YAML' in check_abspath: print('YAML folder exists : {}'.format(check_abspath)) top_path, base_path = check_abspath.split('YAML/') - out_path = path.dirname(path.join(top_path, base_path)) - if path.exists(out_path): + out_path = os.path.dirname(os.path.join(top_path, base_path)) + if os.path.exists(out_path): print('Path exists : {}'.format(out_path)) return out_path else: @@ -74,10 +75,10 @@ def main(): if in_path.endswith('.yaml') or in_path.endswith('.yml'): out_dir = check_for_yaml_folder(in_path) if out_dir: - filename, file_extension = path.splitext(path.basename(in_path)) - out_path = path.join(out_dir, filename) + filename, file_extension = os.path.splitext(os.path.basename(in_path)) + out_path = os.path.join(out_dir, filename) else: - filename, file_extension = path.splitext(path.abspath(in_path)) + filename, file_extension = os.path.splitext(os.path.abspath(in_path)) out_path = filename else: if check_if_plist(in_path): diff --git a/plistyamlplist_lib/__init__.py b/plistyamlplist_lib/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/plist_yaml.py b/plistyamlplist_lib/plist_yaml.py similarity index 98% rename from plist_yaml.py rename to plistyamlplist_lib/plist_yaml.py index 4ebcc68..9fd028f 100755 --- a/plist_yaml.py +++ b/plistyamlplist_lib/plist_yaml.py @@ -13,7 +13,6 @@ import sys import yaml -from os import path from plistlib import readPlist, Data diff --git a/yaml_plist.py b/plistyamlplist_lib/yaml_plist.py similarity index 94% rename from yaml_plist.py rename to plistyamlplist_lib/yaml_plist.py index 2aa45bb..358bbe9 100755 --- a/yaml_plist.py +++ b/plistyamlplist_lib/yaml_plist.py @@ -15,7 +15,8 @@ import sys import yaml -from os import path +import os.path + from plistlib import writePlistToString @@ -48,7 +49,7 @@ def main(): sys.argv[2] except Exception as e: if in_path.endswith('.yaml'): - filename, file_extension = path.splitext(in_path) + filename, file_extension = os.path.splitext(in_path) out_path = filename else: print("Usage: yaml_plist.py ")