Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
kitabatake1013 committed Feb 1, 2022
2 parents 7a4c90a + b8f10c2 commit 9a6c98b
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 37 deletions.
19 changes: 11 additions & 8 deletions AppBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@
#Application Initializer

import accessible_output2.outputs
from accessible_output2.outputs.base import OutputError
import sys
import datetime
import gettext
import logging
import wx
import locale
import logging
import os
import sys
import traceback
import win32api
import datetime
import wx

from accessible_output2.outputs.base import OutputError
from logging import getLogger, FileHandler, Formatter

import constants
import DefaultSettings
import views.langDialog
import simpleDialog
import os
import traceback


class MainBase(wx.App):
def __init__(self):
Expand Down Expand Up @@ -111,7 +113,8 @@ def LoadSettings(self):
#初回起動
self.config.read_dict(DefaultSettings.initialValues)
self.config.write()
self.hLogHandler.setLevel(self.config.getint("general","log_level",20,0,50))
if self.log.hasHandlers():
self.hLogHandler.setLevel(self.config.getint("general","log_level",20,0,50))

def InitTranslation(self):
"""翻訳を初期化する。"""
Expand Down
33 changes: 30 additions & 3 deletions ConfigManager.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
# -*- coding: utf-8 -*-
#ConfigManager
#Copyright (C) 2019-2020 yamahubuki <[email protected]>
#Copyright (C) 2019-2022 yamahubuki <[email protected]>

import os
import configparser
import logging
from logging import getLogger


import errorCodes

class ConfigManager(configparser.ConfigParser):
def __init__(self):
super().__init__(interpolation=None)
self.identifier="ConfigManager"
self.log=getLogger(self.identifier)
self.log.debug("Create config instance")
self.fileName = None

def read(self,fileName):
self.fileName=fileName
Expand All @@ -31,7 +32,33 @@ def read(self,fileName):

def write(self):
self.log.info("write configFile:"+self.fileName)
with open(self.fileName,"w", encoding='UTF-8') as f: return super().write(f)
try:
with open(self.fileName,"w", encoding='UTF-8') as f: super().write(f)
return errorCodes.OK
except PermissionError as e:
self.log.warning("write failed." + str(e))
return errorCodes.ACCESS_DENIED
except FileNotFoundError as e:
self.log.warning("write failed." + str(e))
dirName = os.path.dirname(self.fileName)
self.log.info("try to create directory:"+dirName)
try:
os.makedirs(dirName, exist_ok=True)
except:
self.log.error("auto directory creation failed.")
return errorCodes.ACCESS_DENIED
try:
with open(self.fileName,"w", encoding='UTF-8') as f: super().write(f)
return errorCodes.OK
except:
self.log.error("save failed.")
return errorCodes.ACCESS_DENIED

def getFileName(self):
return self.fileName

def getAbsFileName(self):
return os.path.abspath(self.fileName)

def __getitem__(self,key):
try:
Expand Down
3 changes: 1 addition & 2 deletions NPC.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def exchandler(type, exc, tb):
f.close()
except:
pass
simpleDialog.winDialog("error", "An error has occured. Contact to the developer for further assistance. Detail:" + "\n".join(msg[-2:]))
simpleDialog.winDialog("error", "An error has occurred. Contact to the developer for further assistance. Detail:" + "\n".join(msg[-2:]))
sys.exit(1)

sys.excepthook=exchandler
Expand All @@ -43,7 +43,6 @@ def main():
globalVars.app=app
app.initialize()
app.MainLoop()
app.config.write()

#global schope
if __name__ == "__main__": main()
5 changes: 5 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@

import AppBase
import constants
import errorCodes
import filter
import globalVars
import proxyUtil
import simpleDialog
import update

class Main(AppBase.MainBase):
Expand Down Expand Up @@ -76,6 +78,9 @@ def OnExit(self):

self._releaseMutex()

if self.config.write() != errorCodes.OK:
simpleDialog.errorDialog(_("設定の保存に失敗しました。下記のファイルへのアクセスが可能であることを確認してください。") + "\n" + self.config.getAbsFileName())

# アップデート
globalVars.update.runUpdate()

