Skip to content

Commit

Permalink
feat: Python3 Support (#60, unfinished)
Browse files Browse the repository at this point in the history
WIP: Python3 Support
  • Loading branch information
mkg20001 committed Aug 11, 2019
2 parents 71c3b7c + b86fdb1 commit b07ca66
Show file tree
Hide file tree
Showing 23 changed files with 89 additions and 71 deletions.
4 changes: 2 additions & 2 deletions .ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ disable_var() {
}

if [ -z "$CI_COMMIT_TAG" ]; then # build a nightly
replace_var package.domain luna.mkg20001
replace_var title ZeroNetN
replace_var package.domain luna3.mkg20001
replace_var title ZeroNetN3
# disable_var version.regex
# disable_var version.filename
# replace_var version "$CUR_VERSION.$(date +%s)"
Expand Down
16 changes: 4 additions & 12 deletions .ci/push-fdroid.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
#!/bin/bash

cd release

F=()
set -e

for apk in *; do
F+=(-F "apks=@$apk")
done
cd release

OUT=$(curl 'https://f-droid.mkg20001.io/1/' --compressed -H "$FDROID_TOKEN_1" -H "$FDROID_TOKEN_2" -H 'RM-Background-Type: apks' "${F[@]}")
CMD=$(echo "$FDROID_UPLOAD" | base64 -d)

if [ ! -z "$OUT" ]; then
echo "$OUT" >&2
echo "Signing failed!" >&2
exit 2
fi
eval $CMD
6 changes: 4 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_DRIVER: overlay2
IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
DOCKER_TLS: ""
DOCKER_TLS_CERTDIR: ""

before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
Expand Down Expand Up @@ -56,7 +58,7 @@ package:
script:
- ./.ci/package.sh
only:
- master
- py3
- tags
artifacts:
paths:
Expand All @@ -67,7 +69,7 @@ release-nightly:
script:
- ./.ci/release-nightly.sh
only:
- master
- py3
tags:
- argon
artifacts:
Expand Down
4 changes: 2 additions & 2 deletions .version.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash

CUR_VERSION="0.6.5"
CUR_VERSION="0.7.0"

VER_SUFFIX=2
VER_SUFFIX=1
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ env:
sudo add-apt-repository ppa:kivy-team/kivy -y
sudo apt-get update
sudo apt-get install -y build-essential cmake swig ccache git libtool pkg-config libncurses5:i386 libstdc++6:i386 libgtk2.0-0:i386 libpangox-1.0-0:i386 libpangoxft-1.0-0:i386 libidn11:i386 python2.7 python2.7-dev openjdk-8-jdk unzip zlib1g-dev zlib1g:i386
sudo apt-get install -y automake aidl libbz2-dev libffi-dev
sudo apt-get install -y automake aidl libbz2-dev libffi-dev lld
sudo apt-get install -y python-kivy
sudo pip2 install --upgrade "cython == 0.25"
sudo pip2 install --upgrade Cython==0.28.6
sudo pip2 install --upgrade colorama appdirs 'sh>=1.10,<1.12.5' jinja2 six clint requests
sudo pip2 install --upgrade git+https://github.com/mkg20001/buildozer kivy
sudo pip2 install "appdirs" "colorama>=0.3.3" 'sh>=1.10,<1.12.5' "jinja2" "six"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# ZeroNet-kivy
[简体中文](./README-zh-cn.md)
[Support](https://t.me/zeronet_android)

This app is a simple GUI to control the ZeroNet client. It is packaged using buildozer and uses [Kivy](https://kivy.io).

Expand Down
3 changes: 2 additions & 1 deletion buildozer.spec
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ version.filename = %(source.dir)s/zero/src/Config.py
# (list) Application requirements
# comma seperated e.g. requirements = sqlite3,kivy
requirements = sqlite3,typing,openssl,m2crypto,gevent==1.2.2,msgpack-python,pil,hostpython2,git+https://github.com/kivy/plyer,android,kivy,sentry_sdk,urllib3,certifi
requirements = sqlite3,openssl,m2crypto,'gevent-websocket>=0.10.1',gevent,'greenlet>=0.4.14',msgpack-python,hostpython3,git+https://github.com/kivy/plyer,android,kivy,sentry_sdk,urllib3,certifi,merkletools,coincurve,bitcoin,PySocks,bencode.py,python-bitcoinlib,maxminddb,websocket_client,pyasn1,rsa,pyelliptic==1.5.6,base58
p4a.branch = master
p4a.fork = mkg20001
# (str) Custom source folders for requirements
# Sets custom source for any requirements with recipes
Expand Down
6 changes: 3 additions & 3 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ class ZeronetApp(App):
def url_click(self, url):
full = "http://127.0.0.1:" + \
getConfigValue(self.service.config, "ui_port", "43110") + "/" + url
print "Opening in browser %s" % full
print("Opening in browser %s" % full)
browser(full)

def build(self):
print "Starting..."
print("Starting...")

print "Running on platform %s" % platform
print("Running on platform %s" % platform)

self.service = Service()
'''Starts 2 watchdog processes, which will then start zeronet'''
Expand Down
4 changes: 2 additions & 2 deletions src/platform_android.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

def getSystemLang():
l = mActivity.getResources().getConfiguration().locale.toString()
print "LOCALE: %s" % l
print("LOCALE: %s" % l)
match = re.search("^([a-z]{2})_[A-Z]+.*", l)
if match:
return match.group(1)
Expand Down Expand Up @@ -117,7 +117,7 @@ def getPath(self, append=""):

def runGeneric(self, what, pidid):
if self.isRunning(pidid):
print "Skip starting %s, already running as %s" % (what, self.getPid(pidid))
print("Skip starting %s, already running as %s" % (what, self.getPid(pidid)))
return False
service_fullname = activity.getPackageName() + '.Service' + what
service = autoclass(service_fullname)
Expand Down
6 changes: 3 additions & 3 deletions src/platform_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def getSystemLang(index=0):
l = ls[index]
if l is None:
return "en" # No locales
print "LOCALE: %s" % l
print("LOCALE: %s" % l)
match = re.search("^([a-z]{2})_[A-Z]+.*", str(l))
if match:
return match.group(1)
Expand Down Expand Up @@ -52,7 +52,7 @@ def __init__(self, threadID, name, counter, args):
def run(self):
# print "Starting "+self.name
self.args.communicate()
print self.name + " has exited"
print(self.name + " has exited")


class Service(SystemService):
Expand Down Expand Up @@ -80,7 +80,7 @@ def runService(self):

def runGeneric(self, what, name, pidid):
if self.isRunning(pidid):
print "Skip starting %s, already running as %s" % (name, self.getPid(pidid))
print("Skip starting %s, already running as %s" % (name, self.getPid(pidid)))
return False
self.count += 1
env = os.environ
Expand Down
20 changes: 10 additions & 10 deletions src/platform_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,29 @@ def needUpdate(src, dst, backup):
if conf is not None and confsrc is not None:
return parseRev(conf) < parseRev(confsrc)
else:
print "Some files are missing, need to update"
print("Some files are missing, need to update")
return True


def update(src, dst, backup):
if not needUpdate(src, dst, backup):
print "update not required, skipping"
print("update not required, skipping")
return
try:
if os.path.exists(backup):
# Prepare for updating the exiting code and importing data
shutil.rmtree(backup)
print "zero_backup removed"
print("zero_backup removed")
if os.path.exists(dst):
os.rename(dst, backup)
print "zero renamed to zero_backup"
print("zero renamed to zero_backup")
try:
# Copy ZeroNet entirely to external, shutil.copytree will refuse to
# copy if destination exists.
shutil.copytree(src, dst)
except:
traceback.print_exc()
print "zero copied to external zero"
print("zero copied to external zero")
if os.path.exists(backup):
for import_dir in ["data", "log", "zeronet.conf"]:
if os.path.exists(os.path.join(backup, import_dir)):
Expand All @@ -69,7 +69,7 @@ def update(src, dst, backup):
os.path.join(dst, import_dir)) # import data
except:
traceback.print_exc()
print "%s imported" % import_dir
print("%s imported" % import_dir)
except:
traceback.print_exc()

Expand All @@ -80,7 +80,7 @@ def setConfig(conf):

def defaultValue(key, value):
if key not in c:
print "Applying default value %s for field %s" % (value, key)
print("Applying default value %s for field %s" % (value, key))
saveConfigValue(conf, key, value)
defaultValue("language", os_platform.getSystemLang())
defaultValue("keep_ssl_cert", "")
Expand Down Expand Up @@ -128,11 +128,11 @@ def __init__(self):
self.platform = platform
self.count = 0
self.config = os.path.join(self.getPath("zero"), "zeronet.conf")
print "ZeroNet_Dir=%s" % self.dir
print("ZeroNet_Dir=%s" % self.dir)
mkdirp(self.dir)

def setEnv(self):
print "Setting Env"
print("Setting Env")
env = dict(
{'srcdir': self.getPath("zero"),
'platform': str(self.platform),
Expand Down Expand Up @@ -175,5 +175,5 @@ def run(self):
self.runZero()

def runZero(self):
print "Running ZeroNet"
print("Running ZeroNet")
self.runService()
13 changes: 7 additions & 6 deletions src/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,27 @@
notification = notifi.build()
Service.startForeground(233,notification)

print "env %s" % env
print("env %s" % env)

sys.path.insert(1, env['srcdir'])
print "srcdir: %s" % env['srcdir']
print "sys.path: %s" % sys.path
sys.path.insert(1, env['srcdir'] + '/src') # insert $src/src too, since sometimes it can't find itself
print("srcdir: %s" % env['srcdir'])
print("sys.path: %s" % sys.path)

os.chdir(env['srcdir'])

print "sys.argv: %s" % sys.argv
print("sys.argv: %s" % sys.argv)

with open(env['pidfile'], "w") as f:
f.write(str(os.getpid()))
f.close()

if True: # so beautification does not move this to the top
import zeronet
import zeronet # this is only available AFTER sys.path.insert, since it isn't anywhere in this directory


def main():
zeronet.main()
zeronet.start()

if __name__ == '__main__':
wrapSentry(main)
Expand Down
6 changes: 3 additions & 3 deletions src/translate/Translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ def __repr__(self):
def load(self):
if os.path.isfile(self.lang_file):
data = json.load(open(self.lang_file))
print "Loaded translate file: %s (%s entries)" % (self.lang_file, len(data))
print("Loaded translate file: %s (%s entries)" % (self.lang_file, len(data)))
dict.__init__(self, data)
return True
else:
data = {}
dict.__init__(self, data)
self.clear()
print "Translate file not exists: %s" % self.lang_file
print("Translate file not exists: %s" % self.lang_file)
return False

def format(self, s, kwargs, nested=False):
Expand Down Expand Up @@ -86,7 +86,7 @@ def translateData(self, data, translate_table=None, mode="js"):
data = data.decode("utf8")

patterns = []
for key, val in translate_table.items():
for key, val in list(translate_table.items()):
# Problematic string: only match if called between _(" ") function
if key.startswith("_("):
key = key.replace("_(", "").replace(
Expand Down
2 changes: 1 addition & 1 deletion src/translate/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from Translate import *
from .Translate import *
2 changes: 1 addition & 1 deletion src/translate/languages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"Peer-to-Peer Social Network":"Peer-zu-Peer Soziales Netzwerk",
"Reddit-Like, Decentralized Forum for China":"Reddit ähnliches, dezentralisiertes Forum für China",
"[b]Report a Bug[/b]": "[b]Fehler melden[/b]",
"[b]Help maintain this app[/b]": "[b]Helfe diese App zu pflegen[/b]"
"[b]Donate[/b]": "[b]Spenden[/b]"
}
4 changes: 2 additions & 2 deletions src/watchdog.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
if "watchdog_id" not in os.environ:
raise Exception("No watchdog id!")
id = int(os.environ["watchdog_id"])
print "This is watchdog %s" % id
print("This is watchdog %s" % id)

service = platform.Service()
service.setPid("watchdog%s" % str(id), os.getpid())
Expand All @@ -17,7 +17,7 @@
def isRunning(what):
i = service.isRunning(what)
if not i:
print "%s is not running, starting now" % what
print("%s is not running, starting now" % what)
# else:
# print "%s is running, pid=%s" % (what,service.getPid(what))
return i
Expand Down
2 changes: 1 addition & 1 deletion src/zero
Submodule zero updated 393 files
25 changes: 12 additions & 13 deletions src/zeronet.kv
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,25 @@ BoxLayout:
orientation: "vertical"

Label:
id: ZeroHello
text: "[ref=1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D][b]ZeroHello[/b][/ref]"
on_ref_press: app.url_click("1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D")
id: Support
text: "[ref=t.me/zeronet_android][b]Support[/b][/ref]"
on_ref_press: browser("https://t.me/zeronet_android")

Label:
id: ZeroHelloDesc
text: _("ZeroNet Homepage")
id: SupportDesc
text: _("Android App Discussion & Support")

BoxLayout:
orientation: "vertical"

Label:
id: ZeroBoard
text: "[ref=Board.ZeroNetwork.bit][b]ZeroBoard[/b][/ref]"
on_ref_press: app.url_click("Board.ZeroNetwork.bit")
id: ZeroHello
text: "[ref=1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D][b]ZeroHello[/b][/ref]"
on_ref_press: app.url_click("1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D")

Label:
id: ZeroBoardDesc
text: _("Simple Messaging Board")
id: ZeroHelloDesc
text: _("ZeroNet Homepage")

BoxLayout:
orientation: "vertical"
Expand Down Expand Up @@ -169,9 +169,8 @@ BoxLayout:
background_color:hex("#AFAFAF")
on_press:
self.background_color=hex("#6F6F6F")
browser("https://github.com/HelloZeroNet/ZeroNet-kivy/issues/35")
browser("https://paypal.me/mkg20001")
on_release:
self.background_color=hex("#AFAFAF")
id: Note
text: _("[b]Help maintain this app[/b]")
font_size: "10sp"
text: _("[b]Donate[/b]")
4 changes: 2 additions & 2 deletions src/zeronet_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ConfigParser
import configparser
import os


Expand All @@ -9,7 +9,7 @@ def parseConfig(config_file):
# Load config file
res = dict({})
if os.path.isfile(config_file):
config = ConfigParser.ConfigParser(allow_no_value=True)
config = configparser.ConfigParser(allow_no_value=True)
config.read(config_file)
for section in config.sections():
for key, val in config.items(section):
Expand Down
2 changes: 1 addition & 1 deletion tool.sh
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ case "$1" in
V=$(echo $(cat src/zero/src/Config.py | grep self.version | sed -r "s|self\.version = ['\"](.*)['\"]|\1|g" | head -n 1))
if [ "$V" != "$CUR_VERSION" ]; then echo ".version.sh \$VER_SUFFIX needs to be reset, major version change: $CUR_VERSION != $V" && exit 2; fi
cd src/zero && cp src/Config.py src/Config.py_ && sed -r "s|self\.version = ['\"](.*)['\"]|self.version = \"\1.$VER_SUFFIX\"|g" -i src/Config.py
echo ZGlmZiAtLWdpdCBhL3NyYy9Db25maWcucHkgYi9zcmMvQ29uZmlnLnB5CmluZGV4IGZkN2IwNmJjLi45NTkwNTdmNSAxMDA2NDQKLS0tIGEvc3JjL0NvbmZpZy5weQorKysgYi9zcmMvQ29uZmlnLnB5CkBAIC01NzgsNyArNTc4LDcgQEAgY2xhc3MgQ29uZmlnKG9iamVjdCk6CiAKICAgICAgICAgbG9nZ2luZy5nZXRMb2dnZXIoJycpLm5hbWUgPSAiLSIgICMgUmVtb3ZlIHJvb3QgcHJlZml4CiAKLSAgICAgICAgc2VsZi5pbml0Q29uc29sZUxvZ2dlcigpCisgICAgICAgICMgc2VsZi5pbml0Q29uc29sZUxvZ2dlcigpCiAgICAgICAgIHNlbGYuaW5pdEZpbGVMb2dnZXIoKQogCiBjb25maWcgPSBDb25maWcoc3lzLmFyZ3YpCg== | base64 -d | git apply -
echo ZGlmZiAtLWdpdCBhL3NyYy9tYWluLnB5IGIvc3JjL21haW4ucHkKaW5kZXggZGZjMzJjYzkuLjlmMjFlZjJjIDEwMDY0NAotLS0gYS9zcmMvbWFpbi5weQorKysgYi9zcmMvbWFpbi5weQpAQCAtNTIsNyArNTIsNyBAQCBpZiBjb25maWcuYWN0aW9uID09ICJtYWluIjoKICAgICAgICAgICAgICAgICBwcmludCgiRXJyb3Igc3RhcnRpbmcgYnJvd3NlcjogJXMiICUgZXJyKQogICAgICAgICBzeXMuZXhpdCgpCiAKLWNvbmZpZy5pbml0TG9nZ2luZygpCitjb25maWcuaW5pdExvZ2dpbmcoY29uc29sZV9sb2dnaW5nPUZhbHNlKQogCiAKICMgRGVidWcgZGVwZW5kZW50IGNvbmZpZ3VyYXRpb24K | base64 -d | git apply -
cd ../../
touch .pre
;;
Expand Down
Loading

0 comments on commit b07ca66

Please sign in to comment.