#!/usr/bin/env python

"""
Tool to sync preferences

See the README for more info

"""

from __future__ import print_function

import argparse
import sys

def main():
    with open("README.md") as f:
        help = f.read()
    parser = argparse.ArgumentParser(description=help,
        formatter_class=argparse.RawDescriptionHelpFormatter)

    parser.add_argument('preffile', metavar='PREFFILE', action='store',
        help="""The (binary) preference file""")
    parser.add_argument('destination', metavar='DEST', action='store',
        help="""The destination for the converted xml file""")
    parser.add_argument('-t', '--throttle-time', help="""Throttle time for the
    synchronization, in seconds (default: %(default)s)""", default=10)

    args = parser.parse_args()



if __name__ == '__main__':
    sys.exit(main())

@@ -146,16 +146,86 @@
 port sys
+%0Aimport os%0A%0A__version__ = '1.0'%0A%0Areverse_DNS = 'com.asmeurer.prefsync'
 %0A%0Adef ma
@@ -702,20 +702,24 @@
 hrottle-
-time
+interval
 ', help=
@@ -734,20 +734,32 @@
 tle 
-time
+interval%0A       
  for the
 %0A   
@@ -754,20 +754,16 @@
  for the
-%0A   
  synchro
@@ -809,16 +809,24 @@
 t)s)%22%22%22,
+%0A       
  default
@@ -863,16 +863,1149 @@
 args()%0A%0A
+    if sys.platform != 'darwin':%0A        print(%22Warning: This script has only been tested on Mac OS X%22)%0A%0A    binary = args.preffile%0A    xml = args.destination%0A    throttleinterval = args.throttle_interval%0A%0A    with open(%22binarytoxml.plist%22) as f:%0A        binarytoxml = f.read()%0A%0A    binarytoxml = binarytoxml.replace(%22%7BBINARY%7D%22, binary)%0A    binarytoxml = binarytoxml.replace(%22%7BXML%7D%22, xml)%0A    binarytoxml = binarytoxml.replace(%22%7BTHROTTLEINTERVAL%7D%22, throttleinterval)%0A%0A    with open(%22xmltobinary.plist%22) as f:%0A        xmltobinary = f.read()%0A%0A    xmltobinary = xmltobinary.replace(%22%7BBINARY%7D%22, binary)%0A    xmltobinary = xmltobinary.replace(%22%7BXML%7D%22, xml)%0A    xmltobinary = xmltobinary.replace(%22%7BTHROTTLEINTERVAL%7D%22, throttleinterval)%0A%0A    prefname = os.path.basename(binary).rpartition('.plist')%5B0%5D%0A%0A    # We only support OS X, so don't bother with os.path%0A    with open(%22~/Library/LaunchAgents/%22 + '.'.join(%5Breverse_DNS, prefname,%0A        'binarytoxml'%5D), 'w') as f:%0A        f.write(binarytoxml)%0A%0A    with open(%22~/Library/LaunchAgents/%22 + '.'.join(%5Breverse_DNS, prefname,%0A        'xmltobinary'%5D), 'w') as f:%0A        f.write(xmltobinary)%0A
 %0A%0Aif __n

Write some more of the script