Expand Down
4 changes: 2 additions & 2 deletions constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
APP_FULL_NAME = "windows Native Peing Connector"#アプリケーションの完全な名前
APP_NAME="NPC"#アプリケーションの名前
APP_ICON = None
APP_VERSION="1.3.0"
APP_LAST_RELEASE_DATE="2021-12-18"
APP_VERSION="1.3.1"
APP_LAST_RELEASE_DATE="2022-02-02"
APP_COPYRIGHT_YEAR="2021"
APP_LICENSE="Apache License 2.0"
APP_DEVELOPERS="yamahubuki, ACT Laboratory"
Expand Down
10 changes: 6 additions & 4 deletions dao/userDao.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ def get(self,id):
assert type(id)==int
return self.select("SELECT * FROM users WHERE id = ?;",(id,))

#指定したフラグが立っていないユーザの一覧を得る
#指定したフラグが立っていないユーザ1人を得る
def getWithoutFlag(self,id,disableFlag):
assert type(id)==int
return self.select("SELECT * FROM users WHERE id = ? AND flag&?==0;",(id,disableFlag))

ret = self.select("SELECT * FROM users WHERE id = ? AND flag&?==0;",(id,disableFlag))
if ret:
return ret[0]
return ret

def getFromUserAccount(self, account):
assert type(account)==str
Expand All @@ -64,7 +66,7 @@ def update(self,values):
profile = :profile,
followees = :followees,
flag = :flag
WHERE id = :id;""", values)
WHERE id = :id;""", values).rowcount

def delete(self,id):
return self.connection.execute("DELETE FROM users WHERE id = ?;",(id,))
2 changes: 2 additions & 0 deletions errorCodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
PEING_ERROR=5
TWITTER_ERROR=6
CANCELED=7
ACCESS_DENIED=8


LOGIN_WRONG_PASSWORD=8 #ID/PW誤り
LOGIN_CONFIRM_NEEDED=9 #ユーザによる権限付与が必要
Expand Down
4 changes: 4 additions & 0 deletions public/history.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
windows Native Peing Connector(NPC) 更新履歴

2022/02/02 Version 1.3.1
1. 回答者がPeingIDを変更したことをNPCが検知した後で変更後のPeingIdをNPCに登録しようとした場合に、既に登録されているというエラーが表示されていた不具合を修正しました。
2. [Twitterのフォローリストから一括登録]が正しく動作しなくなった問題を修正しました。

2021/12/18 Version 1.3.0
1. カーソルのあった質問の位置を次回起動時に引き継ぐ機能を追加しました。
2. ソフト終了時、リスト表示設定が保存されていなかった不具合を修正しました。
Expand Down
4 changes: 2 additions & 2 deletions public/readme.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
windows Native Peing Connector -NPC-

