-
Notifications
You must be signed in to change notification settings - Fork 31
/
hs-config.py
140 lines (113 loc) · 5 KB
/
hs-config.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
139
140
# Author: Areeb Beigh
# Created: 11th June 2016
"""
This script creates (or overwrites) a config.ini file with the default
settings which has to be edited later, if config already exists and
overwriting is canceled it simply opens the config file in the default
application
"""
#############################################################################
# Copyright (C) 2016 Areeb Beigh <[email protected]> #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
#############################################################################
# Python imports
import argparse
import configparser
import os
import sys
# Local imports
from src import help
from src.initialize import Initialize
initializer = Initialize()
# hacker-scripts base directory
BASE_DIRECTORY = initializer.BASE_DIRECTORY
# Full path to the config file
config_file = os.path.join(BASE_DIRECTORY, initializer.config_file)
Config = configparser.ConfigParser()
Config.read(config_file)
# Default path to sublime text editor 3 on Windows
editor_path = "C:\\Program Files\\Sublime Text 3\\sublime_text.exe"
if not os.path.exists(editor_path):
editor_path = ""
def main():
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument('--help',
'-help',
action='store_true')
args = parser.parse_args()
if args.help:
cmd = sys.argv[0].partition(".")[0]
help.display_help(cmd)
return
if os.path.isfile(config_file):
print("The file config.ini already exists, do you want to continue and " +
"over-write the file with new settings? (y/N)")
action = input().upper()
if action == "Y" or action == "YES":
create_file()
else:
os.startfile(config_file, 'edit') # Opens the file for editing
sys.exit(0)
else:
create_file()
def create_file():
"""Creates a new configuration file with default values"""
with open(config_file, "w") as f:
f.write("; hacker-scripts configuration file\n")
# Add sections and parameters the the config file
Config.add_section("hs-backup")
Config.set("hs-backup", "purge", "")
Config.set("hs-backup", "retries", "")
Config.set("hs-backup", "backup_location", "")
Config.set("hs-backup", "directory1", "")
Config.set("hs-backup", "directory2", "")
Config.set("hs-backup", "directory3", "")
Config.add_section("hs-browse")
Config.set("hs-browse", "url1", "")
Config.set("hs-browse", "url2", "")
Config.set("hs-browse", "url3", "")
Config.add_section("hs-manage")
Config.set("hs-manage", "extension_set_1", ".txt, .ppt, .doc, .xml")
Config.set("hs-manage", "location_1", "")
Config.set("hs-manage", "extension_set_2", ".jpg, .png, .gif")
Config.set("hs-manage", "location_2", "")
Config.set("hs-manage", "extension_set_3", ".avi, .mp4, .mkv, .flv, .wmv, .m4v, .mpg, .3gp, .3g2, .f4v")
Config.set("hs-manage", "location_3", "")
Config.add_section("hs-music")
Config.set("hs-music", "directory1", "")
Config.set("hs-music", "directory2", "")
Config.set("hs-music", "directory3", "")
Config.add_section("hs-start")
Config.set("hs-start", "program1", "")
Config.set("hs-start", "program2", "")
Config.set("hs-start", "program3", "")
Config.add_section("hs-wallpaper")
Config.set("hs-wallpaper", "directory1", "")
Config.set("hs-wallpaper", "directory2", "")
Config.set("hs-wallpaper", "directory3", "")
Config.add_section("hs-work")
Config.set(
"hs-work",
"editor",
editor_path)
Config.set("hs-work", "project1", "")
Config.set("hs-work", "project2", "")
Config.set("hs-work", "project3", "")
Config.write(f)
print("Config file has been created at " + config_file)
print("You can go ahead and configure the file.")
os.startfile('config.ini', 'edit')
sys.exit(0)
main()