codet 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
codet-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Your Name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,8 @@
1
+ include LICENSE
2
+ include README.md
3
+ include pyproject.toml
4
+ include setup.py
5
+
6
+ recursive-include tests *
7
+ recursive-exclude * __pycache__
8
+ recursive-exclude * *.py[co]
codet-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,76 @@
1
+ Metadata-Version: 2.2
2
+ Name: codet
3
+ Version: 0.1.0
4
+ Summary: 一个跨平台的命令行文件处理工具
5
+ Home-page: https://github.com/yourusername/codet
6
+ Author: Your Name
7
+ Author-email: your.email@example.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.6
10
+ Classifier: Programming Language :: Python :: 3.7
11
+ Classifier: Programming Language :: Python :: 3.8
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
16
+ Requires-Python: >=3.6
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: click>=8.0.0
20
+ Provides-Extra: dev
21
+ Requires-Dist: pytest>=6.0.0; extra == "dev"
22
+ Requires-Dist: black>=21.5b2; extra == "dev"
23
+ Requires-Dist: isort>=5.9.1; extra == "dev"
24
+ Requires-Dist: flake8>=3.9.2; extra == "dev"
25
+ Requires-Dist: twine>=3.4.1; extra == "dev"
26
+ Dynamic: author
27
+ Dynamic: author-email
28
+ Dynamic: classifier
29
+ Dynamic: description
30
+ Dynamic: description-content-type
31
+ Dynamic: home-page
32
+ Dynamic: provides-extra
33
+ Dynamic: requires-dist
34
+ Dynamic: requires-python
35
+ Dynamic: summary
36
+
37
+ # Codet
38
+
39
+ 一个跨平台的命令行文件处理工具。
40
+
41
+ ## 安装
42
+
43
+ ```bash
44
+ pip install codet
45
+ ```
46
+
47
+ ## 使用方法
48
+
49
+ ```bash
50
+ # 显示帮助信息
51
+ codet --help
52
+
53
+ # 使用示例
54
+ codet [命令] [参数]
55
+ ```
56
+
57
+ ## 功能
58
+
59
+ - 文件处理功能
60
+ - 跨平台支持
61
+ - 简单易用的命令行界面
62
+
63
+ ## 开发
64
+
65
+ ```bash
66
+ # 克隆仓库
67
+ git clone https://github.com/yourusername/codet.git
68
+ cd codet
69
+
70
+ # 安装开发依赖
71
+ pip install -e ".[dev]"
72
+ ```
73
+
74
+ ## 许可证
75
+
76
+ MIT
codet-0.1.0/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # Codet
2
+
3
+ 一个跨平台的命令行文件处理工具。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ pip install codet
9
+ ```
10
+
11
+ ## 使用方法
12
+
13
+ ```bash
14
+ # 显示帮助信息
15
+ codet --help
16
+
17
+ # 使用示例
18
+ codet [命令] [参数]
19
+ ```
20
+
21
+ ## 功能
22
+
23
+ - 文件处理功能
24
+ - 跨平台支持
25
+ - 简单易用的命令行界面
26
+
27
+ ## 开发
28
+
29
+ ```bash
30
+ # 克隆仓库
31
+ git clone https://github.com/yourusername/codet.git
32
+ cd codet
33
+
34
+ # 安装开发依赖
35
+ pip install -e ".[dev]"
36
+ ```
37
+
38
+ ## 许可证
39
+
40
+ MIT
@@ -0,0 +1,5 @@
1
+ """
2
+ Codet - 一个跨平台的命令行文件处理工具
3
+ """
4
+
5
+ __version__ = "0.1.0"
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """
5
+ 命令行接口模块
6
+ """
7
+
8
+ import sys
9
+ import click
10
+
11
+ from . import __version__
12
+
13
+
14
+ @click.group()
15
+ @click.version_option(version=__version__)
16
+ def cli():
17
+ """Codet - 一个跨平台的命令行文件处理工具"""
18
+ pass
19
+
20
+
21
+ @cli.command()
22
+ @click.argument('file', type=click.Path(exists=True))
23
+ @click.option('--output', '-o', help='输出文件路径')
24
+ def process(file, output):
25
+ """处理指定文件"""
26
+ click.echo(f"处理文件: {file}")
27
+ if output:
28
+ click.echo(f"输出到: {output}")
29
+ # 这里添加文件处理逻辑
30
+
31
+
32
+ @cli.command()
33
+ @click.argument('directory', type=click.Path(exists=True, file_okay=False, dir_okay=True))
34
+ @click.option('--recursive', '-r', is_flag=True, help='是否递归处理目录')
35
+ def scan(directory, recursive):
36
+ """扫描目录"""
37
+ click.echo(f"扫描目录: {directory}")
38
+ click.echo(f"递归模式: {'开启' if recursive else '关闭'}")
39
+ # 这里添加目录扫描逻辑
40
+
41
+
42
+ def main():
43
+ """CLI主入口函数"""
44
+ try:
45
+ cli()
46
+ except Exception as e:
47
+ click.echo(f"错误: {str(e)}", err=True)
48
+ sys.exit(1)
49
+
50
+
51
+ if __name__ == "__main__":
52
+ main()
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """
5
+ 工具函数模块
6
+ """
7
+
8
+ import os
9
+ import sys
10
+ import platform
11
+
12
+
13
+ def get_system_info():
14
+ """获取系统信息"""
15
+ return {
16
+ "system": platform.system(),
17
+ "release": platform.release(),
18
+ "version": platform.version(),
19
+ "machine": platform.machine(),
20
+ "processor": platform.processor(),
21
+ "python_version": sys.version,
22
+ }
23
+
24
+
25
+ def is_file_binary(file_path):
26
+ """
27
+ 检查文件是否为二进制文件
28
+
29
+ Args:
30
+ file_path (str): 文件路径
31
+
32
+ Returns:
33
+ bool: 如果是二进制文件返回True,否则返回False
34
+ """
35
+ # 读取文件的前4KB内容
36
+ chunk_size = 4096
37
+ try:
38
+ with open(file_path, 'rb') as f:
39
+ chunk = f.read(chunk_size)
40
+
41
+ # 检查是否包含空字节(通常表示二进制文件)
42
+ if b'\x00' in chunk:
43
+ return True
44
+
45
+ # 尝试以UTF-8解码
46
+ try:
47
+ chunk.decode('utf-8')
48
+ return False
49
+ except UnicodeDecodeError:
50
+ return True
51
+ except Exception:
52
+ # 如果出现任何错误,保守地认为它是二进制文件
53
+ return True
54
+
55
+
56
+ def get_file_info(file_path):
57
+ """
58
+ 获取文件信息
59
+
60
+ Args:
61
+ file_path (str): 文件路径
62
+
63
+ Returns:
64
+ dict: 包含文件信息的字典
65
+ """
66
+ stat_info = os.stat(file_path)
67
+ return {
68
+ "path": file_path,
69
+ "size": stat_info.st_size,
70
+ "created": stat_info.st_ctime,
71
+ "modified": stat_info.st_mtime,
72
+ "accessed": stat_info.st_atime,
73
+ "is_binary": is_file_binary(file_path),
74
+ }
75
+
76
+
77
+ def scan_directory(directory, recursive=False):
78
+ """
79
+ 扫描目录
80
+
81
+ Args:
82
+ directory (str): 目录路径
83
+ recursive (bool): 是否递归扫描
84
+
85
+ Returns:
86
+ list: 文件路径列表
87
+ """
88
+ files = []
89
+
90
+ if recursive:
91
+ for root, _, filenames in os.walk(directory):
92
+ for filename in filenames:
93
+ files.append(os.path.join(root, filename))
94
+ else:
95
+ for item in os.listdir(directory):
96
+ item_path = os.path.join(directory, item)
97
+ if os.path.isfile(item_path):
98
+ files.append(item_path)
99
+
100
+ return files
@@ -0,0 +1,76 @@
1
+ Metadata-Version: 2.2
2
+ Name: codet
3
+ Version: 0.1.0
4
+ Summary: 一个跨平台的命令行文件处理工具
5
+ Home-page: https://github.com/yourusername/codet
6
+ Author: Your Name
7
+ Author-email: your.email@example.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.6
10
+ Classifier: Programming Language :: Python :: 3.7
11
+ Classifier: Programming Language :: Python :: 3.8
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
16
+ Requires-Python: >=3.6
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: click>=8.0.0
20
+ Provides-Extra: dev
21
+ Requires-Dist: pytest>=6.0.0; extra == "dev"
22
+ Requires-Dist: black>=21.5b2; extra == "dev"
23
+ Requires-Dist: isort>=5.9.1; extra == "dev"
24
+ Requires-Dist: flake8>=3.9.2; extra == "dev"
25
+ Requires-Dist: twine>=3.4.1; extra == "dev"
26
+ Dynamic: author
27
+ Dynamic: author-email
28
+ Dynamic: classifier
29
+ Dynamic: description
30
+ Dynamic: description-content-type
31
+ Dynamic: home-page
32
+ Dynamic: provides-extra
33
+ Dynamic: requires-dist
34
+ Dynamic: requires-python
35
+ Dynamic: summary
36
+
37
+ # Codet
38
+
39
+ 一个跨平台的命令行文件处理工具。
40
+
41
+ ## 安装
42
+
43
+ ```bash
44
+ pip install codet
45
+ ```
46
+
47
+ ## 使用方法
48
+
49
+ ```bash
50
+ # 显示帮助信息
51
+ codet --help
52
+
53
+ # 使用示例
54
+ codet [命令] [参数]
55
+ ```
56
+
57
+ ## 功能
58
+
59
+ - 文件处理功能
60
+ - 跨平台支持
61
+ - 简单易用的命令行界面
62
+
63
+ ## 开发
64
+
65
+ ```bash
66
+ # 克隆仓库
67
+ git clone https://github.com/yourusername/codet.git
68
+ cd codet
69
+
70
+ # 安装开发依赖
71
+ pip install -e ".[dev]"
72
+ ```
73
+
74
+ ## 许可证
75
+
76
+ MIT
@@ -0,0 +1,16 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ pyproject.toml
5
+ setup.py
6
+ codet/__init__.py
7
+ codet/cli.py
8
+ codet/utils.py
9
+ codet.egg-info/PKG-INFO
10
+ codet.egg-info/SOURCES.txt
11
+ codet.egg-info/dependency_links.txt
12
+ codet.egg-info/entry_points.txt
13
+ codet.egg-info/requires.txt
14
+ codet.egg-info/top_level.txt
15
+ tests/__init__.py
16
+ tests/test_utils.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ codet = codet.cli:main
@@ -0,0 +1,8 @@
1
+ click>=8.0.0
2
+
3
+ [dev]
4
+ pytest>=6.0.0
5
+ black>=21.5b2
6
+ isort>=5.9.1
7
+ flake8>=3.9.2
8
+ twine>=3.4.1
@@ -0,0 +1,2 @@
1
+ codet
2
+ tests
@@ -0,0 +1,12 @@
1
+ [build-system]
2
+ requires = ["setuptools>=42", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [tool.black]
6
+ line-length = 88
7
+ target-version = ['py36', 'py37', 'py38', 'py39', 'py310']
8
+ include = '\.pyi?$'
9
+
10
+ [tool.isort]
11
+ profile = "black"
12
+ multi_line_output = 3
codet-0.1.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
codet-0.1.0/setup.py ADDED
@@ -0,0 +1,44 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ with open("README.md", "r", encoding="utf-8") as fh:
4
+ long_description = fh.read()
5
+
6
+ setup(
7
+ name="codet",
8
+ version="0.1.0",
9
+ author="Your Name",
10
+ author_email="your.email@example.com",
11
+ description="一个跨平台的命令行文件处理工具",
12
+ long_description=long_description,
13
+ long_description_content_type="text/markdown",
14
+ url="https://github.com/yourusername/codet",
15
+ packages=find_packages(),
16
+ classifiers=[
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.6",
19
+ "Programming Language :: Python :: 3.7",
20
+ "Programming Language :: Python :: 3.8",
21
+ "Programming Language :: Python :: 3.9",
22
+ "Programming Language :: Python :: 3.10",
23
+ "License :: OSI Approved :: MIT License",
24
+ "Operating System :: OS Independent",
25
+ ],
26
+ python_requires=">=3.6",
27
+ install_requires=[
28
+ "click>=8.0.0",
29
+ ],
30
+ entry_points={
31
+ "console_scripts": [
32
+ "codet=codet.cli:main",
33
+ ],
34
+ },
35
+ extras_require={
36
+ "dev": [
37
+ "pytest>=6.0.0",
38
+ "black>=21.5b2",
39
+ "isort>=5.9.1",
40
+ "flake8>=3.9.2",
41
+ "twine>=3.4.1",
42
+ ],
43
+ },
44
+ )
@@ -0,0 +1,3 @@
1
+ """
2
+ 测试包
3
+ """
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """
5
+ 工具函数测试模块
6
+ """
7
+
8
+ import os
9
+ import tempfile
10
+ import unittest
11
+
12
+ from codet.utils import get_system_info, is_file_binary, get_file_info, scan_directory
13
+
14
+
15
+ class TestUtils(unittest.TestCase):
16
+ """工具函数测试类"""
17
+
18
+ def test_get_system_info(self):
19
+ """测试获取系统信息"""
20
+ info = get_system_info()
21
+ self.assertIsInstance(info, dict)
22
+ self.assertIn("system", info)
23
+ self.assertIn("python_version", info)
24
+
25
+ def test_is_file_binary(self):
26
+ """测试二进制文件检测"""
27
+ # 创建文本文件
28
+ with tempfile.NamedTemporaryFile(mode='w', delete=False) as text_file:
29
+ text_file.write("这是一个文本文件")
30
+ text_path = text_file.name
31
+
32
+ # 创建二进制文件
33
+ with tempfile.NamedTemporaryFile(mode='wb', delete=False) as binary_file:
34
+ binary_file.write(b'\x00\x01\x02\x03')
35
+ binary_path = binary_file.name
36
+
37
+ try:
38
+ self.assertFalse(is_file_binary(text_path))
39
+ self.assertTrue(is_file_binary(binary_path))
40
+ finally:
41
+ # 清理临时文件
42
+ os.unlink(text_path)
43
+ os.unlink(binary_path)
44
+
45
+ def test_get_file_info(self):
46
+ """测试获取文件信息"""
47
+ with tempfile.NamedTemporaryFile(mode='w', delete=False) as temp_file:
48
+ temp_file.write("测试文件")
49
+ file_path = temp_file.name
50
+
51
+ try:
52
+ info = get_file_info(file_path)
53
+ self.assertIsInstance(info, dict)
54
+ self.assertEqual(info["path"], file_path)
55
+ self.assertIn("size", info)
56
+ self.assertIn("created", info)
57
+ self.assertIn("modified", info)
58
+ self.assertIn("accessed", info)
59
+ self.assertIn("is_binary", info)
60
+ finally:
61
+ os.unlink(file_path)
62
+
63
+ def test_scan_directory(self):
64
+ """测试目录扫描"""
65
+ with tempfile.TemporaryDirectory() as temp_dir:
66
+ # 创建一些测试文件
67
+ for i in range(3):
68
+ with open(os.path.join(temp_dir, f"file{i}.txt"), 'w') as f:
69
+ f.write(f"测试文件 {i}")
70
+
71
+ # 创建子目录和文件
72
+ sub_dir = os.path.join(temp_dir, "subdir")
73
+ os.mkdir(sub_dir)
74
+ with open(os.path.join(sub_dir, "subfile.txt"), 'w') as f:
75
+ f.write("子目录文件")
76
+
77
+ # 测试非递归扫描
78
+ files = scan_directory(temp_dir, recursive=False)
79
+ self.assertEqual(len(files), 3)
80
+
81
+ # 测试递归扫描
82
+ files = scan_directory(temp_dir, recursive=True)
83
+ self.assertEqual(len(files), 4)
84
+
85
+
86
+ if __name__ == "__main__":
87
+ unittest.main()