Skip to content

Commit

Permalink
lint fixes;
Browse files Browse the repository at this point in the history
  • Loading branch information
twiddli committed Feb 11, 2018
1 parent 8b8ca59 commit c18d69f
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 65 deletions.
5 changes: 4 additions & 1 deletion HPtoHPX.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,8 @@ def _page_gen(items):
pages.append((os.path.split(c)[1], c, n, True))
n += 1
finally:
if afs: afs.close()
if afs:
afs.close()
else:
page_hash = (ch_path,)
dir_images = [
Expand All @@ -764,6 +765,7 @@ def _page_gen(items):

yield (page_hash, gallery, pages)


def page_generate(rar_p, args, out_pipe):
rarfile.UNRAR_TOOL = rar_p
item_id, items = args
Expand Down Expand Up @@ -1022,6 +1024,7 @@ def main(args=sys.argv[1:]):

page_pool = []
thread_pool = []

def create_process(items):
pipe1, pipe2 = Pipe(False)
p = Process(target=page_generate, args=(args.rar, items, pipe2), daemon=True)
Expand Down
4 changes: 2 additions & 2 deletions happypanda/common/hlogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ def _log(self, level, *args, stdout=False, stderr=False):

# prevent printing multiple times
if not (constants.dev and not constants.is_frozen):
def p(x):
def p(x):
if stdout:
print(x)
if stderr:
eprint(x)
try:
p(s)
except OSError: # raw write() returned invalid length 64 (should have been between 0 and 32)
except OSError: # raw write() returned invalid length 64 (should have been between 0 and 32)
# fixed in python 3.6+
s = s.encode("utf-8", errors="ignore").decode("ascii")
p(s)
Expand Down
9 changes: 5 additions & 4 deletions happypanda/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from happypanda.common import constants, exceptions, hlogger, config
try:
import winreg
except ImportError: # only available on windows
except ImportError: # only available on windows
pass

log = hlogger.Logger(__name__)
Expand Down Expand Up @@ -115,7 +115,6 @@ def get_argparser():
parser.add_argument('--momo', nargs=argparse.REMAINDER,
help='Reserved (Momo best girl)')


return parser


Expand Down Expand Up @@ -447,13 +446,15 @@ def remove_from_startup(name):
return win32_del_reg(r"Software\Microsoft\Windows\CurrentVersion\Run",
name)


def is_elevated():
if constants.is_win:
try:
return ctypes.windll.shell32.isUserAnAdmin()
except:
except BaseException:
return False


def run_with_privileges(func, *args):
if is_elevated():
print("hi")
Expand All @@ -465,7 +466,7 @@ def run_with_privileges(func, *args):
if not constants.is_frozen:
params = ['run.py']
params += ['--momo'] + list(args)

if constants.is_win:
print(prog)
ctypes.windll.shell32.ShellExecuteW(None, "runas", prog, subprocess.list2cmdline(params), None, 1)
Expand Down
4 changes: 2 additions & 2 deletions happypanda/core/commands/meta_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ def main(self, download_url=None, restart=True, silent=True, push=False) -> bool
else:
m = "The update will be installed on the next startup"
msg = message.Notification(
m,
"A new update is pending to be installed")
m,
"A new update is pending to be installed")
msg.id = constants.PushID.Update.value
self.push(msg)
self.update.emit(st, restart)
Expand Down
2 changes: 1 addition & 1 deletion happypanda/core/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ class WebServer:
happyweb = Flask(__name__, static_url_path='/static',
template_folder=os.path.abspath(constants.dir_templates),
static_folder=os.path.abspath(constants.dir_static))
happyweb.config['PROPAGATE_EXCEPTIONS'] = True # enable only on debug?
happyweb.config['PROPAGATE_EXCEPTIONS'] = True # enable only on debug?
socketio = SocketIO(happyweb, async_mode="gevent")

