File: update_packages.py

package info (click to toggle)
rtv 1.27.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 6,756 kB
  • sloc: python: 11,463; sh: 67; makefile: 4
file content (49 lines) | stat: -rwxr-xr-x 1,382 bytes parent folder | download | duplicates (2)
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
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Update the project's bundled dependencies by downloading the git repository and
copying over the most recent commit.
"""

import os
import shutil
import subprocess
import tempfile

_filepath = os.path.dirname(os.path.relpath(__file__))
ROOT = os.path.abspath(os.path.join(_filepath, '..'))

PRAW_REPO = 'https://github.com/michael-lazar/praw3.git'


def main():

    tmpdir = tempfile.mkdtemp()
    subprocess.check_call(['git', 'clone', PRAW_REPO, tmpdir])

    # Update the commit hash reference
    os.chdir(tmpdir)
    p = subprocess.Popen(['git', 'rev-parse', 'HEAD'], stdout=subprocess.PIPE)
    p.wait()
    commit = p.stdout.read().strip()
    print('Found commit %s' % commit)
    regex = 's/^__praw_hash__ =.*$/__praw_hash__ = \'%s\'/g' % commit
    packages_root = os.path.join(ROOT, 'rtv', 'packages', '__init__.py')
    print('Updating commit hash in %s' % packages_root)
    subprocess.check_call(['sed', '-i', '', regex, packages_root])

    # Overwrite the project files
    src = os.path.join(tmpdir, 'praw')
    dest = os.path.join(ROOT, 'rtv', 'packages', 'praw')
    print('Copying package files to %s' % dest)
    shutil.rmtree(dest, ignore_errors=True)
    shutil.copytree(src, dest)

    # Cleanup
    print('Removing directory %s' % tmpdir)
    shutil.rmtree(tmpdir)


if __name__ == '__main__':
    main()