summaryrefslogtreecommitdiff
path: root/pkg/branding/patch_pixel_logo.py
blob: 464bb729933eebe023d5351159ea77d0222ec0ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# -*- coding: utf-8 -*-
# patch_pixelated_logo.py
# Copyright (C) 2016 LEAP Encryption Acess Project
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""
Patch the Pixelated Logo in the index.html, replacing it with a rebranded
Bitmask Logo. To be used in the pixelated_www assets distributed with the
Bitmask bundles.
"""
__author__ = 'Kali Kaneko <kali@leap.se>'

import os
import sys

from BeautifulSoup import BeautifulSoup


def patch_logo(orig_path, replacement_path):

    with open(orig_path, 'r') as of:
        orig = BeautifulSoup(of.read())

    with open(replacement_path, 'r') as rf:
        new = BeautifulSoup(rf.read())

    new_svg = new.find('svg')
    old_svg = orig.find('svg')
    old_svg.replaceWith(new_svg)

    with open(orig_path, 'w') as f:
        f.write(str(orig))


if __name__ == "__main__":
    here = os.path.dirname(os.path.realpath(__file__))
    if len(sys.argv) > 1:
        orig_path = sys.argv[1]
    else:
        import pixelated_www
        orig_path = os.path.join(pixelated_www.__path__[0],
                                 'index.html')
    assert os.path.isfile(orig_path)
    new_path = os.path.join(here, 'bitmask-logo.svg')
    print('>>> patching file %s with logo in %s' % (orig_path, new_path))
    patch_logo(orig_path, new_path)