Skip to content

Commit

Permalink
lint fixes;
Browse files Browse the repository at this point in the history
  • Loading branch information
twiddli committed Feb 27, 2018
1 parent ae7854c commit 97c011b
Show file tree
Hide file tree
Showing 16 changed files with 78 additions and 66 deletions.
2 changes: 2 additions & 0 deletions bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,11 +447,13 @@ def deploy(args, unknown=None):
print("{}\n\tSHA256 Checksum: {}".format(output_path_a, updater.sha256_checksum(output_path_a)))
print("Done")


def file_checksum(args, u=None):
_activate_venv()
from happypanda.core import updater
print("{}\n\tSHA256 Checksum: {}".format(args.f, updater.sha256_checksum(args.f)))


welcome_msg = """
Welcome to HPX development helper script.
Expand Down
2 changes: 1 addition & 1 deletion happypanda/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class PushID(enum.Enum):

maximum_native_workers = 15

command_progress_removal_time = 60*5 # seconds
command_progress_removal_time = 60 * 5 # seconds

image_sizes = {
"big": (300, 416),
Expand Down
11 changes: 6 additions & 5 deletions happypanda/core/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import weakref
import sys
import itertools
import arrow

from contextlib import contextmanager
from abc import ABCMeta, abstractmethod
Expand Down Expand Up @@ -154,6 +153,7 @@ def merge_progress_into(self, cmd):

def _str_progress_tree(self):
self._tree_reader = ""

def w(l):
self._tree_reader = l.decode('utf-8') + '\n'

Expand All @@ -163,7 +163,6 @@ def w(l):
self._tree_reader = "Tree is empty"
return self._tree_reader


def get_progress(self):

if self._progress_tree:
Expand Down Expand Up @@ -196,7 +195,7 @@ def get_progress(self):
prog_subtitle = cmd._progress_title
prog_subtype = cmd._progress_type
if p['max']:
p['percent'] = (100/p['max'])*p['value']
p['percent'] = (100 / p['max']) * p['value']
else:
p['percent'] = -1.0
p['text'] = prog_text
Expand All @@ -205,7 +204,6 @@ def get_progress(self):
return p
return None


def set_progress(self, value=None, text=None, title=None, type_=None):
assert value is None or isinstance(value, (int, float))
assert text is None or isinstance(text, str)
Expand Down Expand Up @@ -305,7 +303,10 @@ def _main_wrap(self, *args, **kwargs):
if self._progress_max is not None:
self.set_progress(self._progress_max)
if self._progress_count and self._progress_count in self._progresses:
gevent.spawn_later(constants.command_progress_removal_time, lambda: self._progresses.pop(self._progress_count))
gevent.spawn_later(
constants.command_progress_removal_time,
lambda: self._progresses.pop(
self._progress_count))
self._finished_time = arrow.now()
return r

Expand Down
1 change: 0 additions & 1 deletion happypanda/core/commands/database_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ def _update_db(self, stale_cover, item_id, model, old_hash):
s.commit()
self.next_progress()


def _generate_and_add(self, img_hash, old_img_hash, generate, model, item_id, image_size, profile_size):

model_name = db.model_name(model)
Expand Down
16 changes: 7 additions & 9 deletions happypanda/core/commands/download_cmd.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
from happypanda.common import hlogger, constants
from happypanda.core.command import AsyncCommand
from happypanda.core.services import DownloadService
from happypanda.core.commands import networkcmd
#from happypanda.common import hlogger, constants
#from happypanda.core.command import AsyncCommand
#from happypanda.core.services import DownloadService
#from happypanda.core.commands import networkcmd

log = hlogger.Logger(__name__)
#log = hlogger.Logger(__name__)


#class GalleryDownload(AsyncCommand):
# class GalleryDownload(AsyncCommand):
# """
# Download items
# """

# def __init__(self, service = None, priority = constants.Priority.Low):
# assert isinstance(service, DownloadService)
# super().__init__(service, priority)

# def main(self, *requests):
# return super().main(*args, **kwargs)