def run(self, host, port, debug=False, logging_queue=None, cmd_args=None):
Expand Down
10 changes: 5 additions & 5 deletions happypanda/core/web/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,9 @@ def server_proxy():
def app_base(path):
try:
return render_template('base.html',
dev=constants.dev,
same_machine=is_same_machine(),
version=".".join(str(x) for x in constants.version_web))
except:
dev=constants.dev,
same_machine=is_same_machine(),
version=".".join(str(x) for x in constants.version_web))
except BaseException:
log.exception("Unknown exception occurred in views")
# todo: redirect to error page?
# todo: redirect to error page?
6 changes: 5 additions & 1 deletion happypanda/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

log = hlogger.Logger(__name__)
parser = utils.get_argparser() # required to be at module lvl for sphinx.autoprogram ext


def check_update():
with utils.intertnal_db() as db:
update_info = db.get(constants.updater_key, {})
Expand All @@ -48,6 +50,7 @@ def check_update():
state = update_info['state']
return state


def start(argv=None, db_kwargs={}):
assert sys.version_info >= (3, 5), "Python 3.5 and up is required"
e_code = None
Expand All @@ -71,7 +74,8 @@ def start(argv=None, db_kwargs={}):
log.i("\n{}".format(utils.os_info()))
if args.gen_config:
config.config.save_default()
log.i("Generated example configuration file at {}".format(io_cmd.CoreFS(constants.config_example_path).path), stdout=True)
log.i("Generated example configuration file at {}".format(
io_cmd.CoreFS(constants.config_example_path).path), stdout=True)
return

update_state = check_update()
Expand Down
4 changes: 2 additions & 2 deletions templates/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def notif(msg, header="", level="info", icon=None, **kwargs):
"customFields": {
"content": msg,
"header": header,
"mskwargs": {level: True,
"mskwargs": {level: True,
"icon": icon,
"style": {"whiteSpace": "pre-wrap"}
}
Expand Down Expand Up @@ -121,7 +121,7 @@ def server_notifications(data=js_undefined, error=None):
else:
tmout = 20000
ic = "info"
if data['id'] in [1,]:
if data['id'] in [1, ]:
tmout = tmout * 2
ic = "angle double up"
this.notif(data['body'], data['title'], icon=ic, timeout=tmout)
Expand Down
84 changes: 44 additions & 40 deletions templates/src/pages/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,14 @@ def set_thumbs(cmd):
p = d[pnumb]['data']
d[pnumb]['img'] = values[this.cmd_data[p.id]]['data']
this.setState({'pages': d})


__pragma__("nojsiter")


__pragma__("kwargs")


def get_thumbs(data=None, error=None, other=None):
if data is not None and not error:
this.cmd_data = data
Expand All @@ -66,8 +69,6 @@ def get_thumbs(data=None, error=None, other=None):
item_type=this.state.item_type)




def get_pages(data=None, error=None, gid=None):
if data is not None and not error:
pages = this.state.pages
Expand All @@ -80,11 +81,12 @@ def get_pages(data=None, error=None, gid=None):
if this.state.data:
gid = this.state.data.gallery_id
page = this.state.page_list_page
this.setState({'page_list_loading': True, "page_list_page":page+1})
this.setState({'page_list_loading': True, "page_list_page": page + 1})
limit = 50
client.call_func("get_related_items",
this.get_pages, item_type=ItemType.Gallery,
item_id=gid, limit=limit, offset=page*limit)
this.get_pages, item_type=ItemType.Gallery,
item_id=gid, limit=limit, offset=page * limit)


__pragma__("nokwargs")

Expand All @@ -98,7 +100,7 @@ def get_item(ctx=None, data=None, error=None):
this.get_pages(gid=data.gallery_id)
else:
if not utils.get_query("retry"):
utils.go_to(this.props.history, query={"number": 1, "retry":True}, push=False)
utils.go_to(this.props.history, query={"number": 1, "retry": True}, push=False)
elif error:
state.app.notif("Failed to fetch item ({})".format(this.state.id), level="error")
else:
Expand Down Expand Up @@ -141,6 +143,7 @@ def get_page_count(data=None, error=None, gid=None):
client.call_func("get_related_count", this.get_page_count, item_type=item, item_id=item_id,
related_type=this.state.item_type)


__pragma__("nokwargs")


Expand All @@ -149,13 +152,14 @@ def on_key(ev):
gallery_id = this.state.data.gallery_id
number = this.state.data.number
page_count = this.state.page_count

