aboutsummaryrefslogtreecommitdiff
path: root/cbc/cli/cbc_remote_purge.py
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2015-07-23 21:51:01 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2015-07-23 21:51:01 -0400
commit2622bcf956178d4b3dd7e4011511172a60747383 (patch)
treedc8d0e0122b69f605c6324ce880f80a70786d00f /cbc/cli/cbc_remote_purge.py
parent237d2159faac7dadb0232e35f7016588db568808 (diff)
downloadcbc-2622bcf956178d4b3dd7e4011511172a60747383.tar.gz
Initial commit of cbc_remote_purge
Diffstat (limited to 'cbc/cli/cbc_remote_purge.py')
-rw-r--r--cbc/cli/cbc_remote_purge.py73
1 files changed, 73 insertions, 0 deletions
diff --git a/cbc/cli/cbc_remote_purge.py b/cbc/cli/cbc_remote_purge.py
new file mode 100644
index 0000000..397a161
--- /dev/null
+++ b/cbc/cli/cbc_remote_purge.py
@@ -0,0 +1,73 @@
+#!/usr/bin/env python
+'''
+DANGER. THIS WILL WIPE AN ENTIRE ANACONDA.ORG REPOSITORY CHANNEL.
+
+YOU HAVE BEEN WARNED.
+'''
+import argparse
+from subprocess import check_output, STDOUT
+
+
+def choose(answer):
+ answer = answer.upper()
+ if answer == 'Y' or answer == 'YES':
+ return True
+
+ return False
+
+
+def prompt_user(channel):
+ message = 'You about to REMOVE every package inside of: {0}'.format(channel)
+ message_length = len(message)
+ print('!' * message_length)
+ print(message)
+ print('!' * message_length)
+ print('')
+ print('Continue? (y/N) ', end='')
+ answer = input()
+ print('')
+
+ return choose(answer)
+
+
+def main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument('channel', help='Name of channel to be purged of its contents')
+ args = parser.parse_args()
+
+ channel = args.channel
+
+ show_command = 'conda-server channel --show {0}'.format(channel).split()
+ show_output = check_output(show_command, stderr=STDOUT)
+ show_output = show_output.decode()
+
+ found = []
+ for line in show_output.splitlines():
+ line = line.lstrip()
+ if not line:
+ continue
+ if not line.startswith('+'):
+ continue
+ line = line.replace('+', '').lstrip()
+ package = '/'.join(line.split('/')[:2])
+ found.append(package)
+
+ if found:
+ print("Packages to remove:")
+ for pkg in found:
+ print(pkg)
+
+ if not prompt_user(channel):
+ print('Operation aborted by user...')
+ exit(0)
+
+ print('')
+ for pkg in found:
+ purge_command = 'conda-server remove -f {0}'.format(pkg).split()
+ print("Removing [{0:>10s}] :: {1:>10s}".format(channel, pkg))
+ purge_output = check_output(purge_command, stderr=STDOUT)
+ else:
+ print("No packages in channel: {0}".format(channel))
+
+if __name__ == '__main__':
+ main()