バージョン:  ver.1.3.0
リリース:   2021-12-18
バージョン:  ver.1.3.1
リリース:   2022-02-02
開発・配布元: ACT Laboratory (https://actlab.org/)
主要開発者:  吹雪
  ソフト種別:  オープンソースソフトウェア (GitHubリポジトリ:https://github.com/actlaboratory/NPC/)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ bs4
lxml
https://github.com/actlaboratory/proxyutil/archive/0.2.4.zip
https://github.com/actlaboratory/diff_archiver/archive/v1.0.1.zip
https://github.com/actlaboratory/twitter-authorization/archive/1.0.1.zip
https://github.com/actlaboratory/twitter-authorization/archive/1.0.2.zip
17 changes: 12 additions & 5 deletions service.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,26 @@ def __init__(self):

# 指定のユーザが回答の閲覧対象として登録済みならTrue
def isUserRegistered(self,info):
if type(info) in (int,entity.user.User): #idで照会
if type(info)==entity.user.User:
info=info.id
if type(info)==int: #idで照会
try:
if self.userDao.getWithoutFlag(info,constants.FLG_USER_NOT_REGISTERED|constants.FLG_USER_NOT_REGISTERED) != []:
if self.userDao.getWithoutFlag(info,constants.FLG_USER_NOT_REGISTERED|constants.FLG_USER_DISABLE) != []:
return True
return False
except Exception as e:
self.log.error(e)
raise e
if type(info)==entity.user.User: #userEntityで照会。idとaccountの両者一致を確認
try:
ret = self.userDao.getWithoutFlag(info.id,constants.FLG_USER_NOT_REGISTERED|constants.FLG_USER_DISABLE)
if ret == [] or self._createUserObj(ret).account!=info.account:
return False
return True
except Exception as e:
self.log.error(e)
raise e
elif type(info)==str: #accountで照会
try:
if self.userDao.getFromUserAccountWithoutFlag(info,constants.FLG_USER_NOT_REGISTERED|constants.FLG_USER_NOT_REGISTERED) != []:
if self.userDao.getFromUserAccountWithoutFlag(info,constants.FLG_USER_NOT_REGISTERED|constants.FLG_USER_DISABLE) != []:
return True
return False
except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version": "1.3.0", "release_date": "2021-12-18"}
{"version": "1.3.1", "release_date": "2022-02-02"}
17 changes: 8 additions & 9 deletions views/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#main view
#Copyright (C) 2019 Yukio Nozawa <[email protected]>
#Copyright (C) 2019-2021 yamahubuki <[email protected]>
#Copyright (C) 2019-2022 yamahubuki <[email protected]>


import wx
Expand Down Expand Up @@ -206,23 +206,19 @@ def OnMenuSelect(self,event):
#先頭の@はいらないので対策。入力時はあってもなくても良い
prm = re.sub("@?(.*)","\\1", prm)

self.log.debug("add user: %s" % prm)
if self.parent.service.isUserRegistered(prm)==True:
errorDialog(_("指定されたユーザは既に登録済みです。"),self.parent.hFrame)
self.log.warning("user %s already registered." % prm)
return errorCodes.DUPLICATED
user = self.parent.service.getUserInfo(prm)
if user in (errorCodes.PEING_ERROR,errorCodes.NOT_FOUND):
self.showError(user)
return user
if yesNoDialog(_("ユーザ追加"),_("以下のユーザを追加しますか?\n\nID:%(id)d\n%(name)s(%(account)s)") % {"id":user.id,"name":user.name,"account":user.account},self.parent.hFrame)==wx.ID_NO:
self.log.debug("add user:canceled by user")
return
if self.parent.service.addUser(user)==errorCodes.OK:
ret = self.parent.service.addUser(user)
if ret==errorCodes.OK:
dialog(_("登録完了"),_("ユーザの登録に成功しました。今回登録したユーザの回答を表示するには、ビューを再読み込みしてください。"),self.parent.hFrame)
self.log.info("user %s added!" % prm)
else:
errorDialog(_("ユーザの登録に失敗しました。"),self.parent.hFrame)
self.showError(ret)
self.log.error("add user:failed.")

if selected==menuItemsStore.getRef("FILE_POST_QUESTION"):
Expand Down Expand Up @@ -632,6 +628,8 @@ def showError(self,code,parent=None):
errorDialog(_("不明なエラーの為、ログインに失敗しました。サイトの仕様変更や、お使いのインターネット接続の障害が考えられます。まずは、ブラウザから同じIDでログインできるか確認してください。\nブラウザから正常にログインできる場合には、サイトの仕様変更が考えられますので、このメッセージと利用したIDの種類を添えて開発者までお問い合わせください。"),parent)
elif code==errorCodes.LOGIN_RECAPTCHA_NEEDED:
errorDialog(_("ログインに失敗しました。ログインに際してRECAPTCHA(ロボットでないことの確認)が要求されています。同じIDでブラウザからログインした後、再度お試しください。"),parent)
elif code == errorCodes.DUPLICATED:
errorDialog(_("指定されたユーザは既に登録済みです。"))
elif code != errorCodes.OK:
errorDialog(_("不明なエラー%(code)dが発生しました。大変お手数ですが、本ソフトの実行ファイルのあるディレクトリに生成された%(log)sを添付し、作者までご連絡ください。") %{"code":code,"log":constants.LOG_FILE_NAME},parent)
return
Expand Down Expand Up @@ -681,7 +679,8 @@ def setKeymap(self, identifier,ttl, keymap=None,filter=None):
newMap[identifier.upper()][menuData[name]]=key
else:
newMap[identifier.upper()][menuData[name]]=""
newMap.write()
if newMap.write() != errorCodes.OK:
errorDialog(_("設定の保存に失敗しました。下記のファイルへのアクセスが可能であることを確認してください。") + "\n" + self.config.getAbsFileName())
return True

# ログイン状態を確認し、必要ならログインする
Expand Down

0 comments on commit 9a6c98b

Please sign in to comment.