def array_operation(array_a, array_b, calc): a = np.asarray(Common.from_json(array_a)) b = np.asarray(Common.from_json(array_b)) if calc == "add": return str(a + b) elif calc == "sub": return str(a - b) elif calc == "mul": return str(a * b) elif calc == "div": return str(a / b) else: return str(a.dot(b))
def insertToApps(path) : title = fs.getFileName(path) platform = "linux" if Common.is_windows() : platform = "windows" sql = f"INSERT INTO Apps VALUES(NULL, '{title}', '{path}', '', '{platform}', '', '', CURRENT_DATE())" mysql.execute(sql) return
def isExecutable(path) : ret = False if Common.is_windows() : ret = path.endswith(".exe") or path.endswith(".bat") or or path.endswith(".ps1") or or path.endswith(".vbs") else : stinfo = os.stat(path) ret = stinfo.st_mode & S_IXUSR return ret
def numpy_inverse(): if request.method == "POST": coef = request.form["coefficients"] coefficients = Common.from_json(coef) return render_template("numpy_array_inverse.html", result=numpy_module.array_inverse(coefficients), coef=coef) else: return render_template("numpy_array_inverse.html", result="", coef="")
def main(): print("** Videos テーブル用ビデオファイル一覧を作成または挿入する。**") # path 取得 if Common.count_args() == 0: Common.stop(1, "使用方法: python3 InsVideos.py path insert") path = Common.args(0) # print/insert オプション取得 insoption = False if Common.count_args() == 2: insoption = True # 確認 if not insoption: print(f"Path = {path}, Videos テーブルに挿入 = {insoption}") a = Common.readline("Confirm (Y/N) > ") if Text.tolower(a) != 'y': Common.stop(2, "実行を中止しました。") else: pass # ビデオファイル一覧を取得する。 vfiles = getVideoFiles(path) # INSERT 文を作成する。 sql = "INSERT INTO Videos VALUES" for p in vfiles: p = p.replace("'", "''") fileName = FileSystem.getFileName(p) title = Text.left(fileName, len(fileName) - 4) sql += f"(NULL, '0', '{title}', '{p}', '', '', '', '', 0, 0, 0, 0, 0),\n" print(p) sql = Text.left(sql, len(sql) - 2) + ";" if not insoption: print(sql) if insoption: # INSERT 文を実行する。 try: mysql = MySQL.MySQL(UID, PWD, UID) mysql.execute(sql) # 終了メッセージ if not insoption: print("正常に終了しました。") except Error as e: Common.stop("MySQL のエラーにより終了。接続条件やSQL をチェックしてください。" + e.message) return
def doChangeCreator(): sql = Text.format( "SELECT id, creator, path FROM Pictures WHERE id BETWEEN {0} AND {1}", id_start, id_end) Common.esc_print("cyan", sql) UPDATE = "UPDATE Pictures SET creator='{0}' WHERE id={1}" client = mysql.MySQL() rows = client.query(sql) for row in rows: id = row[0] creator = row[1] path = row[2] if creator == "作者": ppath = Text.split('/', path) lenpath = len(ppath) new_creator = ppath[lenpath - 2] sql = Text.format(UPDATE, new_creator, id) print(sql) client.execute(sql) print(sql) else: pass return
def getFileInfo(f): if Common.is_windows(): mode = "" owner = "" group = "" else: mode = "o{0:o}".format(fs.getAttr(f)) owner = fs.getOwner(f) group = fs.getGroup(f) dir_or_link = "" if fs.isDirectory(f): dir_or_link = "D" if fs.isLink(f): dir_or_link += "L" size = fs.getFileSize(f) last = fs.getLastWrite(f) filename = fs.getFileName(f) item = [mode, dir_or_link, owner, group, size, last, filename] return item
#!/usr/bin/env python3 # 再帰的に中間ファイルを削除する。 from Py365Lib import Common, FileSystem as fs import os # 中間ファイルの拡張子 iexts = (".obj", ".res", ".resw", ".pdb", ".pch", ".rc", ".rc2") # パラメータを得る。 print("== 再帰的に中間ファイルを削除する。==") # 対象のフォルダを得る。 if Common.count_args() == 0 : Common.stop(9, "フォルダを指定してください。") folder = Common.args(0) a = Common.readline(folder + "に対して再帰的に中間ファイルを削除します。よろしいですか? (y/n)") if a != "y" : Common.stop(1, "実行を中止しました。") # 実行する。 files = fs.listFilesRecursively(folder, asstr=True) for f in files: ext = fs.getExtension(f) for e in iexts: if ext == e : print("削除: " + f) os.remove(f) else : pass print("終了。")
#!/usr/bin/python3 # 西暦を元号に変換する。 from Py365Lib import Common if Common.count_args() == 0: Common.stop(9, "Enter year. (yyyy)", Common.ESC_FG_YELLOW) y = int(Common.args()[0]) if y >= 1926 and y < 1989: g = "s" x = y - 1926 + 1 else: g = "h" x = y - 1989 + 1 print("{0}{1}".format(g, x))
#!/usr/bin/python3 from Py365Lib import Common, Text # 元号を西暦に変換する。 if Common.count_args() == 0: Common.stop( 9, "Enter Japanese Gengo year. like s20, h10 where characters must be 3.", Common.ESC_FG_YELLOW) g = Common.args()[0] if Text.tolower(g[0]) == 's': y0 = 1926 elif Text.tolower(g[0]) == 'h': y0 = 1989 else: y0 = 1912 gengo = Text.Text(g) if gengo.length == 3: y = int(gengo.right(2)) x = y + y0 - 1 print(x) else: Common.stop(1, "Error: Inpur length must be 3.")
def resizeImage(filePath, size): cmd = ["mogrify", "-resize", size, filePath] Common.exec(cmd) return
count += 1 # 1件もない場合はサブディレクトリを見てみる。 if count == 0 : for dir1 in dirs : dirs1 = fs.listDirectories(dir1) for dp in dirs1 : nd = rename(dp) dp = "'" + dp + "'" nd = "'" + nd + "'" if dp != nd : lines += f"mv -v {dp} {nd}\n" count += 1 return lines # 対象のディレクトリを得る。 if Common.count_args() < 2 : Common.stop(9, "対象のディレクトリとスクリプトファイルの保存先(パス)を指定してください。") # 対象のディレクトリ dir0 = Common.args()[0] if not fs.isDirectory(dir0) : Common.stop(9, f"{dir0} はディレクトリとして存在しません。") # スクリプトファイルのパス savePath = Common.args()[1] # ディレクトリの名前変更コマンドを作成する。 lines = renameDirs(dir0) # スクリプトを作成する。
new_creator = ppath[lenpath - 2] sql = Text.format(UPDATE, new_creator, id) print(sql) client.execute(sql) print(sql) else: pass return # # メイン # ID の範囲を決める。 id_start = 1 id_end = 1000000 id_range = Common.readline("id の範囲 (nnnn-nnnn) を入力してください。(省略時はすべて)") if id_range == "": Common.esc_print("yellow", "すべての id に対して実行します。(y/n)") a = Common.readline(">") if y != "y": Common.stop(9, "実行を中止しました。") else: nn = Text.split('-', id_range) if len(nn) == 2: id_start = int(nn[0]) id_end = int(nn[1]) else: Common.stop(9, "範囲が正しくありません。実行を中止しました。") # Pictures テーブルからクエリーを行って対象のデータを得る。 doChangeCreator() print("完了")
#!/usr/bin/env python3 # サブディレクトリ内にあるファイルを自ディレクトリに名前を変えてコピーする。 from Py365Lib import Common, FileSystem as fs, Text # START # パラメータ確認 if Common.count_args() < 1: Common.stop("Usage : copy_subdir_files.py directory") mydir = Common.args(0) # サブディレクトリ一覧を得る。 dirs = fs.listDirectories(mydir, True) # サブディレクトリごとに繰り返す。 for d in dirs: print(d) files = fs.listFiles(d, "*", True) parts = Text.split("/", d) h = parts[len(parts) - 1] for f in files: f1 = Text.replace("/", "\\", mydir + "/" + h + "/" + fs.getFileName(f)) f2 = Text.replace("/", "\\", mydir + "/" + h + fs.getFileName(f)) print(f"copy \"{f1}\" \"{f2}\"") # 終わり print("Done.")
#!/usr/bin/env python3 # 画像ファイルのサムネールを作成し、BINDATA テーブルに挿入する。 # さらに、そのサムネールを Pictures または Videos テーブル、Album テーブルに、 Music テーブル関連付ける。 # (使用法) InsBINDATA3 画像ファイルのパス Picturesテーブルの対象id # (バージョン) 1.1.0 from PIL import Image, ImageFilter from Py365Lib import Common, FileSystem as fs, Text, MySQL import os, math # 定数定義 NEWSIZE = 64 if Common.is_windows(): SAVEDIR = "c:/temp/" # 注意:Windows では変更が必要 else: SAVEDIR = "/home/user/Pictures/Small" # 注意:Windows では変更が必要 INSERT = "INSERT INTO BINDATA(`title`, `original`, `datatype`, `data`, `info`, `size`) VALUES('{0}', '{1}', '{2}', {3}, '', {4})" UPDATE = "UPDATE {0} SET bindata = {1} WHERE id = {2}" # バイナリーファイルをヘキサに変換する。 def bin2hex(filePath): buff = "0x" b = fs.readBinary(filePath) buff += b.hex() return buff # サムネール画像を取得する。 def saveThumb(filePath):
#!/usr/bin/env python3 # ディレクトリに ^\[.+\]$ が含まれる場合、\[,\] を取る。 # サブディレクトリが ^\[.+\] .+ なら \[.+\] を取る。 from Py365Lib import Common, FileSystem as fs, Text # START # パラメータ確認 if Common.count_args() < 1: Common.stop("Usage : change_dirnames.py directory") # ディレクトリ一覧を得る。 parent = Common.args(0) dirs = fs.listDirectories(parent, True) # ディレクトリ名 [.+] を見つける。 for d in dirs: if Text.re_contain(r".+\[.+\]$", d): d2 = Text.replace("[", "", d) d2 = Text.replace("]", "", d2) fs.move(d, d2) print(d2) print("**************") # サブディレクトリに ^\[.+\] .+ を見つける。 dirs = fs.listDirectories(parent, True) for d in dirs: dirs2 = fs.listDirectories(d, True) for d2 in dirs2: d3 = Text.re_replace(r"\[.+\]\s+", "", d2) fs.move(d2, d3)
#!/usr/bin/env python3 # tail filePath [lines] from Py365Lib import Common, FileSystem as fs from collections import deque if Common.count_args() < 1: Common.stop(9, "Usage: tail filePath [lines] [encoding]") filePath = Common.args(0) if Common.count_args() > 1: n = int(Common.args(1)) else: n = 20 if Common.count_args() > 2: code = Common.args(2) else: code = "utf-8" fifo = deque(maxlen=n) with open(filePath, mode="r", encoding=code) as f: line = f.readline() while line: fifo.append(line) line = f.readline() while True: if len(fifo) > 0: l = fifo.popleft() print(l, end="")
insertData(dir, creator) else : for subdir in subdirs : insertData(subdir, creator) return # データをMySQLに挿入する。 def insertData(dir, creator) : global mark global cmd parts = Text.split('/', dir) title = parts[len(parts) - 1] cmd = f"INSERT INTO Pictures(TITLE, CREATOR, `PATH`, MARK) VALUES('{title}', '{creator}', '{dir}', '{mark}');" print(cmd) return ## プログラム開始 if Common.count_args() == 0 : Common.stop(1, "親ディレクトリを指定してください。", Common.ESC_FG_YELLOW) cmd = "" mark = 'NONE' parentDir = Common.args()[0] if Common.count_args() > 1 : mark = Common.args()[1] insertFolders(parentDir)
def run_command(): c = request.args.get("command") cmds = Text.re_split("\s+", c) return Common.shell(cmds)
#!/usr/bin/python3 # 新しいサムネール画像で BINDATA テーブルを更新する。 from Py365Lib import Common, FileSystem as fs, Text, MySQL import os, math # 定数定義 if Common.is_windows(): SAVEDIR = "c:/temp/" # 注意:変更が必要 else: SAVEDIR = "/home/user/Pictures/Small" # 注意:変更が必要 UPDATE = "UPDATE BINDATA SET data = {0} WHERE id = {1}" # バイナリーファイルをヘキサに変換する。 def bin2hex(filePath): buff = "0x" b = fs.readBinary(filePath) buff += b.hex() return buff # バイナリーファイル filePath の中身でテーブル BINDATA の id の画像データを更新する。 def updateBinaries(filePath, id): filePath = filePath.replace("\\", "/") hexa = bin2hex(filePath) sql = Text.format(UPDATE, hexa, id) mysql_client.execute(sql) return
def api_numpy_function(): kind = request.args.get("kind") xdata = Common.from_json("[" + request.args.get("xdata") + "]") result = numpy_module.numpy_function(kind, xdata) return jsonify(result)
return (nw, nh) # ************************************************* # この値が縮小画像のデフォルトサイズになる。 SIZE = 1600 #SIZE = 1920 #SIZE = 2560 # 縮小画像ファイルのデフォルト保存先 SAVEPATH = 'C:/Temp/small/' # True なら JPEG で保存 JPEG = True # ************************************************* # ここから開始 if Common.count_args() == 0: print("画像縮小専用 Usage: python smalls.py folder size save_path") folder = Common.readline( "画像ファイルの存在するフォルダパスを入力します。(Enter のみで中止。ファイルサイズと保存先はデフォルト値)> ") if folder == "": Common.stop("処理を中止しました。") else: folder = Common.args(0) if Common.count_args() >= 2: SIZE = int(Common.args(1)) if Common.count_args() >= 3: SAVEPATH = Common.args(2) # 指定されたフォルダ内の画像ファイル一覧を得る。 files = fs.listFiles(folder)
# (注意) ファイル一覧は UTF-8、json ファイルは SJIS で作成する。 # json ファイルの例 ''' { "album":165 "media":"HD-LLU3", "series":"アニソン", "mark":"アニメ", "info":"" } ''' from Py365Lib import Common, FileSystem as fs, MySQL # START # パラメータ確認 if Common.count_args() < 1 : Common.stop("Usage : Ins_VideosSQL.py filelist [json]") filelist = Common.args(0) album = 0 media = "media" series = "series" mark = "mark" info = "info" if Common.count_args() >= 2 : json = fs.readJson(Common.args(1)) album = json["album"] media = json["media"] series = json["series"] mark = json["mark"] info = json["info"] else :
#!/usr/bin/env python3 # ディレクトリの名前が [.+] で始まっていたら、その文字列を削除した名前にする。 from Py365Lib import Common, FileSystem as fs, Text # START # パラメータ確認 if Common.count_args() < 1 : Common.stop("Usage : remove_paren.py directory") parent = Common.args(0) print("cd " + parent) dirs = fs.listDirectories(parent, True) for d in dirs : parts = Text.split("/", d) oldname = parts[len(parts)-1] if Text.re_contain(r"^\[.+\].+", oldname) : d2 = Text.re_replace(r"\[.+\]\s", "", d) d2 = Text.trim(d2) parts = Text.split("/", d2) newname = parts[len(parts)-1] print("ren \"{0}\" \"{1}\"".format(oldname, newname)) print("echo Done.")
#!/usr/bin/python3 # 元号の生年から年齢を求める。 from Py365Lib import Common if Common.count_args() == 0: Common.stop(9, "Enter birth_year(Showa)", Common.ESC_FG_YELLOW) showa = int(Common.args()[0]) AGE0 = 92 age = AGE0 - showa + 1 print("s{0}".format(age))
#!/usr/bin/python3 # 指定された id の Pictures テーブルのデータの BINDATA フィールドの値を BINDATA テーブルの録された項目の id で置き換える。 from Py365Lib import MySQL, Common if Common.count_args() == 0: print("Usage: update_pictures_bindata.py Pictures_id") Common.stop(1) id = Common.args(0) mysql = MySQL.MySQL() bindata = mysql.getValue("SELECT max(id) FROM BINDATA") sql = f"UPDATE Pictures SET bindata={bindata} WHERE id={id}" mysql.execute(sql) print("Done.")
parts = path.split("/") n = len(parts) if n > 2 : title = parts[n-1] creator = parts[n-2] else : title = "title" creator = "creator" sql = f"INSERT INTO Pictures(TITLE, CREATOR, PATH, MARK, INFO, FAV, COUNT, BINDATA) VALUES('{title}', '{creator}', '{path}', '', '', 0, 0, 0)" print(sql) mysql.execute(sql) return # START # パラメータ確認 if Common.count_args() < 1 : Common.stop("Usage : InsPictures.py directory") dir_parent = Common.args(0) # MySQL に接続 mysql = MySQL.MySQL() # 画像ファイルを含むサブディレクトリ一覧を得る。 dirlist = fs.listDirectories(dir_parent, True) for dir in dirlist : dirlist2 = fs.listDirectories(dir, True) if len(dirlist2) == 0 : InsertData(dir) else : for path in dirlist2 : InsertData(path) print("Done.")
methods: { submit_click: () => { $.getJSON(URL, {"value":app.value}, (data) => { app.message = data; }); } } }); </script> <p> </p> <p> </p> </body> </html> ''' if Common.count_args() == 0: filePath = Common.readline('HTMLファイルのパス名を入力してください。') else: filePath = Common.args(0) if Common.count_args() < 2: print("1: HTML5 のシンプルなページ") print("2: HTML5 のシンプルなページ + jQuery + Highlight.js") print("3: Bootstrap4 のページ") print("4: Bootstrap4 のページ + Highlight.js ") print("5: Vue.js のページ") pagen = int(Common.readline("番号入力 > ")) else: pagen = int(Common.args(1)) if pagen < 1 or pagen > 4:
#!/usr/bin/env python3 # YJFX_Asset テーブルにデータを挿入する。 from Py365Lib import Common, MySQL # パラメータ確認 if Common.count_args() < 3: Common.stop(9, "Usage: InsAsset.py date asset loss", Common.ESC_FG_YELLOW) date = Common.args(0) asset = Common.args(1) loss = Common.args(2) sql = f"INSERT INTO YJFX_Asset VALUES(null, '{date}', {asset}, {loss}, '')" mysql = MySQL.MySQL() mysql.execute(sql) sql = "SELECT * FROM VW_YJFX_Asset" result = mysql.query(sql) for row in result: print(row) print("Done.")
#!/usr/bin/env python3 # ファイル一覧を PictureAlbum テーブルへインポートでする。 from Py365Lib import Common, FileSystem as fs, MySQL # START # パラメータ確認 if Common.count_args() < 2: Common.stop("Usage : ins_flist.py filelist album_no") filelist = Common.args(0) album_no = Common.args(1) # MySQL に接続 mysql = MySQL.MySQL() # ファイルリストを読む。 lines = fs.readLines(filelist) for path in lines: path = path.strip().replace("'", "''") parts = path.split("/") n = len(parts) if n > 3: title = parts[n - 2] creator = parts[n - 3] else: title = "title" creator = "creator" sql = f"INSERT INTO PictureAlbum VALUES(NULL,{album_no},'{title}','{path}','{creator}','',0,0)" print(sql) mysql.execute(sql) print("Done.")