Beispiel #1
0
def updateDate(mysql, id) :
  # id から path を得る。
  path = mysql.getValue(f"SELECT path FROM Pictures WHERE id={id}")
  if path == None :
    print(f"エラー: id = {id} のデータがありません。")
    return
  print("path = ", path)

  # ディレクトリ内のファイルを検索して、一番新しいファイルの日付を得る。
  #files = fs.listFiles(path, "*", True)
  files = os.listdir(path.encode('utf-8'))
  if len(files) == 0 :
    print("エラー: ファイルが見つかりません。")
    return
  time0 = fs.getLastWrite(path + "/" + files[0].decode('utf-8'))
  pathlast = files[0].decode('utf-8')
  for f in files :
    time1 = fs.getLastWrite(path + "/" + f.decode('utf-8'))
    if time1 < time0 :
      time0 = time1
  date0 = time0[0:10]
  print(date0)

  # Pictures テーブルの当該レコードの日付(date)を更新する。
  sql = f"UPDATE Pictures SET `date`='{date0}' WHERE id={id}"
  print(sql)
  mysql.execute(sql)
  return
Beispiel #2
0
def show_img_folder() :
  files = fs.listFiles(IMG_FOLDER)
  piclist = "<ul>"
  for f in files :
    fname = fs.getFileName(f.decode())
    piclist += "<li><img src=\"{0}\" /> {1}</li>".format(f.decode(), fname)
  piclist += "</ul>"
  return render_template("show_img_folder.html", piclist=piclist)
Beispiel #3
0
def showSource(filePath, style="default"):
    text = fs.readAllText(filePath)
    source = WebPage.WebPage.escape(text)
    title = fs.getFileName(filePath)
    return render_template("showSource.html",
                           source=source,
                           title=title,
                           style=style)
Beispiel #4
0
def apply(fileName, interpreter):
    lines = fs.readLines(fileName)
    if lines[0].startswith('#!'):
        lines[0] = "#!" + interpreter + "\n"
        fs.writeLines(fileName, lines)
    else:
        print("Skiped: 行の先頭にインタプリタ指定が見当たりません。" + fileName)
    return
Beispiel #5
0
def index():
    home_folder = '"' + fs.getHomeDirectory() + '"'
    orderby = request.args.get("orderby")
    hiddenfile = request.args.get("hiddenfile")
    textview = request.args.get("textview")
    favarray = fs.readAllText("fav_folders.csv")
    return render_template('index.html',
                           version='1.0',
                           home=home_folder,
                           fav_folder=favarray)
Beispiel #6
0
def insertBinaries(filePath):
    ext = fs.getExtension(filePath)
    size = fs.getFileSize(filePath)
    name = fs.getFileName(filePath)
    filePath = filePath.replace("\\", "/")
    hexa = bin2hex(filePath)
    sn = mysql_client.getValue("SELECT max(sn) FROM BINDATA") + 1
    sql = Text.format(INSERT, name, filePath, ext, hexa, size, sn)
    mysql_client.execute(sql)
    lastId = mysql_client.getValue("SELECT max(id) FROM BINDATA")
    return lastId
Beispiel #7
0
def insertBinaries(filePath):
    INSERT = "INSERT INTO BINDATA(`title`, `original`, `datatype`, `data`, `info`, `size`) VALUES('{0}', '{1}', '{2}', {3}, '', {4})"
    ext = fs.getExtension(filePath)
    size = fs.getFileSize(filePath)
    fileName = fs.getFileName(filePath)
    filePath = filePath.replace("\\", "/")
    filePath = filePath.replace("'", "''")
    hexa = bin2hex(filePath)
    sql = Text.format(INSERT, fileName, filePath, ext, hexa, size)
    client = MySQL.MySQL()
    client.execute(sql)
    return
Beispiel #8
0
def api_image_resize(folder, size) :
  files = fs.listFiles(folder, asstr=True)
  count = 0
  try :
    for f in files :
      ext = Text.tolower(fs.getExtension(f))
      if ext in [".jpg", ".jpeg", ".png", ".gif"] :
        util.resizeImage(f, size)
        count += 1
  except Exception as e:
    print(str(e))
  return count
Beispiel #9
0
def find():
    folder = request.args.get("folder")
    findstr = request.args.get("findstr")
    files = fs.listDirectories(folder, asstr=True) + fs.listFiles(folder,
                                                                  asstr=True)
    items = []
    for f in files:
        if Text.contain(findstr, f):
            items.append(getFileInfo(f))
        else:
            pass
    return jsonify(items)
Beispiel #10
0
def api_bindata_insert(folder) :
  files = fs.listFiles(folder, asstr=True)
  count = 0
  try :
    for f in files :
      ext = Text.tolower(fs.getExtension(f))
      if ext in [".jpg", ".jpeg", ".png", ".gif"] :
        util.insertBinaries(f)
        count += 1
  except Exception as e :
    print(str(e))
  return count
Beispiel #11
0
def insertBinaries(filePath, origin):
    ext = fs.getExtension(filePath)
    size = fs.getFileSize(filePath)
    parts = origin.split("/")
    n = len(parts)
    name = parts[n - 3] + " " + parts[n - 2]
    filePath = filePath.replace("\\", "/")
    filePath = filePath.replace("'", "''")
    hexa = bin2hex(filePath)
    sql = Text.format(INSERT, name, origin, ext, hexa, size)
    mysql_client.execute(sql)
    lastId = mysql_client.getValue("SELECT max(id) FROM BINDATA")
    return lastId
Beispiel #12
0
def renameAll(args):
    dir = args[0]
    wild = args[1]
    fix = args[2]
    cols = args[3]
    i = 1
    files = fs.listFiles(dir, wild)
    sortedFiles = sorted(files)
    for fold in sortedFiles:
        ext = fs.getExtension(fold)
        fmt = "{0:0" + cols + "d}"
        fnew = dir + "/" + fix + Text.format(fmt, i) + ext
        cmd = f"mv -v {fold} {fnew}"
        print(cmd)
        i += 1
Beispiel #13
0
def delete_badchars(folder):
    # 画像ファイル一覧を得る。
    print(folder)
    files = fs.listFiles(folder, asstr=True)
    # 画像ファイルをリネーム
    for fpath in files:
        #fpath = Common.from_bytes(f)
        ext = fs.getExtension(fpath).lower()
        if ext == ".jpg" or ext == ".png" or ext == ".gif":
            fpath_new = fpath.replace("#", "").replace("+", "")
            if fpath != fpath_new:
                print("mv -v '" + fpath + "' '" + fpath_new + "'")
        else:
            print("Non image passed: " + fpath)
    return
Beispiel #14
0
def convert_image(path, mode):
    im = Image.open(path)
    newim = im.convert(mode)
    time = DateTime.DateTime()
    fileName = TMP + str(time.timestamp) + "_" + fs.getFileName(path)
    newim.save(fileName)
    return fileName
Beispiel #15
0
def pillow_convert():
    if request.method == "POST":
        path = request.form["path"]
        mode = request.form["mode"]
        if mode == "LA" and fs.getExtension(path) == ".jpg":
            return "Error: JPEG は LA を使用できません。"
        return render_template("pillow_convert.html",
                               result=pillow_module.convert_image(path, mode),
                               path=path,
                               mode=mode)
    else:
        defaulticon = fs.getCurrentDirectory() + PYTHONICON
        return render_template("pillow_convert.html",
                               result=defaulticon,
                               path=defaulticon,
                               mode="")
Beispiel #16
0
def insertFolders(parentDir) :
  dirs = fs.listDirectories(parentDir)
  for dir in dirs :
    # 作者名
    parts = Text.split("/", dir)
    creator = parts[len(parts) - 1]
    # 作品名s
    subdirs = fs.listDirectories(dir)
    if len(subdirs) == 0 :
      p = Text.split(' ', creator)
      creator = p[0]
      insertData(dir, creator)
    else :
      for subdir in subdirs :
        insertData(subdir, creator)
  return
Beispiel #17
0
def show_text(filePath, title=""):
    if title == "":
        title = "show_text"
    buf = """<!doctype html>
<html>
<head>
 <meta charset="utf-8" />
 <title>"""
    buf += title
    buf += """</title>
</head>
<body>
<h1 style='text-align:center;'>"""
    buf += title
    buf += """</h1>
<br />
<pre style='margin-left:5%;'>
  """
    buf += escape(fs.readAllText(filePath))
    buf += """</pre>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>
  """
    return buf
Beispiel #18
0
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
Beispiel #19
0
def rotate_image(path, angle=0):
    if angle < -180 and angle > 180:
        return "Error: angle must be -180 <= p <= 180."
    im = Image.open(path)
    newim = im.rotate(angle)
    time = DateTime.DateTime()
    fileName = TMP + str(time.timestamp) + "_" + fs.getFileName(path)
    newim.save(fileName)
    return fileName
Beispiel #20
0
def getVideoFiles(path):
    files = glob.glob(path + "/**/*", recursive=True)
    vfiles = list()
    for f in files:
        ext = FileSystem.getExtension(f)
        if ext in VIDEOEXT:
            fn = str(f).replace("\\", "/")
            vfiles.append(str(fn))
    return vfiles
Beispiel #21
0
def crop_image(path, left_top, right_bottom):
    p = left_top.split(",")
    q = right_bottom.split(",")
    xy = (int(p[0]), int(p[1]), int(q[0]), int(q[1]))
    im = Image.open(path)
    newim = im.crop(xy)
    time = DateTime.DateTime()
    fileName = TMP + str(time.timestamp) + "_" + fs.getFileName(path)
    newim.save(fileName)
    return fileName
Beispiel #22
0
def pillow_info():
    if request.method == "POST":
        path = request.form["path"]
        return render_template("get_image_info.html",
                               result=pillow_module.get_image_info(path),
                               path=path)
    else:
        defaulticon = fs.getCurrentDirectory() + PYTHONICON
        return render_template("get_image_info.html",
                               result="",
                               path=defaulticon)
Beispiel #23
0
def mirror_image(path, mode):
    im = Image.open(path)
    if mode == "mirror":
        newim = ImageOps.mirror(im)
    elif mode == "flip":
        newim = ImageOps.flip(im)
    else:
        return "Fatal error"
    time = DateTime.DateTime()
    fileName = TMP + str(time.timestamp) + "_" + fs.getFileName(path)
    newim.save(fileName)
    return fileName
Beispiel #24
0
def list_files():
    folder = request.args.get("folder")
    orderby = request.args.get("orderby")
    hiddenfile = request.args.get("hiddenfile")
    # ディレクトリ一覧
    items1 = []
    folders = fs.listDirectories(folder, asstr=True)
    for f in folders:
        fn = fs.getFileName(f)
        if hiddenfile == 1:  # 隠しファイルを表示する。
            items1.append(getFileInfo(f))  # すべてのフォルダ
        else:
            if not fn.startswith("."):  # 隠しファイル(フォルダ)は表示しない。
                items1.append(getFileInfo(f))
        if orderby == "size" or orderby == "rsize":
            items1 = sortby("name", items1)
        else:
            if len(items1) > 0:
                items1 = sortby(orderby, items1)
    # ファイル一覧
    files = fs.listFiles(folder, asstr=True)
    items2 = []
    for f in files:
        fn = fs.getFileName(f)
        if hiddenfile == 1:  # 隠しファイルを表示する。
            items2.append(getFileInfo(f))  # すべてのファイル
        else:
            if not fn.startswith("."):  # 隠しファイルは表示しない。
                items2.append(getFileInfo(f))
        if len(items2) > 0:
            items2 = sortby(orderby, items2)
    # ディレクトリ一覧とファイル一覧を1つのリストにする。
    items = []
    for i in items1:
        items.append(i)
    for i in items2:
        items.append(i)
    return jsonify(items)
Beispiel #25
0
def renameDirs(dir0) :
    count = 0
    lines = "#!/bin/bash\n"
    dirs = fs.listDirectories(dir0)
    for dp in dirs :
        nd = rename(dp)
        dp = "'" + dp + "'"
        nd = "'" + nd + "'"
        if dp != nd :
            lines += f"mv -v {dp} {nd}\n"
            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
Beispiel #26
0
def pillow_mirror():
    if request.method == "POST":
        path = request.form["path"]
        mode = request.form["mode"]
        return render_template("pillow_mirror.html",
                               result=pillow_module.mirror_image(path, mode),
                               path=path,
                               mode=mode)
    else:
        defaulticon = fs.getCurrentDirectory() + PYTHONICON
        return render_template("pillow_mirror.html",
                               result=defaulticon,
                               path=defaulticon,
                               mode="")
Beispiel #27
0
def resize_image(path, percent=50):
    if percent <= 0 and percent > 100:
        return "Error: percent must be 0 < p <= 100."
    im = Image.open(path)
    width = im.size[0]
    height = im.size[1]
    rate = percent / 100.0
    new_width = math.floor(width * rate)
    new_height = math.floor(height * rate)
    newim = im.resize((new_width, new_height))
    time = DateTime.DateTime()
    fileName = TMP + str(time.timestamp) + "_" + fs.getFileName(path)
    newim.save(fileName)
    return fileName
Beispiel #28
0
def pillow_rotate():
    if request.method == "POST":
        path = request.form["path"]
        angle = int(request.form["angle"])
        return render_template("pillow_rotate.html",
                               result=pillow_module.rotate_image(path, angle),
                               path=path,
                               angle=angle)
    else:
        defaulticon = fs.getCurrentDirectory() + PYTHONICON
        return render_template("pillow_rotate.html",
                               result=defaulticon,
                               path=defaulticon,
                               angle="")
Beispiel #29
0
def saveThumb(filePath):
    im = Image.open(filePath)
    # print(im.format, im.size, im.mode)
    if im.size[0] > im.size[1]:
        w = NEWSIZE
        h = math.floor(NEWSIZE * (im.size[1] / im.size[0]))
    else:
        w = math.floor(NEWSIZE * (im.size[0] / im.size[1]))
        h = NEWSIZE
    newsize = (w, h)
    newim = im.resize(newsize, Image.LANCZOS)
    newPath = SAVEDIR + fs.getFileName(filePath)
    newim.save(newPath)
    return newPath
Beispiel #30
0
def pillow_resize():
    if request.method == "POST":
        path = request.form["path"]
        percent = int(request.form["percent"])
        return render_template("pillow_resize.html",
                               result=pillow_module.resize_image(
                                   path, percent),
                               path=path,
                               percent=percent)
    else:
        defaulticon = fs.getCurrentDirectory() + PYTHONICON
        return render_template("pillow_resize.html",
                               result=defaulticon,
                               path=defaulticon,
                               percent="")