Skip to content

Commit

Permalink
Merge pull request dmgbuild#14 from PeterPetrik/master
Browse files Browse the repository at this point in the history
Enable license test and fix licensing for python3. Fix dmgbuild#12
  • Loading branch information
al45tair authored Oct 7, 2019
2 parents a98a36c + 5be2cb1 commit 9932217
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 67 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@
.#*
dist
build
.DS_Store
.idea
14 changes: 9 additions & 5 deletions dmgbuild/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,11 @@ def to_rgb(self):
'yellowgreen': (154, 205, 50)
}

_ws_re = re.compile('\s+')
_token_re = re.compile('[A-Za-z_][A-Za-z0-9_]*')
_hex_re = re.compile('#([0-9a-f]{3}(?:[0-9a-f]{3})?)$')
_number_re = re.compile('[0-9]*(\.[0-9]*)')
_ws_re = re.compile(r'\s+')
_token_re = re.compile(r'[A-Za-z_][A-Za-z0-9_]*')
_hex_re = re.compile(r'#([0-9a-f]{3}(?:[0-9a-f]{3})?)$')
_number_re = re.compile(r'[0-9]*(\.[0-9]*)')


class ColorParser (object):
def __init__(self, s):
Expand Down Expand Up @@ -485,10 +486,13 @@ def parseAngle(self):
raise ValueError('bad angle unit "%s"' % tok)
return n

