Skip to content

Commit

Permalink
reconfigure as a package
Browse files Browse the repository at this point in the history
  • Loading branch information
Graham R Pugh committed Mar 6, 2020
1 parent 17d2b12 commit c4a4b1e
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 18 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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).

35 changes: 35 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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 ||:
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <input-file> [<output-file>]
```

Expand Down Expand Up @@ -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)
8 changes: 8 additions & 0 deletions pkg/plistyamlplist/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# .DS_Store files!
.DS_Store

# our build directory
build/

# package products
payload/usr/local/bin/*
5 changes: 5 additions & 0 deletions pkg/plistyamlplist/Bom.txt
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions pkg/plistyamlplist/build-info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>distribution_style</key>
<false/>
<key>identifier</key>
<string>com.github.grahampugh.plistyamlplist</string>
<key>install_location</key>
<string>/</string>
<key>name</key>
<string>plistyamlplist-${version}.pkg</string>
<key>ownership</key>
<string>recommended</string>
<key>postinstall_action</key>
<string>none</string>
<key>suppress_bundle_relocation</key>
<true/>
<key>version</key>
<string>0.1</string>
</dict>
</plist>
19 changes: 10 additions & 9 deletions plistyamlplist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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:
Expand All @@ -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):
Expand Down
Empty file added plistyamlplist_lib/__init__.py
Empty file.
1 change: 0 additions & 1 deletion plist_yaml.py → plistyamlplist_lib/plist_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import sys
import yaml
from os import path
from plistlib import readPlist, Data


Expand Down
5 changes: 3 additions & 2 deletions yaml_plist.py → plistyamlplist_lib/yaml_plist.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

import sys
import yaml
from os import path
import os.path

from plistlib import writePlistToString


Expand Down Expand Up @@ -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 <input-file> <output-file>")
Expand Down

0 comments on commit c4a4b1e

Please sign in to comment.