2 # Adapted from custom_dsstore.py by the Jalview team 2024
3 # Copyright (c) 2013-2017 The Bitcoin Core developers
4 # Distributed under the MIT software license, see the accompanying
5 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
12 parser = argparse.ArgumentParser(
13 prog = "jalview_custom_dsstore.py",
14 description = "Take an existing DS_Store file and change the volume name and add path to background image"
16 parser.add_argument("-i", "--input", help="The existing styled DS_Store file", dest="input")
17 parser.add_argument("-o", "--output", help="The output DS_Store file", dest="output")
18 parser.add_argument("-v", "--volumename", help="The name of the output DS_Store volume", dest="volumename")
19 parser.add_argument("-b", "--backgroundfile", help="The background image filename to use", dest="backgroundfile", default="background.png")
20 parser.add_argument("-d", "--backgrounddir", help="The background image hidden dirname to use", dest="backgrounddir", default=".background")
21 parser.add_argument("-c", "--config", help="YAML configuration for window and icon sizes and positions", dest="config")
22 parser.add_argument("-m", "--dmg", help="The filename of the DMG file", dest="dmg", default="Jalview_macos.dmg")
23 parser.add_argument("--dump", help="Display contents of the input DS_Store to stdout", action="store_true", dest="dump")
24 parser.add_argument("-q", "--quiet", help="Don't print messages to stdout", action="store_true", dest="quiet")
25 parser.add_argument("--appname", help="Filename of the application on the DMG (including '.app')", dest="appname")
26 parser.add_argument("--appxpos", help="x position of the application icon", dest="appxpos", type=int)
27 parser.add_argument("--appypos", help="y position of the application icon", dest="appypos", type=int)
29 args = parser.parse_args()
39 if (args.dump and not args.input):
40 exit("When --dump used, an --input must be given")
43 with ds_store.DSStore.open(args.input, 'r') as d:
44 for key in ["bwsp", "icvp","Iloc"]:
46 print(f"d['.']['{key}'] =\n" + pprint.pformat(d['.'][key], width=4))
48 print(f"No info for d['.']['{key}']")
50 a = mac_alias.Alias.from_bytes( d['.']['icvp']['backgroundImageAlias'] )
51 print("backgroundImageAlias:")
52 print("alias.volume="+pprint.pformat(a.volume))
53 print("alias.target="+pprint.pformat(a.target))
58 pprint.pprint(f"d['{data}']="+d[data], width=1)
60 print(f"No info for d['{data}']")
63 if (args.output and not (args.input or args.config)):
64 exit("Need --input FILENAME or --config FILENAME to produce an --output")
67 exit("Provide --output FILENAME to output DS_Store")
69 if (not args.volumename):
70 exit("Provide a volume name with --volumename NAME")
72 if (not args.backgroundfile):
73 exit("Provide a background image filename (just the file, no path) with --backgroundfile FILENAME")
75 package_name_ns = args.volumename
76 configfilename = args.config
79 configfile = open(configfilename, 'r')
80 config = json.load(configfile)
82 inputds = ds_store.DSStore.open(args.input)
83 outputds = ds_store.DSStore.open(args.output, 'w+')
88 for key in "ShowStatusBar SidebarWidthTenElevenOrLater ShowToolbar ShowTabView ContainerShowSidebar WindowBounds ShowSidebar ShowPathbar".split():
89 if config and 'bwsp' in config and key in config['bwsp']:
90 bwsp[key] = config['bwsp'][key]
91 myprint(f"Setting bwsp['{key}'] to '"+str(bwsp[key])+"' from config")
93 if key in inputds['.']['bwsp']:
94 bwsp[key] = inputds['.']['bwsp'][key]
95 myprint(f"Setting bwsp['{key}'] to '"+str(bwsp[key])+"' from input DS_Store")
97 myprint(f"Did not find '{key}' in input bwsp")
99 outputds['.']['bwsp'] = bwsp
103 alias = mac_alias.Alias.from_bytes(inputds['.']['icvp']['backgroundImageAlias'])
105 alias.volume.name = args.volumename
106 alias.volume.posix_path = "/Volumes/" + args.volumename
107 alias.volume.disk_image_alias = None
108 alias.target.filename = args.backgroundfile
109 alias.target.folder_name = args.backgrounddir
110 alias.target.carbon_path = f'{args.volumename}:{args.backgrounddir}:{args.backgroundfile}'
111 alias.target.posix_path = f'/{args.backgrounddir}/{args.backgroundfile}'
113 icvp['backgroundImageAlias'] = alias.to_bytes()
114 myprint(f"Setting icvp['backgroundImageAlias']")
116 for key in "backgroundColorRed backgroundColorBlue backgroundColorGreen gridSpacing gridOffsetX gridOffsetY showItemInfo viewOptionsVersion arrangeBy textSize labelOnBottom backgroundType showIconPreview iconSize".split():
117 if config and 'icvp' in config and key in config['icvp']:
118 icvp[key] = config['icvp'][key]
119 myprint(f"Setting icvp['{key}'] to '"+str(icvp[key])+"' from config")
121 if key in inputds['.']['icvp']:
122 icvp[key] = inputds['.']['icvp'][key]
123 myprint(f"Setting icvp['{key}'] to '"+str(icvp[key])+"' from input DS_Store")
125 myprint(f"Did not find '{key}' in input icvp")
127 outputds['.']['icvp'] = icvp
128 outputds['.']['vSrn'] = ('long', 1)
131 for fileinfo in config['files']:
132 outputds[fileinfo['name']]['Iloc'] = (fileinfo['xpos'], fileinfo['ypos'])
133 myprint("Setting icon location for filename '" + fileinfo['name'] + "' to ( " + str(fileinfo['xpos']) + ", " + str(fileinfo['ypos']) + " )")
138 if (not xpos) and 'app' in config and 'xpos' in config['app']:
139 xpos = config['app']['xpos']
142 if (not ypos) and 'app' in config and 'ypos' in config['app']:
143 ypos = config['app']['ypos']
145 if xpos != None and ypos != None:
146 outputds[args.appname]['Iloc'] = (xpos, ypos)
147 myprint("Setting icon location for filename '" + args.appname + "' to ( " + str(xpos) + ", " + str(ypos) + " )")