_color_re = re.compile('\s*(#|rgb|hsl|hwb|cmyk|gray|grey|%s)'
_color_re = re.compile(r'\s*(#|rgb|hsl|hwb|cmyk|gray|grey|%s)'
% '|'.join(_x11_colors.keys()))


def isAColor(s):
return _color_re.match(s)


def parseColor(s):
return ColorParser(s).parseColor()
2 changes: 1 addition & 1 deletion dmgbuild/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ def roundup(x, n):
imageDirectory = '.'
for candidateName in os.listdir(imageDirectory):
hasScale = re.match(
'^(?P<name>.+)@(?P<scale>\d+)x(?P<extension>\.\w+)$',
r'^(?P<name>.+)@(?P<scale>\d+)x(?P<extension>\.\w+)$',
candidateName)
if hasScale and name == hasScale.group('name') and \
extension == hasScale.group('extension'):
Expand Down
13 changes: 6 additions & 7 deletions dmgbuild/licensing.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,13 @@ def add_license(filename, license_info):
with open(license_data) as f:
license_data = f.read()

if license_data.startswith('{\\rtf1'):
fork.add(Resource(b'RTF ', 5000 + ndx, language + ' SLA',
str(license_data)))
if type(license_data) == bytes and license_data.startswith(b'{\\rtf1'):
fork.add(Resource(b'RTF ', 5000 + ndx, (language + ' SLA').encode(),
license_data))
else:
fork.add(TextResource(5000 + ndx, language + ' SLA',
fork.add(TextResource(5000 + ndx, (language + ' SLA').encode(),
maybe_encode(license_data, encoding_name)))
fork.add(StyleResource(5000 + ndx, language + ' SLA',
fork.add(StyleResource(5000 + ndx, (language + ' SLA').encode(),
[Style(0, 12, 9, Style.Helvetica,
0, 0, (0, 0, 0))]))

Expand All @@ -449,8 +449,7 @@ def add_license(filename, license_info):

buttons = [maybe_encode(b, encoding_name) for b in buttons]

fork.add(StringListResource(5000 + ndx, language + ' Buttons',
buttons))
fork.add(StringListResource(5000 + ndx, (language + ' Buttons').encode(), buttons))

lpic.append((lang_id, ndx, is_two_byte))

Expand Down
36 changes: 20 additions & 16 deletions dmgbuild/resources.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import struct

class Resource (object):
def __init__(self, res_type, res_id, res_name, data=None, res_attrs=0):
self.res_type = str(res_type)
self.res_type = res_type
self.res_id = res_id
if isinstance(res_name, basestring):
res_name = str(res_name)
self.res_name = res_name
self.res_attrs = res_attrs
if data is None:
self.data = None
self.data = str(data)
self.data = data

self.data_offset = None
self.name_offset = None
Expand All @@ -30,8 +27,8 @@ def __init__(self, res_id, res_name, tmpl, res_attrs=0):
data = []
for name,typecode in tmpl:
data.append(struct.pack(b'B', len(name)))
data.append(str(name))
data.append(str(typecode))
data.append(name)
data.append(typecode)
super(TMPLResource, self).__init__(b'TMPL', res_id, res_name,
b''.join(data), res_attrs)

Expand All @@ -41,14 +38,15 @@ def __init__(self, res_id, res_name, strings, res_attrs=0):
data.append(struct.pack(b'>H', len(strings)))
for s in strings:
data.append(struct.pack(b'B', len(s)))
data.append(str(s))
data.append(s)

super(StringListResource, self).__init__(b'STR#', res_id, res_name,
b''.join(data), res_attrs)

class TextResource (Resource):
def __init__(self, res_id, res_name, string, res_attrs=0):
super(TextResource, self).__init__(b'TEXT', res_id, res_name,
str(string), res_attrs)
string, res_attrs)

class Style (object):
# Fonts
Expand Down Expand Up @@ -171,7 +169,7 @@ def from_data(clss, data):
raise ValueError('Bad resource data - data too short')

# Read the header
data_start, map_start, data_len, map_len = struct.unpack(b'>LLLL',
data_start, map_start, data_len, map_len = struct.unpack('>LLLL',
data[0:16])

if data_start + data_len > len(data):
Expand All @@ -183,7 +181,7 @@ def from_data(clss, data):

# Read the map header
fork_attrs, type_offset, name_offset, max_type_ndx \
= struct.unpack(b'>HHHH', data[map_start + 22:map_start + 30])
= struct.unpack('>HHHH', data[map_start + 22:map_start + 30])
num_types = max_type_ndx + 1

if type_offset + 8 * num_types > map_len:
Expand All @@ -201,7 +199,7 @@ def from_data(clss, data):
for ntype in range(0, num_types):
type_pos = 2 + type_offset + 8 * ntype
res_type, max_item_ndx, ref_offset \
= struct.unpack(b'>4sHH', data[type_pos:type_pos+8])
= struct.unpack('>4sHH', data[type_pos:type_pos+8])
num_items = max_item_ndx + 1

result.types[res_type] = []
Expand All @@ -213,7 +211,7 @@ def from_data(clss, data):
for nitem in range(0, num_items):
ref_elt = ref_list_offset + 12 * nitem
res_id, res_name_offset, data_offset \
= struct.unpack(b'>hHL', data[ref_elt:ref_elt+8])
= struct.unpack('>hHL', data[ref_elt:ref_elt+8])

res_attrs = data_offset >> 24
data_offset &= 0xffffff
Expand All @@ -222,7 +220,7 @@ def from_data(clss, data):
raise ValueError('Bad resource data - item data out of range')

data_offset += data_start
res_len = struct.unpack(b'>L', data[data_offset:data_offset+4])[0]
res_len = struct.unpack('>L', data[data_offset:data_offset+4])[0]
if data_offset + res_len >= data_start + data_len:
raise ValueError('Bad resource data - item data too large')

Expand All @@ -234,7 +232,13 @@ def from_data(clss, data):
res_name_offset += name_offset
if res_name_offset >= map_start + map_len:
raise ValueError('Bad resource data - name out of range')
res_name_len = struct.unpack(b'B', data[res_name_offset])[0]
try:
# python2
res_name_len = struct.unpack('B', data[res_name_offset])[0]
except:
# python3
res_name_len = data[res_name_offset]

res_name = data[res_name_offset + 1:res_name_offset + res_name_len + 1]

result.types[res_type].append(Resource(res_type, res_id,
Expand Down Expand Up @@ -271,7 +275,7 @@ def to_data(self):
name_offset = 65535
else:
name_offset = names_len
n = str(item.res_name)
n = item.res_name
names.append(struct.pack(b'B', len(n)) + n)
names_len += 1 + len(n)

Expand Down
76 changes: 38 additions & 38 deletions examples/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,33 +196,33 @@ def icon_from_app(app_path):
# pt_PT, ro_RO, ru_RU, se, sk_SK, sl_SI, sr_RS, sv_SE, th_TH, to_TO, tr_TR,
# uk_UA, ur_IN, ur_PK, uz_UZ, vi_VN, zh_CN, zh_TW

# license = {
# 'default-language': 'en_US',
# 'licenses': {
# # For each language, the text of the license. This can be plain text,
# # RTF (in which case it must start "{\rtf1"), or a path to a file
# # containing the license text. If you're using RTF,
# # watch out for Python escaping (or read it from a file).
# 'English': b'''{\\rtf1\\ansi\\ansicpg1252\\cocoartf1504\\cocoasubrtf820
# {\\fonttbl\\f0\\fnil\\fcharset0 Helvetica-Bold;\\f1\\fnil\\fcharset0 Helvetica;}
# {\\colortbl;\\red255\\green255\\blue255;\\red0\\green0\\blue0;}
# {\\*\\expandedcolortbl;;\\cssrgb\\c0\\c0\\c0;}
# \\paperw11905\\paperh16837\\margl1133\\margr1133\\margb1133\\margt1133
# \\deftab720
# \\pard\\pardeftab720\\sa160\\partightenfactor0

# \\f0\\b\\fs60 \\cf2 \\expnd0\\expndtw0\\kerning0
# \\up0 \\nosupersub \\ulnone \\outl0\\strokewidth0 \\strokec2 Test License\\
# \\pard\\pardeftab720\\sa160\\partightenfactor0

# \\fs36 \\cf2 \\strokec2 What is this?\\
# \\pard\\pardeftab720\\sa160\\partightenfactor0

# \\f1\\b0\\fs22 \\cf2 \\strokec2 This is the English license. It says what you are allowed to do with this software.\\
# \\
# }''',
# },
# 'buttons': {
license = {
'default-language': 'en_US',
'licenses': {
# For each language, the text of the license. This can be plain text,
# RTF (in which case it must start "{\rtf1"), or a path to a file
# containing the license text. If you're using RTF,
# watch out for Python escaping (or read it from a file).
'en_GB': b'''{\\rtf1\\ansi\\ansicpg1252\\cocoartf1504\\cocoasubrtf820
{\\fonttbl\\f0\\fnil\\fcharset0 Helvetica-Bold;\\f1\\fnil\\fcharset0 Helvetica;}
{\\colortbl;\\red255\\green255\\blue255;\\red0\\green0\\blue0;}
{\\*\\expandedcolortbl;;\\cssrgb\\c0\\c0\\c0;}
\\paperw11905\\paperh16837\\margl1133\\margr1133\\margb1133\\margt1133
\\deftab720
\\pard\\pardeftab720\\sa160\\partightenfactor0
\\f0\\b\\fs60 \\cf2 \\expnd0\\expndtw0\\kerning0
\\up0 \\nosupersub \\ulnone \\outl0\\strokewidth0 \\strokec2 Test License\\
\\pard\\pardeftab720\\sa160\\partightenfactor0
\\fs36 \\cf2 \\strokec2 What is this?\\
\\pard\\pardeftab720\\sa160\\partightenfactor0
\\f1\\b0\\fs22 \\cf2 \\strokec2 This is the English license. It says what you are allowed to do with this software.\\
\\
}''',
},
'buttons': {
# # For each language, text for the buttons on the licensing window.
# #
# # Default buttons and text are built-in for the following languages:
Expand All @@ -236,14 +236,14 @@ def icon_from_app(app_path):
# # You don't need to specify them for those languages; if you fail to
# # specify them for some other language, English will be used instead.

# 'en_US': (
# b'English',
# b'Agree',
# b'Disagree',
# b'Print',
# b'Save',
# b'If you agree with the terms of this license, press "Agree" to '
# b'install the software. If you do not agree, press "Disagree".'
# ),
# },
# }
'en_US': (
b'English',
b'Agree',
b'Disagree',
b'Print',
b'Save',
b'If you agree with the terms of this license, press "Agree" to '
b'install the software. If you do not agree, press "Disagree".'
),
},
}

0 comments on commit 9932217

Please sign in to comment.