1515 from importlib import resources
1616
1717from ds_store import DSStore
18- from mac_alias import Alias , Bookmark
18+ from mac_alias import Alias
1919
2020from . import colors , licensing
2121
@@ -159,16 +159,20 @@ def load_json(filename, settings):
159159 settings ["icon_locations" ] = icon_locations
160160
161161
162- def build_dmg ( # noqa; C901
162+ def build_dmg ( # noqa: C901
163163 filename ,
164164 volume_name ,
165165 settings_file = None ,
166- settings = {} ,
167- defines = {} ,
166+ settings = None ,
167+ defines = None ,
168168 lookForHiDPI = True ,
169169 detach_retries = 12 ,
170170 callback = quiet_callback ,
171171):
172+ if defines is None :
173+ defines = {}
174+ if settings is None :
175+ settings = {}
172176 options = {
173177 # Default settings
174178 "filename" : filename ,
@@ -269,8 +273,8 @@ def build_dmg( # noqa; C901
269273 # Set up the finder data
270274 bounds = options ["window_rect" ]
271275
272- bounds_string = "{{{{{}, {}}}, {{{}, {}}}}}" . format (
273- bounds [0 ][0 ], bounds [0 ][1 ], bounds [1 ][0 ], bounds [1 ][1 ]
276+ bounds_string = (
277+ f"{{{{ { bounds [0 ][0 ]} , { bounds [0 ][1 ]} }}, {{ { bounds [1 ][0 ]} , { bounds [1 ][1 ]} }}}}"
274278 )
275279 bwsp = {
276280 "ShowStatusBar" : options ["show_status_bar" ],
@@ -373,8 +377,11 @@ def build_dmg( # noqa; C901
373377 for n , column in enumerate (options ["list_columns" ]):
374378 cndx [column ] = n
375379 width = options ["list_column_widths" ].get (column , default_widths [column ])
376- asc = "ascending" == options ["list_column_sort_directions" ].get (
377- column , default_sort_directions [column ]
380+ asc = (
381+ options ["list_column_sort_directions" ].get (
382+ column , default_sort_directions [column ]
383+ )
384+ == "ascending"
378385 )
379386
380387 lsvp ["columns" ][columns [column ]] = {
@@ -387,10 +394,10 @@ def build_dmg( # noqa; C901
387394
388395 n = len (options ["list_columns" ])
389396 for k in columns :
390- if cndx .get (k , None ) is None :
397+ if cndx .get (k ) is None :
391398 cndx [k ] = n
392399 width = default_widths [k ]
393- asc = "ascending" == default_sort_directions [k ]
400+ asc = default_sort_directions [k ] == "ascending"
394401
395402 lsvp ["columns" ][columns [column ]] = {
396403 "index" : n ,
@@ -453,7 +460,7 @@ def roundup(x, n):
453460 path = path [0 ]
454461
455462 if not os .path .islink (path ) and os .path .isdir (path ):
456- for dirpath , dirnames , filenames in os .walk (path ):
463+ for dirpath , _dirnames , filenames in os .walk (path ):
457464 for f in filenames :
458465 fp = os .path .join (dirpath , f )
459466 total_size += roundup (os .lstat (fp ).st_size , 4096 )
@@ -566,8 +573,6 @@ def roundup(x, n):
566573 if icon or badge_icon :
567574 subprocess .call (["/usr/bin/SetFile" , "-a" , "C" , mount_point ])
568575
569- background_bmk = None
570-
571576 callback (
572577 {
573578 "type" : "operation::start" ,
@@ -627,8 +632,8 @@ def roundup(x, n):
627632 except Exception as e :
628633 output .seek (0 )
629634 raise ValueError (
630- ' unable to compile combined HiDPI file "%s" got error: %s \n output: %s'
631- % ( background , str (e ), output .read ())
635+ f" unable to compile combined HiDPI file { background !r } "
636+ f"got error: { str (e )} \n output: { output .read ()} "
632637 )
633638
634639 _ , kind = os .path .splitext (background )
@@ -645,10 +650,9 @@ def roundup(x, n):
645650 with open (path_in_image , "wb" ) as out_file :
646651 out_file .write (in_file .read ())
647652 else :
648- raise ValueError ('background file "%s " not found' % background )
653+ raise ValueError (f 'background file "{ background } " not found' )
649654
650655 alias = Alias .for_file (path_in_image )
651- background_bmk = Bookmark .for_file (path_in_image )
652656
653657 icvp ["backgroundType" ] = 2
654658 icvp ["backgroundImageAlias" ] = alias .to_bytes ()
@@ -767,7 +771,7 @@ def roundup(x, n):
767771 }
768772 )
769773
770- userfn = options .get ("create_hook" , None )
774+ userfn = options .get ("create_hook" )
771775 if callable (userfn ):
772776 userfn (mount_point , options )
773777
@@ -785,8 +789,6 @@ def roundup(x, n):
785789 d ["." ]["bwsp" ] = bwsp
786790 if include_icon_view_settings :
787791 d ["." ]["icvp" ] = icvp
788- if background_bmk :
789- d ["." ]["pBBk" ] = background_bmk
790792 if include_list_view_settings :
791793 d ["." ]["lsvp" ] = lsvp
792794 d ["." ]["icvl" ] = icvl
@@ -819,7 +821,7 @@ def roundup(x, n):
819821 subprocess .check_call (("sync" , "--file-system" , mount_point ))
820822
821823 retry_time = 1
822- for tries in range (detach_retries ):
824+ for _ in range (detach_retries ):
823825 callback (
824826 {
825827 "type" : "command::start" ,
@@ -833,8 +835,8 @@ def roundup(x, n):
833835 {
834836 "type" : "command::finished" ,
835837 "command" : "hdiutil::detach" ,
836- "ret: " : ret ,
837- "output: " : output ,
838+ "ret" : ret ,
839+ "output" : output ,
838840 }
839841 )
840842
0 commit comments