def go_prev(): return utils.go_to(
history,
query={
'gid': gallery_id,
"number": number - 1})

def go_next():
def go_next():
if int(number) < int(page_count):
return utils.go_to(
history,
Expand Down Expand Up @@ -185,14 +189,15 @@ def go_last(): return utils.go_to(

def on_update(p_props, p_state):
if p_state.data != this.state.data:
query={
query = {
'gid': this.state.data.gallery_id,
"number": this.state.data.number}
this.setState({'config_visible': False})
if not this.state.cfg_pagelist_open:
this.setState({'pages_visible': False})
utils.go_to(this.props.history, query=query, push=False)


def receive_props(n_props):
if n_props.location != this.props.location:
this.get_item()
Expand Down Expand Up @@ -248,22 +253,21 @@ def page_render():
p_url = utils.build_url(query={'gid': gid, "number": int(number) - 1})

thumb = e(thumbitem.Thumbnail,
img=img,
item_id=p_id,
item_type=this.state.item_type,
size_type=ImageSize.Original,
centered=True,
fluid=False,
bordered=True,
placeholder="",
inverted=this.state.cfg_invert,
style=thumb_style,
className=thumb_class
)
img=img,
item_id=p_id,
item_type=this.state.item_type,
size_type=ImageSize.Original,
centered=True,
fluid=False,
bordered=True,
placeholder="",
inverted=this.state.cfg_invert,
style=thumb_style,
className=thumb_class
)
if n_url:
thumb = e(Link, thumb, to=n_url)


rows = []

rows.append(e(ui.Table.Row,
Expand Down Expand Up @@ -308,30 +312,30 @@ def page_render():
set_page = this.set_page
return e(ui.Sidebar.Pushable,
e(ui.Ref,
e(ui.Sidebar,
e(itemview.SimpleView,
e(ui.Card.Group,
*[e(pageitem.Page,
data=all_pages[x]['data'],
centered=True,
link=False,
onClick=set_page,
) for x in all_pages],
itemsPerRow=2,
),
on_load_more=this.on_pagelist_load_more,
loading=this.state.page_list_loading,
context=this.state.page_list_ref,
),
as_=ui.Segment,
e(ui.Sidebar,
e(itemview.SimpleView,
e(ui.Card.Group,
*[e(pageitem.Page,
data=all_pages[x]['data'],
centered=True,
link=False,
onClick=set_page,
) for x in all_pages],
itemsPerRow=2,
),
on_load_more=this.on_pagelist_load_more,
loading=this.state.page_list_loading,
context=this.state.page_list_ref,
),
as_=ui.Segment,
size="small",
visible=this.state.pages_visible,
direction="left",
animation="overlay",
loading=this.state.pages_loading,
),
innerRef=this.set_pagelist_ref,
),
innerRef=this.set_pagelist_ref,
),
e(ui.Sidebar,
e(ui.Form,
e(ui.Form.Select, options=cfg_direction, label=tr(this, "", "Reading Direction"),
Expand Down Expand Up @@ -393,7 +397,7 @@ def page_render():
'getInitialState': lambda: {'id': int(utils.get_query("id", 0)),
'gid': int(utils.get_query("gid", 0)),
'pages': {},
'page_list_ref':None,
'page_list_ref': None,
'page_list_page': 0,
'page_list_loading': False,
'page_count': 0,
Expand Down
2 changes: 2 additions & 0 deletions templates/src/single/pageitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ def page_on_update(p_props, p_state):
if p_props.data != this.props.data:
this.setState({'data': this.props.data, 'id': this.props.data.id if this.props.data else None})


def page_on_click(e):
if this.props.onClick:
this.props.onClick(e, this.state.data)


def page_render():
fav = 0
title = ""
Expand Down
3 changes: 3 additions & 0 deletions templates/src/single/thumbitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,14 @@ def thumbnail_did_mount():
this.is_mounted = True
if not this.props.img:
this.get_thumb()


def thumbnail_will_unmount():
this.is_mounted = False
if this.state.active_cmd:
this.state.active_cmd.stop()


def thumbnail_render():
img_url = this.state.placeholder
if this.state.img:
Expand Down

0 comments on commit c18d69f

Please sign in to comment.