def execute(self): log.debug('application name will be: %s', self.fullname) if self.manifest: manifestPath = self.manifest else: try: manifestPath = _locateFile(self.path, 'manifest.json') except IOError: log.error("unable to locate manifest.json") raise ToolsError("unable to locate manifest.json") with printer('Loading manifest'): manifest = CocaineConfigReader.load(manifestPath) with printer('Uploading manifest'): channel = yield self.storage.write('manifests', self.name, manifest, APPS_TAGS) yield channel.rx.get() try: response = yield self.client.build(self.path, tag=self.fullname, streaming=self._on_read) if response.code != 200: raise ToolsError('building failed with error code {0} {1}'.format(response.code, response.body)) response = yield self.client.push(self.fullname, auth={}, streaming=self._on_read) if response.code != 200: raise ToolsError('pushing failed with error code {0} {1}'.format(response.code, response.body)) except Exception as err: log.error("Error occurred. %s Erase manifest", err) channel = yield self.storage.remove('manifests', self.name) yield channel.rx.get() raise err
def execute(self): log.debug('application name will be: %s', self.fullname) if self.manifest: manifestPath = self.manifest else: manifestPath = _locateFile(self.path, 'manifest.json') with printer('Loading manifest'): manifest = CocaineConfigReader.load(manifestPath) with printer('Uploading manifest'): yield self.storage.write('manifests', self.name, manifest, APPS_TAGS) try: response = yield self.client.build(self.path, tag=self.fullname, streaming=self._on_read) if response.code != 200: raise ToolsError('upload failed with error code {0}'.format(response.code)) response = yield self.client.push(self.fullname, {}, streaming=self._on_read) if response.code != 200: raise ToolsError('upload failed with error code {0}'.format(response.code)) except Exception as err: log.error("Error occurred. Erase manifest") yield self.storage.remove('manifests', self.name) raise err
def execute(self): with printer('Loading "%s"', self.name): content = yield self.view() with printer('Editing "%s"', self.name): with tempfile.NamedTemporaryFile(delete=False) as fh: name = fh.name fh.write(json.dumps(content)) ec = None # locate default editor default_editor = locate_editor() if default_editor is not None: default_editor in self.EDITORS and self.EDITORS.remove(default_editor) self.EDITORS.insert(0, default_editor) for editor in self.EDITORS: try: ec = subprocess.call([editor, name]) break except OSError: continue if ec is None: raise ValueError('cannot open runlist for editing - any of {0} editors not found'.format(self.EDITORS)) if ec != 0: raise ValueError('editing failed with exit code {0}'.format(ec)) with open(name) as fh: yield self.upload(fh.read()) # Remove temp file os.unlink(name)
def execute(self): log.debug('application name will be: %s', self.fullname) if self.manifest: manifestPath = self.manifest else: try: manifestPath = _locateFile(self.path, 'manifest.json') except IOError: log.error("unable to locate manifest.json") raise ToolsError("unable to locate manifest.json") with printer('Loading manifest'): manifest = CocaineConfigReader.load(manifestPath) with printer('Uploading manifest'): channel = yield self.storage.write('manifests', self.name, manifest, APPS_TAGS) yield channel.rx.get() try: response = yield self.client.build(self.path, tag=self.fullname, streaming=self._on_read) if response.code != 200: raise ToolsError('building failed with error code {0} {1}'.format(response.code, response.body)) response = yield self.client.push(self.fullname, auth={}, streaming=self._on_read) if response.code != 200: raise ToolsError('pushing failed with error code {0} {1}'.format(response.code, response.body)) except Exception as err: log.error("Error occurred. %s Erase manifest" % err) channel = yield self.storage.remove('manifests', self.name) yield channel.rx.get() raise err
def _createRepository(self): with printer('Creating temporary directory') as p: repositoryPath = tempfile.mkdtemp() p(repositoryPath) with printer('Copying "%s" to "%s"', self.path, repositoryPath): repositoryPath = os.path.join(repositoryPath, 'repo') log.debug('Repository temporary path - "{0}"'.format(repositoryPath)) shutil.copytree(self.path, repositoryPath) return repositoryPath
def execute(self): with printer('Loading manifest'): manifest = CocaineConfigReader.load(self.manifest) with printer('Reading package "%s"', self.package): package = msgpack.dumps(readArchive(self.package)) with printer('Uploading manifest'): yield self.storage.write('manifests', self.name, manifest, APPS_TAGS) with printer('Uploading application "%s"', self.name): yield self.storage.write('apps', self.name, package, APPS_TAGS)
def execute(self): with printer('Loading manifest'): manifest = CocaineConfigReader.load(self.manifest) # Not only a manifest is being uploaded, # self.package could be None if manifest_only=True if self.package is not None: with printer('Reading package "%s"', self.package): package = msgpack.dumps(readArchive(self.package)) with printer('Uploading application "%s"', self.name): yield self.storage.write('apps', self.name, package, APPS_TAGS) with printer('Uploading manifest'): yield self.storage.write('manifests', self.name, manifest, APPS_TAGS)
def _createPackage(self, repositoryPath): with printer('Creating package'): packagePath = os.path.join(repositoryPath, 'package.tar.gz') tar = tarfile.open(packagePath, mode='w:gz') tar.add(repositoryPath, arcname='') tar.close() return packagePath
def execute(self): with printer('Removing "%s"', self.name): apps = yield List(self.storage).execute() if self.name not in apps: raise ToolsError('application "{0}" does not exist'.format(self.name)) yield self.storage.remove('manifests', self.name) yield self.storage.remove('apps', self.name)
def execute(self): with printer('Removing "%s"', self.name): apps = yield List(self.storage).execute() if self.name not in apps: raise ToolsError('application "{0}" does not exist'.format( self.name)) yield self.storage.remove('manifests', self.name) yield self.storage.remove('apps', self.name)
def execute(self): with printer('Loading manifest'): manifest = CocaineConfigReader.load(self.manifest) # Not only a manifest is being uploaded, # self.package could be None if manifest_only=True if self.package is not None: with printer('Reading package "%s"', self.package): package = msgpack.dumps(readArchive(self.package)) with printer('Uploading application "%s"', self.name): channel = yield self.storage.write('apps', self.name, package, APPS_TAGS) yield channel.rx.get() with printer('Uploading manifest'): channel = yield self.storage.write('manifests', self.name, manifest, APPS_TAGS) yield channel.rx.get() raise gen.Return("Uploaded successfully")
def execute(self): with printer('Removing "%s"', self.name): apps = yield List(self.storage).execute() if self.name not in apps: raise ToolsError('application "{0}" does not exist'.format(self.name)) yield self.storage.remove('manifests', self.name) try: yield self.storage.remove('apps', self.name) except ServiceError: log.info('Unable to delete an application source from storage.', 'It\'s okay, if the application is a Docker image')
def execute(self): with printer('Loading "%s"', self.name): content = yield self.view() with printer('Editing "%s"', self.name): with tempfile.NamedTemporaryFile(delete=False) as fh: name = fh.name fh.write(json.dumps(content, indent=4)) ec = None # locate default editor default_editor = locate_editor() if default_editor is not None: default_editor in self.EDITORS and self.EDITORS.remove( default_editor) self.EDITORS.insert(0, default_editor) for editor in self.EDITORS: try: ec = subprocess.call([editor, name]) break except OSError: continue if ec is None: raise ValueError( 'cannot open runlist for editing - any of {0} editors not found' .format(self.EDITORS)) if ec != 0: raise ValueError( 'editing failed with exit code {0}'.format(ec)) with open(name) as fh: yield self.upload(fh.read()) # Remove temp file os.unlink(name)
def execute(self): with printer('Loading "%s"', self.name): content = yield runlist.View(self.storage, self.name).execute() with printer('Editing "%s"', self.name): with tempfile.NamedTemporaryFile(delete=False) as fh: name = fh.name fh.write(json.dumps(content)) ec = None for editor in self.EDITORS: try: ec = subprocess.call([editor, name]) break except OSError: continue if ec is None: raise ValueError('cannot open runlist for editing - any of {0} editors not found'.format(self.EDITORS)) if ec != 0: raise ValueError('editing failed with exit code {0}'.format(ec)) with open(name) as fh: yield runlist.Upload(self.storage, self.name, fh.read()).execute()
def execute(self): with printer('Removing "%s"', self.name): apps = yield List(self.storage).execute() if self.name not in apps: raise ToolsError('application "{0}" does not exist'.format(self.name)) channel = yield self.storage.remove('manifests', self.name) yield channel.rx.get() try: channel = yield self.storage.remove('apps', self.name) yield channel.rx.get() except ServiceError: log.info('Unable to delete an application source from storage. ' 'It\'s okay, if the application is a Docker image') raise gen.Return("Removed successfully")
def _locateFile(path, filenameLocate): with printer('Locating %s', filenameLocate) as p: basename, separator, extension = filenameLocate.partition('.') locatedFilenames = [] for root, dirNames, filenames in os.walk(path): for filename in filenames: if filename.startswith(basename): priority = 1 if root == path: priority += 100 if filename == filenameLocate: priority += 10 locatedFilenames.append((os.path.join(root, filename), priority)) locatedFilenames = sorted(locatedFilenames, key=lambda filename: filename[1], reverse=True) log.debug('Filenames found: {0}'.format(locatedFilenames)) if not locatedFilenames: raise IOError('No files found in "{0}" or subdirectories'.format(path)) filename, priority = locatedFilenames[0] p('found "%s"', filename) return os.path.abspath(filename)
def execute(self): with printer('Loading profile'): profile = CocaineConfigReader.load(self.profile) with printer('Uploading "%s"', self.name): yield self.storage.write('profiles', self.name, profile, PROFILES_TAGS)
def execute(self): runlist = CocaineConfigReader.load(self.runlist) with printer('Uploading "%s"', self.name): yield self.storage.write('runlists', self.name, runlist, RUNLISTS_TAGS)
def execute(self): with printer('Loading profile'): profile = CocaineConfigReader.load(self.profile) with printer('Uploading "%s"', self.name): yield upload_profile(self.storage, self.name, profile)