Created
December 10, 2017 15:05
-
-
Save freretuc/6e9f829171e30871c9560f316e066922 to your computer and use it in GitHub Desktop.
Check last version, download, extract, compile snap7 on Raspberry PI (need 7zip)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import glob | |
import os | |
import platform | |
import urllib.request | |
import re | |
import shutil | |
import sys | |
arch = { | |
'x64': 'x86_64', | |
'ia32': 'i386', | |
'x86': 'i386', | |
'armv7': 'arm_v7', | |
'armv7l': 'arm_v7', | |
'armv6': 'arm_v6' | |
}.get(platform.machine(), platform.machine()) | |
with urllib.request.urlopen('https://sourceforge.net/projects/snap7/rss?path=/') as response: | |
html = response.read().decode('utf-8') | |
m = re.search('snap7-full-(\d\.\d\.\d)\.7z', html) | |
version = m.group(1) | |
os.chdir("/tmp/") | |
pwd = os.getcwd() | |
print("Downloading snap7, version " + version + " ... ") | |
url = 'https://sourceforge.net/projects/snap7/files/' + version + '/snap7-full-' + version + '.7z/download' | |
urllib.request.urlretrieve(url, 'snap7-full-' + version + '.7z') | |
print ("Extracting files ...") | |
os.system('7zr x -y snap7-full-' + version +'.7z') | |
os.chdir(pwd + '/snap7-full-' + version + '/build/unix/') | |
print("Compiling ...") | |
os.system('make -f ' + arch + '_linux.mk all') | |
os.chdir(pwd + '/snap7-full-' + version + '/build/bin/' + arch + '-linux/') | |
shutil.copyfile('libsnap7.so', '/usr/lib/libsnap7.so') | |
shutil.copyfile('libsnap7.so', '/usr/local/lib/libsnap7.so') | |
os.chdir(pwd) | |
os.remove('snap7-full-' + version + '.7z') | |
shutil.rmtree('snap7-full-' + version + '') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment