File: make_scripts.py

package info (click to toggle)
trash-cli 0.24.5.26-0.3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,972 kB
  • sloc: python: 9,789; sh: 121; makefile: 11
file content (37 lines) | stat: -rw-r--r-- 1,131 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
import os
from textwrap import dedent

from tests.support.project_root import project_root
from trashcli.fs import write_file, make_file_executable


def make_scripts():
    return Scripts(write_file, make_file_executable)


class Scripts:
    def __init__(self, write_file, make_file_executable):
        self.write_file = write_file
        self.make_file_executable = make_file_executable
        self.created_scripts = []

    def add_script(self, name, module, main_function):
        path = script_path_for(name)
        script_contents = dedent("""\
            #!/usr/bin/env python
            from __future__ import absolute_import
            import sys
            from %(module)s import %(main_function)s as main
            sys.exit(main())
            """) % locals()
        self.write_file(path, script_contents)
        self.make_file_executable(path)
        self.created_scripts.append(script_path_without_base_dir_for(name))


def script_path_for(name):
    return os.path.join(project_root(), script_path_without_base_dir_for(name))


def script_path_without_base_dir_for(name):
    return os.path.join(name)