4 changes: 2 additions & 2 deletions happypanda/core/commands/meta_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class CheckUpdate(AsyncCommand):
Check for new release
"""

def __init__(self, service = None, priority = constants.Priority.Low):
def __init__(self, service=None, priority=constants.Priority.Low):
return super().__init__(service, priority)

def main(self, silent=True, force=False, push=False) -> dict:
Expand Down Expand Up @@ -58,7 +58,7 @@ class UpdateApplication(AsyncCommand):

update = CommandEvent("update", bool, bool)

def __init__(self, service = None, priority = constants.Priority.Low):
def __init__(self, service=None, priority=constants.Priority.Low):
return super().__init__(service, priority)

def main(self, download_url=None, restart=True, silent=True, push=False) -> bool:
Expand Down
5 changes: 3 additions & 2 deletions happypanda/core/commands/networkcmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def save(self, filepath, decode_unicode=False, extension=False):
if extension:
filepath = io_cmd.CoreFS(filepath.path + io_cmd.CoreFS(os.path.split(self._url)[1]).ext, filepath._archive)

self.set_max_progress(int(self._rsp.headers.get('Content-Length', '0').strip())+1)
self.set_max_progress(int(self._rsp.headers.get('Content-Length', '0').strip()) + 1)
self.set_progress(type_=enums.ProgressType.Request)
log.d("Saving to filepath", filepath)
with filepath.open(mode="wb") as f:
Expand All @@ -102,7 +102,8 @@ def save(self, filepath, decode_unicode=False, extension=False):
for data in self._rsp.iter_content(chunk_size=1024, decode_unicode=decode_unicode):
data_len = len(data)
dl_length += data_len
self.next_progress(data_len, text="[{0:.3f} mbps] - {1}".format((dl_length/1000000)/max((arrow.now() - s_time).seconds, 1), self._url))
self.next_progress(
data_len, text="[{0:.3f} mbps] - {1}".format((dl_length / 1000000) / max((arrow.now() - s_time).seconds, 1), self._url))
f.write(data)
f.flush()
else:
Expand Down
3 changes: 2 additions & 1 deletion happypanda/core/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def check_release(silent=True, cmd=None):
repo_name = config.github_repo.value['repo']
repo_owner = config.github_repo.value['owner']
try:
r = SimpleGETRequest("https://api.github.com/repos/{}/{}/tags".format(repo_owner, repo_name)).merge(cmd).run()
r = SimpleGETRequest(
"https://api.github.com/repos/{}/{}/tags".format(repo_owner, repo_name)).merge(cmd).run()
data = r.json
with utils.intertnal_db() as db:
tags = [x['name'] for x in data] if data else []
Expand Down
3 changes: 2 additions & 1 deletion happypanda/interface/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ class ItemSort(_APIEnum):
#: Tag
NamespaceTagTag = 31


class ProgressType(_APIEnum):

#: Unknown
Expand All @@ -197,4 +198,4 @@ class ProgressType(_APIEnum):
#: A check for new update
CheckUpdate = 3
#: Updating application
UpdateApplication = 4
UpdateApplication = 4
3 changes: 1 addition & 2 deletions happypanda/interface/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def get_command_state(command_ids: list):
def get_command_progress(command_ids: list = None):
"""
Get progress of command operation
If the command did not set a maximum value, the returned percent will be set to less than ``0.0`` for infinity.
This should be polled every few seconds to get updated values.
Expand Down Expand Up @@ -311,7 +311,6 @@ def get_command_progress(command_ids: list = None):
"""
_command_msg(command_ids)


cmd_p = []
if command_ids is not None:
for i in command_ids:
Expand Down
1 change: 1 addition & 0 deletions templates/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def on_update(props):
# TODO: scroll restoration
window.scrollTo(0, 0)


def on_path_mount():
state.history = this.props.history

Expand Down
5 changes: 4 additions & 1 deletion templates/src/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class ItemSort:
#: Tag
NamespaceTagTag = 31


class ProgressType:

#: Unknown
Expand All @@ -95,10 +96,12 @@ class ProgressType:
#: Updating application
UpdateApplication = 4


class PushID():
Update = 1
User = 200


def log(msg):
if state.debug:
print(msg)
Expand Down Expand Up @@ -534,7 +537,7 @@ def get_value(self, cmd_id=None, block=False):
self.poll_until_complete(3000)
while True:
if self.finished():
break
break

if ids:
self._fetch_value(cmd_ids=ids)
Expand Down
1 change: 1 addition & 0 deletions templates/src/pages/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ def abouttab_check_update_value(cmd):
state.new_update = True
this.setState({"update_msg": cmd_data, 'update_checking': False})


def abouttab_check_update(data=None, error=None):
if data is not None and not error:
cmd = Command(data)
Expand Down
82 changes: 43 additions & 39 deletions templates/src/pages/downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from src.state import state
from src import utils


def get_progress(data=None, error=None):
if data is not None and not error:
this.setState({"data": data})
Expand All @@ -19,10 +20,12 @@ def get_progress(data=None, error=None):
if state['active'] and state['connected']:
client.call_func("get_command_progress", this.get_progress)


def page_mount():
this.get_progress()
this.interval_func = setInterval(this.get_progress, 1500)


def page_render():

els = []
Expand All @@ -47,57 +50,58 @@ def page_render():
kwargs['autoSuccess'] = False

els.append(e(ui.List.Item,
e(ui.List.Content,
e(ui.List.Header, p_title),
e(ui.Progress, *([p.subtitle] if p.subtitle else []),
precision=2,
indicating=True,
active=True,
**kwargs),
e(ui.List.Description,
e(ui.List,
e(ui.List.Item,e(ui.List.Content, utils.moment.unix(p.timestamp).fromNow())),
e(ui.List.Item,e(ui.List.Content, p.text)),
horizontal=True,
divided=True,
),
className="sub-text"),
)
))
e(ui.List.Content,
e(ui.List.Header, p_title),
e(ui.Progress, *([p.subtitle] if p.subtitle else []),
precision=2,
indicating=True,
active=True,
**kwargs),
e(ui.List.Description,
e(ui.List,
e(ui.List.Item, e(ui.List.Content, utils.moment.unix(p.timestamp).fromNow())),
e(ui.List.Item, e(ui.List.Content, p.text)),
horizontal=True,
divided=True,
),
className="sub-text"),
)
))

return e(ui.Container,
e(ui.Form,
e(ui.Form.Group,
e(ui.Form.Input,
width=16,
fluid=True,
action={'color': 'teal', 'icon':'download'}),
placeholder=tr(this, "", "Click to see supported URLs"),
),
),
e(ui.Divider, section=True),
e(ui.List,
*els,
selection=True,
relaxed="very",
divided=True,
animated=True,
),
)
e(ui.Form,
e(ui.Form.Group,
e(ui.Form.Input,
width=16,
fluid=True,
action={'color': 'teal', 'icon': 'download'}),
placeholder=tr(this, "", "Click to see supported URLs"),
),
),
e(ui.Divider, section=True),
e(ui.List,
*els,
selection=True,
relaxed="very",
divided=True,
animated=True,
),
)


Page = createReactClass({
'displayName': 'DownloadsPage',
'interval_func': None,

'componentWillMount': lambda: this.props.menu([
e(ui.Menu.Item, js_name=tr(this, "", "Batch URLs")),
]),
]),
'componentDidMount': page_mount,
'componentWillUnmount': lambda: clearInterval(this.interval_func) if this.interval_func else None,

'getInitialState': lambda: {
'data': [],
},
'data': [],
},

'get_progress': get_progress,

Expand Down
3 changes: 2 additions & 1 deletion templates/src/pages/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ def get_page_count(data=None, error=None, gid=None):


def on_key(ev):
if ev.preventDefaulted: return
if ev.preventDefaulted:
return

history = this.props.history
gallery_id = this.state.data.gallery_id
Expand Down
2 changes: 1 addition & 1 deletion templates/src/state.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

state = {
'app': None,
'history': None, # router history
'history': None, # router history
'container_ref': None, # main conatiner
'commands': set(),
'debug': True,
Expand Down

0 comments on commit 97c011b

Please sign in to comment.