Skip to content

Instantly share code, notes, and snippets.

@freretuc
Created December 10, 2017 15:05
Show Gist options
  • Save freretuc/6e9f829171e30871c9560f316e066922 to your computer and use it in GitHub Desktop.
Save freretuc/6e9f829171e30871c9560f316e066922 to your computer and use it in GitHub Desktop.
Check last version, download, extract, compile snap7 on Raspberry PI (need 7zip)
#!/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