-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/lhhong/crumbs
- Loading branch information
Showing
23 changed files
with
562 additions
and
485 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
from PIL import Image, ImageTk | ||
import easygui | ||
import commands | ||
import subprocess as p | ||
import platform | ||
import os | ||
import re | ||
import sys | ||
import atexit | ||
from time import sleep | ||
import signal | ||
import Tkinter as tk | ||
|
||
dir_path = os.path.dirname(os.path.realpath(__file__)) | ||
print(dir_path) | ||
cwd = os.getcwd() | ||
print(cwd) | ||
os.chdir(dir_path) | ||
cwd = os.getcwd() | ||
print(cwd) | ||
|
||
IMAGE_PATH = "LoadingPageDesign.ppm" | ||
|
||
class Splash(object): | ||
"Splash Screen GUI" | ||
def __init__(self, root): | ||
self.root = root | ||
self.root.overrideredirect(True) | ||
w = self.root.winfo_screenwidth() | ||
h = self.root.winfo_screenheight() | ||
# Full screen | ||
# Display an image | ||
self.label = tk.Label(self.root) | ||
self.label._image = tk.PhotoImage(file=IMAGE_PATH) | ||
self.label.configure(image = self.label._image) | ||
self.label.pack() | ||
self.root.after(10000, self.root.quit) | ||
|
||
def center(win): | ||
win.update_idletasks() | ||
width = win.winfo_width() | ||
frm_width = win.winfo_rootx() - win.winfo_x() | ||
win_width = width + 2 * frm_width | ||
height = win.winfo_height() | ||
titlebar_height = win.winfo_rooty() - win.winfo_y() | ||
win_height = height + titlebar_height + frm_width | ||
x = win.winfo_screenwidth() // 2 - win_width // 2 | ||
y = win.winfo_screenheight() // 2 - win_height // 2 | ||
win.geometry('{}x{}+{}+{}'.format(width, height, x, y)) | ||
win.deiconify() | ||
|
||
def inplace_change(filename, old_regex, new_string): | ||
# Safely read the input filename using 'with' | ||
with open(filename) as f: | ||
s = f.read() | ||
|
||
# Safely write the changed content, if found in the file | ||
with open(filename, 'w') as f: | ||
s = re.sub(old_regex, new_string, s) | ||
f.write(s) | ||
|
||
try: | ||
predictorPid = int(p.check_output(['pidof','-s','nn_crumbs'])) | ||
os.kill(predictorPid, signal.SIGTERM) | ||
except: | ||
a=0 | ||
|
||
configPath = os.path.join('config', 'ethereumj.conf') | ||
|
||
hostSystem = platform.system() | ||
|
||
#retrieve private ips | ||
ip = "127.0.0.1" | ||
peer = "127.0.0.1" | ||
addresses = [] | ||
if hostSystem == 'Linux': | ||
ips = p.check_output(['hostname', '-I']) | ||
addresses = ips.split() | ||
elif hostSystem == 'Darwin': | ||
for NUMBER in [0,5]: | ||
addr = commands.getoutput('ipconfig getifaddr en' + str(NUMBER)) | ||
if len(addr) > 1: | ||
addresses.append(addr) | ||
elif hostSystem == 'Windows': | ||
ips = commands.getoutput("ipconfig | where {$_ -match 'IPv4.+\s(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' } | out-null; $Matches[1]") | ||
addresses = ips.split() | ||
|
||
#selection of bind ip | ||
for address in addresses: | ||
print(address) | ||
if len(addresses) == 0: | ||
ip = easygui.enterbox(msg='Unable to detect your IP address,\nplease enter the desired IP address to use.\n\nIf remained at 127.0.0.1,\nthe application will not communicate across computers.', title='No IP detected', default='127.0.0.1', strip=True) | ||
if not re.match(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$', ip): | ||
easygui.msgbox('Invalid IP address entered. IPv4 addresses are in the format xxx.xxx.xxx.xxx') | ||
sys.exit(0) | ||
elif len(addresses) != 1: | ||
ip = easygui.choicebox(msg='Multiple IP addresses detected, please select IP address to be used', title='Select your IP', choices=addresses) | ||
else: | ||
ip = addresses[0] | ||
|
||
#enter ip of peers | ||
if ip != '127.0.0.1': | ||
peerIp = easygui.enterbox(msg='Your IP address is : ' + ip + '\n\nEnter IP used by the other computer (optional)', title='IP Resolution', strip=True) | ||
if peerIp: | ||
print(peerIp) | ||
if not re.match(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$', peer): | ||
easygui.msgbox('Invalid IP address entered. IPv4 addresses are in the format xxx.xxx.xxx.xxx') | ||
sys.exit(0) | ||
else: | ||
peer = peerIp | ||
inplace_change(configPath, r'ip_addr = \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}', 'ip_addr = ' + ip) | ||
inplace_change(configPath, r'peer_ip = \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}', 'peer_ip = ' + peer) | ||
|
||
#run services | ||
backendLog = open('backend.log','w+') | ||
|
||
backend = p.Popen(['java','-jar','ethereum-1.0.jar'], stdout=backendLog) | ||
|
||
if hostSystem == 'Linux': | ||
predictor = p.Popen(['components-linux/predictor/nn_crumbs']) | ||
if hostSystem == 'Darwin': | ||
predictor = p.Popen(['components-darwin/predictor/nn_crumbs.app/Contents/MacOS/nn_crumbs']) | ||
|
||
|
||
print('backend pid: ' + str(backend.pid)) | ||
print('predictor pid: ' + str(predictor.pid)) | ||
|
||
#show splash screen | ||
root = tk.Tk() | ||
appl = Splash(root) | ||
center(root) | ||
root.mainloop() | ||
|
||
sleep(9) | ||
|
||
root.destroy() | ||
|
||
if hostSystem == 'Linux': | ||
frontend = p.Popen(['components-linux/frontend/crumbs']) | ||
elif hostSystem == 'Darwin': | ||
frontend = p.Popen(['components-darwin/frontend/crumbs.app/Contents/MacOS/crumbs']) | ||
|
||
print('frontend pid: ' + str(frontend.pid)) | ||
|
||
def exitHandler(): | ||
backend.kill() | ||
predictor.kill() | ||
# p.call(['kill',int(p.check_output(['pidof','-s','nn_crumbs']))]) | ||
print(int(p.check_output(['pidof','-s','nn_crumbs']))) | ||
predictorPid = int(p.check_output(['pidof','-s','nn_crumbs'])) | ||
os.kill(predictorPid, signal.SIGTERM) | ||
print('exiting app') | ||
|
||
atexit.register(exitHandler) | ||
|
||
frontend.wait() | ||
sys.exit(0) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# -*- mode: python -*- | ||
|
||
block_cipher = None | ||
|
||
|
||
a = Analysis(['crumbs.py'], | ||
pathex=['/home/low/crumbs/builing_dir'], | ||
binaries=[], | ||
datas=[], | ||
hiddenimports=[], | ||
hookspath=[], | ||
runtime_hooks=[], | ||
excludes=[], | ||
win_no_prefer_redirects=False, | ||
win_private_assemblies=False, | ||
cipher=block_cipher) | ||
pyz = PYZ(a.pure, a.zipped_data, | ||
cipher=block_cipher) | ||
exe = EXE(pyz, | ||
a.scripts, | ||
a.binaries, | ||
a.zipfiles, | ||
a.datas, | ||
name='crumbs', | ||
debug=False, | ||
strip=False, | ||
upx=True, | ||
console=True ) |
Binary file not shown.
90 changes: 90 additions & 0 deletions
90
dist/components-darwin/predictor/nn_crumbs.app/Contents/Info.plist
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>English</string> | ||
<key>CFBundleDisplayName</key> | ||
<string>nn_crumbs</string> | ||
<key>CFBundleExecutable</key> | ||
<string>nn_crumbs</string> | ||
<key>CFBundleIconFile</key> | ||
<string>nn_crumbs</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>org.pythonmac.unspecified.nn_crumbs</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>nn_crumbs</string> | ||
<key>CFBundlePackageType</key> | ||
<string>APPL</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>0.0.0</string> | ||
<key>CFBundleSignature</key> | ||
<string>????</string> | ||
<key>CFBundleVersion</key> | ||
<string>0.0.0</string> | ||
<key>LSHasLocalizedDisplayName</key> | ||
<false/> | ||
<key>NSAppleScriptEnabled</key> | ||
<false/> | ||
<key>NSHumanReadableCopyright</key> | ||
<string>Copyright not specified</string> | ||
<key>NSMainNibFile</key> | ||
<string>MainMenu</string> | ||
<key>NSPrincipalClass</key> | ||
<string>NSApplication</string> | ||
<key>PyMainFileNames</key> | ||
<array> | ||
<string>__boot__</string> | ||
</array> | ||
<key>PyOptions</key> | ||
<dict> | ||
<key>alias</key> | ||
<true/> | ||
<key>argv_emulation</key> | ||
<false/> | ||
<key>emulate_shell_environment</key> | ||
<false/> | ||
<key>no_chdir</key> | ||
<false/> | ||
<key>prefer_ppc</key> | ||
<false/> | ||
<key>site_packages</key> | ||
<false/> | ||
<key>use_faulthandler</key> | ||
<false/> | ||
<key>use_pythonpath</key> | ||
<false/> | ||
<key>verbose</key> | ||
<false/> | ||
</dict> | ||
<key>PyResourcePackages</key> | ||
<array> | ||
</array> | ||
<key>PyRuntimeLocations</key> | ||
<array> | ||
<string>@executable_path/../Frameworks/libpython2.7.dylib</string> | ||
<string>//anaconda/lib/libpython2.7.dylib</string> | ||
</array> | ||
<key>PythonInfoDict</key> | ||
<dict> | ||
<key>PythonExecutable</key> | ||
<string>//anaconda/bin/python</string> | ||
<key>PythonLongVersion</key> | ||
<string>2.7.12 |Anaconda 4.2.0 (x86_64)| (default, Jul 2 2016, 17:43:17) | ||
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)]</string> | ||
<key>PythonShortVersion</key> | ||
<string>2.7</string> | ||
<key>py2app</key> | ||
<dict> | ||
<key>alias</key> | ||
<true/> | ||
<key>template</key> | ||
<string>app</string> | ||
<key>version</key> | ||
<string>0.12</string> | ||
</dict> | ||
</dict> | ||
</dict> | ||
</plist> |
Binary file added
BIN
+35.5 KB
dist/components-darwin/predictor/nn_crumbs.app/Contents/MacOS/nn_crumbs
Binary file not shown.
5 changes: 5 additions & 0 deletions
5
dist/components-darwin/predictor/nn_crumbs.app/Contents/MacOS/python
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
XSym | ||
0021 | ||
c4a505b8f3aff1beee230ccfa9c4fc3f | ||
//anaconda/bin/python | ||
|
1 change: 1 addition & 0 deletions
1
dist/components-darwin/predictor/nn_crumbs.app/Contents/PkgInfo
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
APPL???? |
109 changes: 109 additions & 0 deletions
109
dist/components-darwin/predictor/nn_crumbs.app/Contents/Resources/__boot__.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
def _reset_sys_path(): | ||
# Clear generic sys.path[0] | ||
import sys, os | ||
resources = os.environ['RESOURCEPATH'] | ||
while sys.path[0] == resources: | ||
del sys.path[0] | ||
_reset_sys_path() | ||
|
||
|
||
def _site_packages(): | ||
import site, sys, os | ||
paths = [] | ||
prefixes = [sys.prefix] | ||
if sys.exec_prefix != sys.prefix: | ||
prefixes.append(sys.exec_prefix) | ||
for prefix in prefixes: | ||
paths.append(os.path.join(prefix, 'lib', 'python' + sys.version[:3], | ||
'site-packages')) | ||
if os.path.join('.framework', '') in os.path.join(sys.prefix, ''): | ||
home = os.environ.get('HOME') | ||
if home: | ||
paths.append(os.path.join(home, 'Library', 'Python', | ||
sys.version[:3], 'site-packages')) | ||
|
||
# Work around for a misfeature in setuptools: easy_install.pth places | ||
# site-packages way to early on sys.path and that breaks py2app bundles. | ||
# NOTE: this is hacks into an undocumented feature of setuptools and | ||
# might stop to work without warning. | ||
sys.__egginsert = len(sys.path) | ||
|
||
for path in paths: | ||
site.addsitedir(path) | ||
_site_packages() | ||
|
||
|
||
def _chdir_resource(): | ||
import os | ||
os.chdir(os.environ['RESOURCEPATH']) | ||
_chdir_resource() | ||
|
||
|
||
def _setup_ctypes(): | ||
from ctypes.macholib import dyld | ||
import os | ||
frameworks = os.path.join(os.environ['RESOURCEPATH'], '..', 'Frameworks') | ||
dyld.DEFAULT_FRAMEWORK_FALLBACK.insert(0, frameworks) | ||
dyld.DEFAULT_LIBRARY_FALLBACK.insert(0, frameworks) | ||
|
||
_setup_ctypes() | ||
|
||
|
||
def _path_inject(paths): | ||
import sys | ||
sys.path[:0] = paths | ||
|
||
|
||
_path_inject(['/Users/signapoop/Desktop/Crumbs/crumbs/builing_dir']) | ||
|
||
|
||
import re, sys | ||
cookie_re = re.compile(b"coding[:=]\s*([-\w.]+)") | ||
if sys.version_info[0] == 2: | ||
default_encoding = 'ascii' | ||
else: | ||
default_encoding = 'utf-8' | ||
|
||
def guess_encoding(fp): | ||
for i in range(2): | ||
ln = fp.readline() | ||
|
||
m = cookie_re.search(ln) | ||
if m is not None: | ||
return m.group(1).decode('ascii') | ||
|
||
return default_encoding | ||
|
||
def _run(): | ||
global __file__ | ||
import os, site | ||
sys.frozen = 'macosx_app' | ||
|
||
argv0 = os.path.basename(os.environ['ARGVZERO']) | ||
script = SCRIPT_MAP.get(argv0, DEFAULT_SCRIPT) | ||
|
||
sys.argv[0] = __file__ = script | ||
if sys.version_info[0] == 2: | ||
with open(script, 'rU') as fp: | ||
source = fp.read() + "\n" | ||
else: | ||
with open(script, 'rb') as fp: | ||
encoding = guess_encoding(fp) | ||
|
||
with open(script, 'r', encoding=encoding) as fp: | ||
source = fp.read() + '\n' | ||
|
||
BOM=b'\xef\xbb\xbf'.decode('utf-8') | ||
if source.startswith(BOM): | ||
source = source[1:] | ||
|
||
|
||
exec(compile(source, script, 'exec'), globals(), globals()) | ||
|
||
|
||
DEFAULT_SCRIPT='/Users/signapoop/Desktop/Crumbs/crumbs/builing_dir/nn_crumbs.py' | ||
SCRIPT_MAP={} | ||
try: | ||
_run() | ||
except KeyboardInterrupt: | ||
pass |
Oops, something went wrong.