-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpreference.py
56 lines (45 loc) · 1.58 KB
/
preference.py
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
# ##### BEGIN GPL LICENSE BLOCK #####
#
# 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 <https://www.gnu.org/licenses/>.
#
# ##### END GPL LICENSE BLOCK #####
import logging
import os
import socket
logger = logging.getLogger(__name__)
preview_collections = {}
def get_current_ip():
"""
Retrieve the main network interface IP.
"""
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
ip = s.getsockname()[0]
s.close()
return ip
def generate_connexion_qrcode(app_address, output_path):
import pyqrcode
logger.info('Generating connexion qrcode (addr: {}) '.format(app_address))
url = pyqrcode.create(app_address)
qr_path = os.path.join(output_path, 'easy_connect_qr_code.png')
url.png(qr_path, scale=4)
logger.info('Success, qrcode saved in {}.'.format(qr_path))
def print_qrcode(app_address):
import qrcode, io
qr = qrcode.QRCode()
qr.add_data(app_address)
f = io.StringIO()
qr.print_ascii(out=f)
f.seek(0)
print(f.read())