Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def execute(self):
if self.cwd == self.root:
self.raise_exists()
else:
print "Creating .pin directory structure..."
alias = None
if self.options.alias:
alias = self.options.alias[0]
registry.initialize_project(self.cwd, alias=alias)
self.root = self.cwd
return True
def done(self):
print "pin project initialized in: %s" % self.cwd
command.register(PinInitCommand)
class PinDestroyCommand(command.PinCommand):
'''Destroy and unregister the project from pin.'''
command = 'destroy'
def is_relevant(self):
return self.root
def raise_no_project(self):
msg = "No pin project found. (aborted)"
print msg
def execute(self):
current_alias = registry._projects[proj_path].get('alias')
if current_alias:
prompt = "Alias `{alias}' already set, overwrite?".format(alias=current_alias)
answer = option_select(['y','n'], prompt)
if answer == 'n':
print "Aborted."
return
_projects[proj_path]['alias'] = name
_aliases[name] = proj_path
registry.save_registry()
print "Alias `{alias}' has been set for, {path}".format(alias=name,
path=proj_path)
return True
command.register(PinAliasCommand)
class PinHelpCommand(command.PinCommand):
'''This help information.'''
command = 'help'
def setup_parser(self, parser):
parser.add_argument('command', nargs='*',
default=None)
parser.add_argument('-a', '--all', dest='all', action='store_true')
def process_simplecom(self, name, collen):
comcls = command.get(name)
comobj = comcls([])
if comobj.is_relevant() or self.options.all:
while repeat:
pinpath = os.path.join(self.root, PROJECT_FOLDER)
print "WARNING: Will destory all data in the .pin directory!"
os.system("ls %s" % pinpath)
selection = option_select(['y', 'n'], "Really destroy?")
if selection == 'n':
print "Aborted."
return
elif selection == 'y':
shutil.rmtree(pinpath)
registry.unregister(self.root)
return True
def done(self):
print "Pin project has been destroyed."
command.register(PinDestroyCommand)
class PinProjectProxy(object):
'''Pin project project used for Go command'''
def __init__(self, path):
self.__doc__ = path
class PinGoCommand(command.PinCommand):
'''
Teleport to a specific project.
'''
command = 'go'
def setup_parser(self, parser):
pcomcls = command.get(self.options.command[0])
if pcomcls and hasattr(pcomcls, 'get_subcommands'):
subcommands = pcomcls.get_subcommands()
if subcommands:
for name, com in subcommands.items():
if name == self.options.command[1]:
print com.__doc__ or 'Command has no docstring.'
else:
self.do_default_help()
else:
self.do_default_help()
command.register(PinHelpCommand)
def write_script(self, file):
if self.path:
file.write("cd %s\n" % self.path)
@classmethod
def get_subcommands(cls):
subs = dict()
for p, meta in registry._projects.items():
alias = meta.get('alias')
if alias:
subs[alias] = PinProjectProxy(p)
else:
subs[os.path.basename(p)] = PinProjectProxy(p)
return subs
command.register(PinGoCommand)
class PinAliasCommand(command.PinCommand):
'''Manage project aliases'''
command = 'alias'
def setup_parser(self, parser):
parser.add_argument('name', nargs="?")
parser.add_argument('-p', '--proj', nargs="?", dest='project')
def execute(self):
# pdb.set_trace()
name = self.options.name
project = getattr(self.options, 'project', None)
if project: