File: tidelift.py

package info (click to toggle)
python-psutil 5.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,512 kB
  • sloc: python: 18,651; ansic: 15,029; makefile: 441; javascript: 153
file content (40 lines) | stat: -rwxr-xr-x 1,210 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python3
# Copyright (c) 2009 Giampaolo Rodola'. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""
Update news entry of Tidelift with latest HISTORY.rst section.
Put your Tidelift API token in a file first:
~/.tidelift.token
"""

from __future__ import print_function
import os
import requests
import psutil
from psutil.tests import import_module_by_path


def upload_relnotes(package, version, text, token):
    url = "https://api.tidelift.com/external-api/" + \
          "lifting/pypi/%s/release-notes/%s" % (package, version)
    res = requests.put(
        url=url,
        data=text.encode('utf8'),
        headers={"Authorization": "Bearer: %s" % token})
    print(version, res.status_code, res.text)
    res.raise_for_status()


def main():
    here = os.path.abspath(os.path.dirname(__file__))
    path = os.path.join(here, "print_announce.py")
    get_changes = import_module_by_path(path).get_changes
    with open(os.path.expanduser("~/.tidelift.token")) as f:
        token = f.read().strip()
    upload_relnotes('psutil', psutil.__version__, get_changes(), token)


if __name__ == "__main__":
    main()