|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2014 - 2017 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing some common utility functions for the Git package. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 import os |
|
13 import sys |
|
14 |
|
15 from PyQt5.QtCore import QProcessEnvironment, QByteArray |
|
16 |
|
17 import Utilities |
|
18 |
|
19 |
|
20 def getConfigPath(): |
|
21 """ |
|
22 Public function to get the filename of the config file. |
|
23 |
|
24 @return filename of the config file (string) |
|
25 """ |
|
26 if Utilities.isWindowsPlatform(): |
|
27 userprofile = os.environ["USERPROFILE"] |
|
28 return os.path.join(userprofile, ".gitconfig") |
|
29 else: |
|
30 homedir = Utilities.getHomeDir() |
|
31 return os.path.join(homedir, ".gitconfig") |
|
32 |
|
33 |
|
34 def prepareProcess(proc, language=""): |
|
35 """ |
|
36 Public function to prepare the given process. |
|
37 |
|
38 @param proc reference to the proces to be prepared (QProcess) |
|
39 @param language language to be set (string) |
|
40 """ |
|
41 env = QProcessEnvironment.systemEnvironment() |
|
42 |
|
43 # set the language for the process |
|
44 if language: |
|
45 env.insert("LANGUAGE", language) |
|
46 |
|
47 proc.setProcessEnvironment(env) |
|
48 |
|
49 |
|
50 try: |
|
51 from Globals import strToQByteArray |
|
52 except ImportError: |
|
53 def strToQByteArray(txt): |
|
54 """ |
|
55 Module function to convert a Python string into a QByteArray. |
|
56 |
|
57 @param txt Python string to be converted |
|
58 @type str, bytes, bytearray, unicode |
|
59 """ |
|
60 if sys.version_info[0] == 2: |
|
61 if isinstance(txt, unicode): # __IGNORE_WARNING__ |
|
62 txt = txt.encode("utf-8") |
|
63 else: |
|
64 if isinstance(txt, str): |
|
65 txt = txt.encode("utf-8") |
|
66 |
|
67 return QByteArray(txt) |