psutil

Форк
0
/
print_announce.py 
138 строк · 3.3 Кб
1
#!/usr/bin/env python3
2

3
# Copyright (c) 2009 Giampaolo Rodola'. All rights reserved.
4
# Use of this source code is governed by a BSD-style license that can be
5
# found in the LICENSE file.
6

7
"""Prints release announce based on HISTORY.rst file content.
8
See: https://pip.pypa.io/en/stable/reference/pip_install/#hash-checking-mode.
9

10
"""
11

12
import os
13
import re
14
import subprocess
15
import sys
16

17
from psutil import __version__
18

19

20
HERE = os.path.abspath(os.path.dirname(__file__))
21
ROOT = os.path.realpath(os.path.join(HERE, '..', '..'))
22
HISTORY = os.path.join(ROOT, 'HISTORY.rst')
23
PRINT_HASHES_SCRIPT = os.path.join(
24
    ROOT, 'scripts', 'internal', 'print_hashes.py'
25
)
26

27
PRJ_NAME = 'psutil'
28
PRJ_VERSION = __version__
29
PRJ_URL_HOME = 'https://github.com/giampaolo/psutil'
30
PRJ_URL_DOC = 'http://psutil.readthedocs.io'
31
PRJ_URL_DOWNLOAD = 'https://pypi.org/project/psutil/#files'
32
PRJ_URL_WHATSNEW = (
33
    'https://github.com/giampaolo/psutil/blob/master/HISTORY.rst'
34
)
35

36
template = """\
37
Hello all,
38
I'm glad to announce the release of {prj_name} {prj_version}:
39
{prj_urlhome}
40

41
About
42
=====
43

44
psutil (process and system utilities) is a cross-platform library for \
45
retrieving information on running processes and system utilization (CPU, \
46
memory, disks, network) in Python. It is useful mainly for system \
47
monitoring, profiling and limiting process resources and management of \
48
running processes. It implements many functionalities offered by command \
49
line tools such as: ps, top, lsof, netstat, ifconfig, who, df, kill, free, \
50
nice, ionice, iostat, iotop, uptime, pidof, tty, taskset, pmap. It \
51
currently supports Linux, Windows, macOS, Sun Solaris, FreeBSD, OpenBSD, \
52
NetBSD and AIX.  Supported Python versions are 2.7 and 3.6+. PyPy is also \
53
known to work.
54

55
What's new
56
==========
57

58
{changes}
59

60
Links
61
=====
62

63
- Home page: {prj_urlhome}
64
- Download: {prj_urldownload}
65
- Documentation: {prj_urldoc}
66
- What's new: {prj_urlwhatsnew}
67

68
Hashes
69
======
70

71
{hashes}
72

73
--
74

75
Giampaolo - https://gmpy.dev/about
76
"""
77

78

79
def get_changes():
80
    """Get the most recent changes for this release by parsing
81
    HISTORY.rst file.
82
    """
83
    with open(HISTORY) as f:
84
        lines = f.readlines()
85

86
    block = []
87

88
    # eliminate the part preceding the first block
89
    while lines:
90
        line = lines.pop(0)
91
        if line.startswith('===='):
92
            break
93
    else:
94
        raise ValueError("something wrong")
95

96
    lines.pop(0)
97
    while lines:
98
        line = lines.pop(0)
99
        line = line.rstrip()
100
        if re.match(r"^- \d+_", line):
101
            line = re.sub(r"^- (\d+)_", r"- #\1", line)
102

103
        if line.startswith('===='):
104
            break
105
        block.append(line)
106
    else:
107
        raise ValueError("something wrong")
108

109
    # eliminate bottom empty lines
110
    block.pop(-1)
111
    while not block[-1]:
112
        block.pop(-1)
113

114
    return "\n".join(block)
115

116

117
def main():
118
    changes = get_changes()
119
    hashes = (
120
        subprocess.check_output([sys.executable, PRINT_HASHES_SCRIPT, 'dist/'])
121
        .strip()
122
        .decode()
123
    )
124
    text = template.format(
125
        prj_name=PRJ_NAME,
126
        prj_version=PRJ_VERSION,
127
        prj_urlhome=PRJ_URL_HOME,
128
        prj_urldownload=PRJ_URL_DOWNLOAD,
129
        prj_urldoc=PRJ_URL_DOC,
130
        prj_urlwhatsnew=PRJ_URL_WHATSNEW,
131
        changes=changes,
132
        hashes=hashes,
133
    )
134
    print(text)
135

136

137
if __name__ == '__main__':
138
    main()
139

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.