xenoslib 0.3.2__tar.gz → 0.4.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.
Files changed (25) hide show
  1. {xenoslib-0.3.2/xenoslib.egg-info → xenoslib-0.4.0}/PKG-INFO +1 -1
  2. {xenoslib-0.3.2 → xenoslib-0.4.0}/xenoslib/__init__.py +1 -0
  3. {xenoslib-0.3.2 → xenoslib-0.4.0}/xenoslib/about.py +1 -1
  4. xenoslib-0.4.0/xenoslib/time_utils.py +95 -0
  5. {xenoslib-0.3.2 → xenoslib-0.4.0/xenoslib.egg-info}/PKG-INFO +1 -1
  6. {xenoslib-0.3.2 → xenoslib-0.4.0}/xenoslib.egg-info/SOURCES.txt +1 -0
  7. {xenoslib-0.3.2 → xenoslib-0.4.0}/LICENSE +0 -0
  8. {xenoslib-0.3.2 → xenoslib-0.4.0}/README.md +0 -0
  9. {xenoslib-0.3.2 → xenoslib-0.4.0}/setup.cfg +0 -0
  10. {xenoslib-0.3.2 → xenoslib-0.4.0}/setup.py +0 -0
  11. {xenoslib-0.3.2 → xenoslib-0.4.0}/xenoslib/__main__.py +0 -0
  12. {xenoslib-0.3.2 → xenoslib-0.4.0}/xenoslib/base.py +0 -0
  13. {xenoslib-0.3.2 → xenoslib-0.4.0}/xenoslib/dev.py +0 -0
  14. {xenoslib-0.3.2 → xenoslib-0.4.0}/xenoslib/extend.py +0 -0
  15. {xenoslib-0.3.2 → xenoslib-0.4.0}/xenoslib/linux.py +0 -0
  16. {xenoslib-0.3.2 → xenoslib-0.4.0}/xenoslib/mail.py +0 -0
  17. {xenoslib-0.3.2 → xenoslib-0.4.0}/xenoslib/mock.py +0 -0
  18. {xenoslib-0.3.2 → xenoslib-0.4.0}/xenoslib/onedrive.py +0 -0
  19. {xenoslib-0.3.2 → xenoslib-0.4.0}/xenoslib/tools/__init__.py +0 -0
  20. {xenoslib-0.3.2 → xenoslib-0.4.0}/xenoslib/tools/config_loader.py +0 -0
  21. {xenoslib-0.3.2 → xenoslib-0.4.0}/xenoslib/win_trayicon.py +0 -0
  22. {xenoslib-0.3.2 → xenoslib-0.4.0}/xenoslib/windows.py +0 -0
  23. {xenoslib-0.3.2 → xenoslib-0.4.0}/xenoslib.egg-info/dependency_links.txt +0 -0
  24. {xenoslib-0.3.2 → xenoslib-0.4.0}/xenoslib.egg-info/requires.txt +0 -0
  25. {xenoslib-0.3.2 → xenoslib-0.4.0}/xenoslib.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xenoslib
3
- Version: 0.3.2
3
+ Version: 0.4.0
4
4
  Summary: Xenos' common lib
5
5
  Home-page: https://github.com/XenosLu/xenoslib.git
6
6
  Author: Xenocider
@@ -10,3 +10,4 @@ elif sys.platform == "linux":
10
10
  elif sys.platform == "darwin":
11
11
  from .linux import * # noqa
12
12
  from .base import * # noqa
13
+ from .time_utils import * # noqa
@@ -4,4 +4,4 @@ __url__ = "https://github.com/XenosLu/xenoslib.git"
4
4
  __author__ = "Xenocider"
5
5
  __author_email__ = "xenos.lu@gmail.com"
6
6
  __license__ = "MIT License"
7
- __version__ = "0.3.2"
7
+ __version__ = "0.4.0"
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ # @Author : Xenos Lu
4
+ # @Created : 2023-01
5
+ # @Updated : 2025-08-14
6
+ import os
7
+ import logging
8
+ import inspect
9
+ from datetime import datetime
10
+
11
+ logger = logging.getLogger(__name__)
12
+
13
+ # 添加多语言支持
14
+ def get_system_language():
15
+ """获取系统语言环境"""
16
+ lang = os.getenv('LANG', '').split('.')[0]
17
+ return lang if lang and '_' in lang else 'en_US'
18
+
19
+ # 创建翻译字典
20
+ TRANSLATIONS = {
21
+ 'zh_CN': {
22
+ 'days': ('天', '天'),
23
+ 'hours': ('小时', '小时'),
24
+ 'minutes': ('分钟', '分钟'),
25
+ 'seconds': ('秒', '秒'),
26
+ 'updated': '最近更新',
27
+ 'ago': '前',
28
+ 'file_error': '获取文件信息失败'
29
+ },
30
+ 'en_US': {
31
+ 'days': ('day', 'days'),
32
+ 'hours': ('hour', 'hours'),
33
+ 'minutes': ('minute', 'minutes'),
34
+ 'seconds': ('second', 'seconds'),
35
+ 'updated': 'last updated',
36
+ 'ago': 'ago',
37
+ 'file_error': 'Failed to get file info'
38
+ }
39
+ }
40
+
41
+ def timedelta_to_human_readable(delta, lang=None):
42
+ """将时间差转换为人类可读格式(支持中英双语)"""
43
+ if lang is None:
44
+ lang = get_system_language()
45
+
46
+ trans = TRANSLATIONS.get(lang, TRANSLATIONS['en_US'])
47
+ days = delta.days
48
+ hours, remainder = divmod(delta.seconds, 3600)
49
+ minutes, seconds = divmod(remainder, 60)
50
+
51
+ time_units = {
52
+ "days": (days, trans['days']),
53
+ "hours": (hours, trans['hours']),
54
+ "minutes": (minutes, trans['minutes']),
55
+ "seconds": (seconds, trans['seconds']),
56
+ }
57
+
58
+ for unit, (value, labels) in time_units.items():
59
+ if value > 0:
60
+ # 处理英文单复数
61
+ if lang.startswith('en_') and value > 1:
62
+ return f"{value} {labels[1]}"
63
+ return f"{value}{labels[0]}" if lang.startswith('zh_') else f"{value} {labels[0]}"
64
+
65
+ # 默认返回0秒
66
+ zero_label = "0" + trans['seconds'][0] if lang.startswith('zh_') else f"0 {trans['seconds'][1]}"
67
+ return zero_label
68
+
69
+ def log_file_update_time(lang=None):
70
+ """显示调用文件最近更新时间(支持中英双语)"""
71
+ if lang is None:
72
+ lang = get_system_language()
73
+ trans = TRANSLATIONS.get(lang, TRANSLATIONS['en_US'])
74
+
75
+ try:
76
+ stack = inspect.stack()
77
+ for frame_info in stack:
78
+ if frame_info.filename != __file__:
79
+ file_path = frame_info.filename
80
+ break
81
+ else:
82
+ file_path = __file__
83
+
84
+ mtime = datetime.fromtimestamp(os.path.getmtime(file_path))
85
+ delta_str = timedelta_to_human_readable(datetime.now() - mtime, lang)
86
+ filename = os.path.basename(file_path)
87
+
88
+ # 双语日志输出
89
+ log_msg = (
90
+ f"{filename} {trans['updated']}: "
91
+ f"{mtime:%Y-%m-%d %H:%M} ({delta_str} {trans['ago']})"
92
+ )
93
+ logger.info(log_msg)
94
+ except Exception as e:
95
+ logger.error(f"{trans['file_error']}: {e}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xenoslib
3
- Version: 0.3.2
3
+ Version: 0.4.0
4
4
  Summary: Xenos' common lib
5
5
  Home-page: https://github.com/XenosLu/xenoslib.git
6
6
  Author: Xenocider
@@ -11,6 +11,7 @@ xenoslib/linux.py
11
11
  xenoslib/mail.py
12
12
  xenoslib/mock.py
13
13
  xenoslib/onedrive.py
14
+ xenoslib/time_utils.py
14
15
  xenoslib/win_trayicon.py
15
16
  xenoslib/windows.py
16
17
  xenoslib.egg-info/PKG-INFO
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes