File: Atom.edit.py

package info (click to toggle)
renpy 7.1.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 107,352 kB
  • sloc: python: 42,124; ansic: 4,781; makefile: 43; sh: 14
file content (85 lines) | stat: -rwxr-xr-x 1,992 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python

# The path to a copy of Atom that's been installed globally, if one exists.
# This is overidden by RENPY_ATOM, if set. If either is given, that is used
# and no special handing of the .atom directory is performed.
ATOM = None

import sys
import os
import subprocess
import platform
import shutil

import renpy


class Editor(renpy.editor.Editor):

    has_projects = True

    def get_atom(self):
        """
        Returns the path to the atom executable, if None. Also takes care
        of setting up the .atom directory if it's not available.
        """

        atom = os.environ.get("RENPY_ATOM", ATOM)

        if atom is not None:
            return atom

        DIR = os.path.abspath(os.path.dirname(__file__))

        if renpy.windows:
            atom = os.path.join(DIR, "atom-windows", "atom.exe")
        elif renpy.macintosh:
            atom = os.path.join(DIR, "Atom.app", "Contents", "Resources", "app", "atom.sh")
        else:
            atom = os.path.join(DIR, "atom-linux-" + platform.machine(), "atom")

        default_dot_atom = os.path.join(DIR, "default-dot-atom")
        dot_atom = os.path.join(DIR, ".atom")

        if not os.path.exists(dot_atom) and os.path.exists(default_dot_atom):
            shutil.copytree(default_dot_atom, dot_atom)

        return atom

    def begin(self, new_window=False, **kwargs):
        self.args = [ ]

    def open(self, filename, line=None, **kwargs):

        if line:
            filename = "{}:{}".format(filename, line)

        self.args.append(filename)

    def open_project(self, project):
        self.args.append(project)

    def end(self, **kwargs):

        atom = self.get_atom()

        self.args.reverse()

        args = [ atom ] + self.args
        args = [ renpy.exports.fsencode(i) for i in args ]

        subprocess.Popen(args)


def main():
    e = Editor()
    e.begin()

    for i in sys.argv[1:]:
        e.open(i)

    e.end()


if __name__ == "__main__":
    main()