Skip to content

Instantly share code, notes, and snippets.

@ScreamingDev
Created February 19, 2014 22:42
Show Gist options
  • Select an option

  • Save ScreamingDev/9103205 to your computer and use it in GitHub Desktop.

Select an option

Save ScreamingDev/9103205 to your computer and use it in GitHub Desktop.
very first python :)
import argparse
import git
import os
import colorama
import shutil
class InitAction(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
if os.path.isdir(".git"):
print colorama.Fore.YELLOW + "This is already a project. Skipping the rest."
return
repo = git.Repo.init(os.curdir)
print colorama.Fore.GREEN + "Created new repo"
class DestroyAction(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
try:
shutil.rmtree('.git')
print colorama.Fore.GREEN + "Deleted repository"
except OSError as ex:
print colorama.Fore.RED + "Something went wrong. Is it realy a git repo?"
parser = argparse.ArgumentParser(description="Clone repos and spread them in your project")
parser.add_argument('-q', '--quiet', help="Only shows errors.", action='store_true')
parser.add_argument('-v', '--verbose', help="Tell me more about it!", action='store_true')
parser.add_argument('--init', help="Set up the basic structure", action=InitAction, nargs=0)
parser.add_argument('--destroy', help="Bye bye beautiful!", action=DestroyAction, nargs=0)
parser.parse_args()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment