-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
177 additions
and
43 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
#!/usr/bin/python3 | ||
# -*- coding: utf-8 -*- | ||
# Author: i2cy([email protected]) | ||
# Project: I2cylib | ||
# Filename: i2tec_home | ||
# Created on: 2022/9/19 | ||
|
||
import os | ||
from pathlib import Path | ||
from shutil import rmtree | ||
|
||
|
||
class DirTree(os.PathLike): | ||
|
||
def __init__(self, *root: (os.PathLike, str)): | ||
self.__root = Path(*root) | ||
self.name = self.__root.name | ||
|
||
def __str__(self): | ||
return self.__root.as_posix() | ||
|
||
def __fspath__(self): | ||
return self.__root.__fspath__() | ||
|
||
def __iter__(self): | ||
return self.__root.iterdir() | ||
|
||
def __len__(self): | ||
cnt = 0 | ||
for i in self.__root.iterdir(): | ||
cnt += 1 | ||
return cnt | ||
|
||
def exists(self): | ||
return self.__root.exists() | ||
|
||
def fixPath(self, is_file=True, touch=False): | ||
if is_file: | ||
self.__root.parent.mkdir(parents=True, exist_ok=True) | ||
if touch: | ||
self.__root.touch(exist_ok=True) | ||
else: | ||
self.__root.mkdir(parents=True, exist_ok=True) | ||
|
||
def isFixed(self): | ||
return self.__root.parent.exists() | ||
|
||
def touch(self): | ||
if self.exists(): | ||
return | ||
|
||
self.fixPath(is_file=True, touch=True) | ||
|
||
def isFile(self): | ||
return self.__root.is_file() | ||
|
||
def isDir(self): | ||
return self.__root.is_dir() | ||
|
||
def remove(self): | ||
if self.isDir(): | ||
rmtree(self) | ||
else: | ||
os.remove(self) | ||
|
||
def asPosix(self): | ||
return str(self) | ||
|
||
def parent(self): | ||
return DirTree(self.__root.parent) | ||
|
||
def toList(self, dir_only=False, file_only=False): | ||
ret = [] | ||
for ele in self: | ||
if ele.is_dir(): | ||
if not file_only: | ||
ret.append(DirTree(ele)) | ||
else: | ||
if not dir_only: | ||
ret.append(DirTree(ele)) | ||
return ret | ||
|
||
def join(self, *path: (os.PathLike, str)): | ||
return DirTree(self, *path) | ||
|
||
|
||
def i2TecHome(): | ||
return DirTree(Path.home(), ".i2tec") | ||
|
||
|
||
if __name__ == '__main__': | ||
import time | ||
|
||
root = i2TecHome() | ||
root.fixPath(False) | ||
print(root) | ||
print("root got {} file(dir)s within".format(len(root))) | ||
print("listing files under it:") | ||
for i, path in enumerate(root.toList(file_only=True)): | ||
print("\t{}. \"{}\"".format(i, path)) | ||
|
||
file_path = root.join("{}.txt".format(int(time.time()))) | ||
print("creating text file ") | ||
with open(file_path, "w") as f: | ||
f.write("test.file.content.{}".format(time.time)) | ||
f.close() | ||
|
||
print("creating dir") | ||
dir_path = root.join("{}".format(int(time.time()))) | ||
dir_path.fixPath(False) | ||
print("making random files") | ||
for i in range(5): | ||
dir_path.join("{}.txt".format(time.time())).touch() | ||
|
||
print("listing everything under root:") | ||
for i, path in enumerate(root.toList()): | ||
print("\t{}. \"{}\"".format(i, path)) | ||
|
||
print("listing everything under test dir:") | ||
for i, path in enumerate(dir_path.toList()): | ||
print("\t{}. \"{}\"".format(i, path)) | ||
|
||
print("removing dir") | ||
dir_path.remove() | ||
|
||
print("removing test file") | ||
file_path.remove() | ||
|
||
print("listing everything under root:") | ||
for i, path in enumerate(root.toList()): | ||
print("\t{}. \"{}\"".format(i, path)) |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,39 @@ | ||
Metadata-Version: 2.1 | ||
Name: i2cylib | ||
Version: 1.11.2 | ||
Version: 1.12.0 | ||
Summary: A Python library contains a lot of useful functions and tools | ||
Home-page: https://github.com/i2cy/i2cylib | ||
Author: I2cy Cloud | ||
Author-email: [email protected] | ||
License: UNKNOWN | ||
Project-URL: Bug Tracker, https://github.com/i2cy/i2cylib/issues | ||
Project-URL: Source Code, https://github.com/i2cy/i2cylib | ||
Project-URL: Documentation, https://github.com/i2cy/I2cylib/wiki/API-Document | ||
Description: # 主要包含 | ||
- `ICCode` i2cy常用的混淆算法 | ||
- `Dynkey` 动态验证密匙生成/验证工具 | ||
- `SQLiteDB` SQLite3数据库面向对象式API | ||
- `ICFat64` 类FAT虚拟文件系统 | ||
- `I2TCP` 高度封装的用户层通讯协议 | ||
- `PID` 异步PID模组 | ||
- `utils` 各种常用的小工具 | ||
|
||
# 安装方法 | ||
`pip install i2cylib` | ||
|
||
# 内嵌命令行工具 | ||
- `icen` 基于ICCode混淆算法的文件加密工具 | ||
- `i2cydbserver` 基于SQLite的数据库服务端 | ||
- `i2scan` 端口扫描、系统推断工具 | ||
|
||
# 环境需求 | ||
`Python3.6+` | ||
|
||
# API文档 | ||
[Project Wiki](https://github.com/i2cy/I2cylib/wiki/API-Document) | ||
Platform: UNKNOWN | ||
Classifier: Programming Language :: Python :: 3 | ||
Classifier: License :: OSI Approved :: MIT License | ||
Classifier: Operating System :: OS Independent | ||
Requires-Python: >=3.6 | ||
Description-Content-Type: text/markdown | ||
License-File: LICENSE | ||
|
||
# 主要包含 | ||
- `ICCode` i2cy常用的混淆算法 | ||
- `Dynkey` 动态验证密匙生成/验证工具 | ||
- `SQLiteDB` SQLite3数据库面向对象式API | ||
- `ICFat64` 类FAT虚拟文件系统 | ||
- `I2TCP` 高度封装的用户层通讯协议 | ||
- `PID` 异步PID模组 | ||
- `utils` 各种常用的小工具 | ||
|
||
# 安装方法 | ||
`pip install i2cylib` | ||
|
||
# 内嵌命令行工具 | ||
- `icen` 基于ICCode混淆算法的文件加密工具 | ||
- `i2cydbserver` 基于SQLite的数据库服务端 | ||
- `i2scan` 端口扫描、系统推断工具 | ||
|
||
# 环境需求 | ||
`Python3.6+` | ||
|
||
# API文档 | ||
[Project Wiki](https://github.com/i2cy/I2cylib/wiki/API-Document) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
|
||
setuptools.setup( | ||
name="i2cylib", # Replace with your own username | ||
version="1.11.2", | ||
version="1.12.0", | ||
author="I2cy Cloud", | ||
author_email="[email protected]", | ||
description="A Python library contains a lot of useful functions and tools", | ||
|