Skip to content

Commit

Permalink
HG: Added file command to add or delete files.
Browse files Browse the repository at this point in the history
  • Loading branch information
Svieg committed May 17, 2016
1 parent d7ea007 commit 17aec6f
Showing 1 changed file with 44 additions and 7 deletions.
51 changes: 44 additions & 7 deletions malboxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ def initialize():
'Value of the key.')
parser_reg.add_argument('valuetype', help=
'Type of the value of the key: '
'DWORD for integer, String for string')
'DWORD for integer, String for string.')
parser_reg.set_defaults(func=reg)

# dir command
parser_dir = subparsers.add_parser('directory', help=
'Modifies a directory')
'Modifies a directory.')
parser_dir.add_argument('profile', help=
'Name of the profile to modify.')
parser_dir.add_argument('modtype', help=
Expand All @@ -88,18 +88,24 @@ def initialize():

# wallpaper command

# parser_wallpaper = subparsers.add_parser('wallpaper', help=
# '')

# package command
parser_package = subparsers.add_parser('package', help=
'Adds package to install')
'Adds package to install.')
parser_package.add_argument('profile', help=
'Name of the profile to modify.')
parser_package.add_argument('package', help=
'Name of the package to install')
'Name of the package to install.')
parser_package.set_defaults(func=package)

#document command
parser_document = subparsers.add_parser('document', help=
'Adds a file')
parser_document.add_argument('profile', help=
'Name of the profile to modify.')
parser_document.add_argument('docpath', help=
'Path of the file to add with the filename. Ex: C:\Document.txt')
parser_directory.set_defaults(func=document)

# no command
parser.set_defaults(func=default)

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

def document(parser, args):
""" Adds the file manipulation commands to the profile."""
if args.modtype == "add":
command = "New-Item"
line = "{0} -Path {1}\r\n".format(command, args.dirpath)
print("Adding file: {}".format(args.dirpath))
elif args.modtype == "delete":
command = "Remove-Item"
line = "{0} -Path {1}\r\n".format(
command, args.dirpath)
print("Removing file: {}".format(args.dirpath))
else:
print("Directory modification type invalid.")
print("Valid ones are: add, delete.")

filename = "scripts/windows/{}.ps1".format(args.profile)
f = open(filename, "a")
f.write(line)
f.close()

""" Add the script to the profile."""
config = load_config(args.profile)
provisioners_list = config["provisioners"][0]["scripts"]
""" If the script is not already in the profile."""
if filename not in provisioners_list:
provisioners_list.append(filename)
f = open("profiles/{}.json".format(args.profile), "w")
json.dump(config, f, sort_keys=True, indent=4, separators=(',', ': '))
f.close()


if __name__ == "__main__":
try:
parser, args = initialize()
Expand Down

0 comments on commit 17aec6f

Please sign in to comment.