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 99c2dde..fe98044 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,8 +69,8 @@ $ ./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 @@ -78,8 +78,12 @@ If the folder `/Users/myuser/gitrepo/product` exists, the converted file will be /Users/myuser/gitrepo/product/com.something.plist -If there is no `YAML` folder in the path, the converted file will be placed in the same folder +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. # 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 f65ad24..7316ab6 100755 --- a/plistyamlplist.py +++ b/plistyamlplist.py @@ -12,10 +12,10 @@ """ import sys -from os import path +import os.path -from plist_yaml import plist_yaml -from yaml_plist import yaml_plist +from plistyamlplist_lib.plist_yaml import plist_yaml +from plistyamlplist_lib.yaml_plist import yaml_plist def usage(): @@ -48,20 +48,17 @@ def check_if_plist(in_path): def check_for_yaml_folder(check_path): - """Check folder hierarchy for a YAML folder. - - Output to same folder structure outwith YAML 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) - 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): - print("Path exists : {}".format(out_path)) + """Check folder hierarchy for a YAML folder. Output to same folder structure outwith YAML + 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 = 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 = 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: print("Path does not exist : {}".format(out_path)) @@ -82,10 +79,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 100% rename from plist_yaml.py rename to plistyamlplist_lib/plist_yaml.py diff --git a/yaml_plist.py b/plistyamlplist_lib/yaml_plist.py similarity index 92% rename from yaml_plist.py rename to plistyamlplist_lib/yaml_plist.py index 12b7b37..d944c9b 100755 --- a/yaml_plist.py +++ b/plistyamlplist_lib/yaml_plist.py @@ -14,7 +14,9 @@ """ import sys -from os import path +import yaml +import os.path + from plistlib import writePlistToString import yaml @@ -48,8 +50,8 @@ def main(): try: sys.argv[2] except Exception as e: - if in_path.endswith(".yaml"): - filename, file_extension = path.splitext(in_path) + if in_path.endswith('.yaml'): + filename, file_extension = os.path.splitext(in_path) out_path = filename else: print("Usage: yaml_plist.py ")