diff --git a/plistyamlplist.py b/plistyamlplist.py index 5c9dcfc..ce4cf37 100755 --- a/plistyamlplist.py +++ b/plistyamlplist.py @@ -102,7 +102,7 @@ def get_out_path(in_path, filetype): else: filename, _ = os.path.splitext(os.path.abspath(in_path)) out_path = filename - if filetype == "json": + elif filetype == "json": out_dir = check_for_json_folder(in_path) if out_dir: filename, _ = os.path.splitext(os.path.basename(in_path)) @@ -146,8 +146,10 @@ def main(): for glob_file in glob_files: out_path = get_out_path(glob_file, filetype) if filetype == "yaml": + print("Processing YAML folder with globs...") yaml_plist(glob_file, out_path) elif filetype == "json": + print("Processing JSON folder with globs...") json_plist(glob_file, out_path) else: try: @@ -157,17 +159,23 @@ def main(): else: out_path = sys.argv[2] if filetype == "yaml": + print("Processing yaml file...") yaml_plist(in_path, out_path) elif filetype == "json": + print("Processing json file...") json_plist(in_path, out_path) # allow for converting whole folders if 'YAML' or 'JSON' is in the path # and the path supplied is a folder elif os.path.isdir(in_path) and "YAML" in in_path: + print("Processing YAML folder...") + filetype = "yaml" for in_file in os.listdir(in_path): in_file_path = os.path.join(in_path, in_file) out_path = get_out_path(in_file_path, filetype) yaml_plist(in_file_path, out_path) elif os.path.isdir(in_path) and "JSON" in in_path: + print("Processing JSON folder...") + filetype = "json" for in_file in os.listdir(in_path): in_file_path = os.path.join(in_path, in_file) out_path = get_out_path(in_file_path, filetype) @@ -180,6 +188,7 @@ def main(): out_path = get_out_path(in_path, filetype) else: out_path = sys.argv[2] + print("Processing plist file...") plist_yaml(in_path, out_path) else: print("\nERROR: Input File is not PLIST, JSON or YAML format.\n") diff --git a/plistyamlplist_lib/plist_yaml.py b/plistyamlplist_lib/plist_yaml.py index 4f0796f..760c159 100755 --- a/plistyamlplist_lib/plist_yaml.py +++ b/plistyamlplist_lib/plist_yaml.py @@ -11,6 +11,7 @@ taken from the input file, with .yaml added to the end. """ +import subprocess import sys from collections import OrderedDict @@ -21,7 +22,12 @@ from plistlib import Data # Python 2 from plistlib import readPlist as load_plist -import yaml +try: + import yaml +except ImportError: + subprocess.check_call([sys.executable, "-m", "ensurepip", "--user"]) + subprocess.check_call([sys.executable, "-m", "pip", "install", "pyyaml", "--user"]) + import yaml def represent_ordereddict(dumper, data): @@ -107,7 +113,7 @@ def main(): try: sys.argv[2] - except Exception as e: + except Exception: out_path = "%s.yaml" % in_path else: out_path = sys.argv[2] diff --git a/plistyamlplist_lib/yaml_plist.py b/plistyamlplist_lib/yaml_plist.py index 8868ee1..346567e 100755 --- a/plistyamlplist_lib/yaml_plist.py +++ b/plistyamlplist_lib/yaml_plist.py @@ -13,15 +13,21 @@ For best results, the input file should therefore be named with """ +import subprocess import sys -import yaml import os.path try: # python 3 from plistlib import dumps as write_plist except ImportError: # python 2 from plistlib import writePlistToString as write_plist -import yaml + +try: + import yaml +except ImportError: + subprocess.check_call([sys.executable, "-m", "ensurepip", "--user"]) + subprocess.check_call([sys.executable, "-m", "pip", "install", "pyyaml", "--user"]) + import yaml def convert(data): @@ -60,7 +66,7 @@ def main(): in_path = sys.argv[1] try: sys.argv[2] - except Exception as e: + except Exception: if in_path.endswith(".yaml"): filename, _ = os.path.splitext(in_path) out_path = filename diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..59bfe65 --- /dev/null +++ b/setup.py @@ -0,0 +1,8 @@ +from setuptools import setup, find_packages + +setup( + name="plistyamlplist", + version="0.4.0", + packages=find_packages(include=["plistyamlplist_lib", "plistyamlplist_lib.*"]), + install_requires=["pyyaml"], +)