def handle(self, *args, **options): if len(args) != 1: raise CommandError("Pass one and only one [container_name] as an argument") self._connection = Auth()._get_connection() container_name = args[0] print("Creating container: {0}".format(container_name)) container = self._connection.create_container(container_name) if options.get("private"): print("Private container: {0}".format(container_name)) container.make_private() else: print("Public container: {0}".format(container_name)) container.make_public(ttl=CUMULUS["TTL"])
def handle(self, *args, **options): self._connection = Auth()._get_connection() container_names = self._connection.list_container_names() if args: matches = [] for container_name in container_names: if container_name in args: matches.append(container_name) container_names = matches if not container_names: print("No containers found.") return if not args: account_details = self._connection.get_account_details() print("container_count | object_count | bytes_used") print("{0}, {1}, {2}\n".format( account_details["container_count"], account_details["object_count"], account_details["bytes_used"], )) opts = ["name", "count", "size", "uri"] output = [o for o in opts if options.get(o)] if output: print(" | ".join(output)) else: print(" | ".join(opts)) for container_name in container_names: container = self._connection.get_container(container_name) info = { "name": container.name, "count": container.object_count, "size": container.total_bytes, "cdn_enabled": container.cdn_enabled, "uri": container.cdn_uri if container.cdn_enabled else None, } output = [str(info[o]) for o in opts if options.get(o)] if not output: output = [str(info[o]) for o in opts] print(", ".join(output))
def handle_noargs(self, *args, **options): # setup self.set_options(options) self._connection = Auth()._get_connection() self.container = self._connection.get_container(self.container_name) # wipe first if self.wipe: self.wipe_container() # match local files abspaths = self.match_local(self.file_root, self.includes, self.excludes) relpaths = [] for path in abspaths: filename = path.split(self.file_root)[1] if filename.startswith("/"): filename = filename[1:] relpaths.append(filename) if not relpaths: settings_root_prefix = "MEDIA" if self.syncmedia else "STATIC" raise CommandError( "The {0}_ROOT directory is empty " "or all files have been ignored.".format(settings_root_prefix)) for path in abspaths: if not os.path.isfile(path): raise CommandError("Unsupported filetype: {0}.".format(path)) # match cloud objects cloud_objs = self.match_cloud(self.includes, self.excludes) remote_objects = { obj.name: datetime.datetime.strptime(obj.last_modified, "%Y-%m-%dT%H:%M:%S.%f") for obj in self.container.get_objects() } # sync self.upload_files(abspaths, relpaths, remote_objects) self.delete_extra_files(relpaths, cloud_objs) if not self.quiet or self.verbosity > 1: self.print_tally()
def handle(self, *args, **options): """ Lists all the items in a container to stdout. """ self._connection = Auth()._get_connection() if len(args) == 0: containers = self._connection.list_containers() if not containers: print("No containers were found for this account.") elif len(args) == 1: containers = self._connection.list_container_object_names(args[0]) if not containers: print("No matching container found.") else: raise CommandError("Pass one and only one [container_name] as an argument") for container in containers: print(container)
def handle(self, *args, **options): if len(args) != 1: raise CommandError( "Pass one and only one [container_name] as an argument") container_name = args[0] if not options.get("is_yes"): is_ok = raw_input( "Permanently delete container {0}? [y|N] ".format( container_name)) if not is_ok == "y": raise CommandError("Aborted") print("Connecting") self._connection = Auth()._get_connection() container = self._connection.get_container(container_name) print("Deleting objects from container {0}".format(container_name)) container.delete_all_objects() container.delete() print("Deletion complete")
def set_options(self, **options): """ Set instance variables based on an options dict """ self.interactive = options['interactive'] self.verbosity = options['verbosity'] self.symlink = options['link'] self.clear = options['clear'] self.dry_run = options['dry_run'] ignore_patterns = options['ignore_patterns'] if options['use_default_ignore_patterns']: ignore_patterns += ['CVS', '.*', '*~'] self.ignore_patterns = list(set(ignore_patterns)) self.post_process = options['post_process'] self.container_name = CUMULUS["CONTAINER"] self._connection = Auth()._get_connection() self.container = self._connection.get_container(self.container_name)