Skip to content

Commit 17aec6f

Browse files
committed
HG: Added file command to add or delete files.
1 parent d7ea007 commit 17aec6f

File tree

1 file changed

+44
-7
lines changed

1 file changed

+44
-7
lines changed

malboxes.py

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ def initialize():
7272
'Value of the key.')
7373
parser_reg.add_argument('valuetype', help=
7474
'Type of the value of the key: '
75-
'DWORD for integer, String for string')
75+
'DWORD for integer, String for string.')
7676
parser_reg.set_defaults(func=reg)
7777

7878
# dir command
7979
parser_dir = subparsers.add_parser('directory', help=
80-
'Modifies a directory')
80+
'Modifies a directory.')
8181
parser_dir.add_argument('profile', help=
8282
'Name of the profile to modify.')
8383
parser_dir.add_argument('modtype', help=
@@ -88,18 +88,24 @@ def initialize():
8888

8989
# wallpaper command
9090

91-
# parser_wallpaper = subparsers.add_parser('wallpaper', help=
92-
# '')
93-
9491
# package command
9592
parser_package = subparsers.add_parser('package', help=
96-
'Adds package to install')
93+
'Adds package to install.')
9794
parser_package.add_argument('profile', help=
9895
'Name of the profile to modify.')
9996
parser_package.add_argument('package', help=
100-
'Name of the package to install')
97+
'Name of the package to install.')
10198
parser_package.set_defaults(func=package)
10299

100+
#document command
101+
parser_document = subparsers.add_parser('document', help=
102+
'Adds a file')
103+
parser_document.add_argument('profile', help=
104+
'Name of the profile to modify.')
105+
parser_document.add_argument('docpath', help=
106+
'Path of the file to add with the filename. Ex: C:\Document.txt')
107+
parser_directory.set_defaults(func=document)
108+
103109
# no command
104110
parser.set_defaults(func=default)
105111

@@ -357,6 +363,37 @@ def package(parser, args):
357363
json.dump(config, f, sort_keys=True, indent=4, separators=(',', ': '))
358364
f.close()
359365

366+
def document(parser, args):
367+
""" Adds the file manipulation commands to the profile."""
368+
if args.modtype == "add":
369+
command = "New-Item"
370+
line = "{0} -Path {1}\r\n".format(command, args.dirpath)
371+
print("Adding file: {}".format(args.dirpath))
372+
elif args.modtype == "delete":
373+
command = "Remove-Item"
374+
line = "{0} -Path {1}\r\n".format(
375+
command, args.dirpath)
376+
print("Removing file: {}".format(args.dirpath))
377+
else:
378+
print("Directory modification type invalid.")
379+
print("Valid ones are: add, delete.")
380+
381+
filename = "scripts/windows/{}.ps1".format(args.profile)
382+
f = open(filename, "a")
383+
f.write(line)
384+
f.close()
385+
386+
""" Add the script to the profile."""
387+
config = load_config(args.profile)
388+
provisioners_list = config["provisioners"][0]["scripts"]
389+
""" If the script is not already in the profile."""
390+
if filename not in provisioners_list:
391+
provisioners_list.append(filename)
392+
f = open("profiles/{}.json".format(args.profile), "w")
393+
json.dump(config, f, sort_keys=True, indent=4, separators=(',', ': '))
394+
f.close()
395+
396+
360397
if __name__ == "__main__":
361398
try:
362399
parser, args = initialize()

0 commit comments

Comments
 (0)