-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdkp.py
138 lines (124 loc) · 4.42 KB
/
dkp.py
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import sys
import os
import io
import mimetypes
__author__ = "Mohammed Alkindi"
__version__ = '0.1'
__version_type__ = "development"
# Program create desktop files in order to show them as a program in
# Ubuntu Unity, KDE and other launchers
ERROR_OS_NOT_SUPPORTED = 10
ERROR_BIN_NOT_FOUND = 11
help_command_line = \
"""Desktop file creator
SETTINGS :
:
-c :Create new .desktop file
-h :Show help
-v :Show application version
SETTING OPTIONS :
:
-c [Binary file] [desktop output] :"""
file_cmd = "#This file was generated by dkp desktop file maker v" + __version__
help_about = __author__ + " v" + __version__ + " " + __version_type__
dpe_Desktop_Entry = "[Desktop Entry]"
dpe_Desktop_Action_NewDocument = "[Desktop Action NewDocument]"
dp_name="Name" # Support multiple languages. Main language is English
dp_genericname="GenericName"
dp_version="Version"
dp_terminal="Terminal"
mimetypes.MimeTypes
dp_icon="Icon"
dp_actions = "Actions"
dp_type = "Type"
dp_exec = "Exec"
dp_mimetype="MimeType"
dp_Comment="Comment" # Support multiple languages. Main language is English
dp_StartupNotify = "StartupNotify"
dp_X_GIO_NoFuse = "X-GIO-NoFuse"
dp_StartupWMClass = "StartupWMClass"
dp_X_KDE_Protocols = "X-KDE-Protocols"
dp_Categories = "Categories"
# Determine if this os is posix or not
debuglevel = 0 # Set debug level to zero
# Fetch OS data
os_data = os.uname()
f- io.FileIO()
if str(os_data.sysname).lower() != "linux":
print("ERROR: This operating system is not supported by dkp.")
quit(ERROR_OS_NOT_SUPPORTED)
# Check and store the given arguments
arg = sys.argv[1:]
if len(arg) > 0:
if arg[0] == "-h":
print(help_command_line)
quit()
elif arg[0] == "-v":
print(help_about)
quit()
if len(arg) < 2:
print("No arguments, Please type -h for argument list")
quit()
excefilename = arg[0]
distoffilename = str(arg[1])
try:
fle = io.FileIO(excefilename)
except FileNotFoundError:
print("the file name \"" + excefilename + "\" was not found. Please make sure the location of input file")
quit(ERROR_BIN_NOT_FOUND)
# Check weather if the located file is application, shell or any file is executable
mim = mimetypes.guess_type(excefilename)
# Data enter manuals
data_version = "1.0"
data_version_ = input("Version[" + data_version + "]:")
if data_version_ != "":
data_version = data_version_
data_terminal = False
data_terminal_ = input("Terminal[" + str(data_terminal) + "]:")
if data_version_ != "":
data_terminal = bool(data_terminal_)
data_Icon = "Nothing"
data_Icon_ = input("Icon[" + data_Icon + "]:")
if data_Icon_ != "":
data_Icon = data_Icon_
data_type = "Application"
data_type_ = input("Type[" + data_type + "]:")
if data_type_ != "":
data_type = data_type_
data_categories = "Anything;"
data_categories_ = input("Categories[" + data_categories + "]:")
if data_categories_ != "":
data_categories = data_categories_
data_exec = excefilename
data_exec_ = input("Exec[" + excefilename + "]:")
if data_exec_ != "":
data_exec = data_exec_
data_name = excefilename
data_name_ = input("Name[" + data_name + "]:")
if data_name_ != "":
data_name = data_name_
data_genericname = excefilename
data_genericname_ = input("GenericName[" + data_genericname + "]:")
if data_genericname_ != "":
data_genericname = data_genericname_
data_comment = ""
data_comment_ = input("Comment[" + data_comment + "]:")
if data_comment_ != "":
data_comment = data_comment_
filearray = list((file_cmd,dpe_Desktop_Entry))
filearray.append(dp_version + "=" + data_version)
filearray.append(dp_terminal + "=" + str(data_terminal))
filearray.append(dp_icon + "=" + data_Icon)
filearray.append(dp_type + "=" + data_type)
filearray.append(dp_Categories + "=" + data_categories)
filearray.append(dp_exec + "=" + data_exec)
filearray.append(dp_name + "=" + data_name)
filearray.append(dp_genericname + "=" + data_genericname)
filearray.append(dp_Comment + "=" + data_comment)
filewrite = io.FileIO(distoffilename,mode='w')
for item in filearray:
filewrite.write(bytearray(item,"UTF-8"))
filewrite.write(bytearray("\n","UTF-8"))
filewrite.flush()
filewrite.close()
print("Desktop file created at " + distoffilename)