class UploadRemote(actions.Storage): def __init__(self, storage, path, name): super(UploadRemote, self).__init__(storage) self.url = path self.name = name if not self.url: raise ValueError('Please specify repository URL') if not self.name: rx = re.compile(r'^.*/(?P<name>.*?)(\..*)?$') match = rx.match(self.url) self.name = match.group('name') @coroutine def execute(self): repositoryPath = tempfile.mkdtemp() manifestPath = os.path.join(repositoryPath, 'manifest-start.json') packagePath = os.path.join(repositoryPath, 'package.tar.gz') self.repositoryDownloader = GitRepositoryDownloader() self.moduleInstaller = PythonModuleInstaller(repositoryPath, manifestPath) print('Repository path: {0}'.format(repositoryPath)) try: yield self.cloneRepository(repositoryPath) yield self.installRepository() yield self.createPackage(repositoryPath, packagePath) yield Upload( self.storage, **{ 'name': self.name, 'manifest': manifestPath, 'package': packagePath }).execute() except (RepositoryDownloadError, ModuleInstallError) as err: print(err) @coroutine def cloneRepository(self, repositoryPath): self.repositoryDownloader.download(self.url, repositoryPath) @coroutine def installRepository(self): self.moduleInstaller.install() @coroutine def createPackage(self, repositoryPath, packagePath): tar = tarfile.open(packagePath, mode='w:gz') tar.add(repositoryPath, arcname='')
class AppUploadFromRepositoryAction(StorageAction): def __init__(self, storage, **config): super(AppUploadFromRepositoryAction, self).__init__(storage, **config) self.name = config.get('name') self.url = config.get('url') if not self.url: raise ValueError('Please specify repository URL') if not self.name: rx = re.compile(r'^.*/(?P<name>.*?)(\..*)?$') match = rx.match(self.url) self.name = match.group('name') def execute(self): return ChainFactory([self.doWork]) def doWork(self): repositoryPath = tempfile.mkdtemp() manifestPath = os.path.join(repositoryPath, 'manifest-start.json') packagePath = os.path.join(repositoryPath, 'package.tar.gz') self.repositoryDownloader = GitRepositoryDownloader() self.moduleInstaller = PythonModuleInstaller(repositoryPath, manifestPath) print('Repository path: {0}'.format(repositoryPath)) try: yield self.cloneRepository(repositoryPath) yield self.installRepository() yield self.createPackage(repositoryPath, packagePath) yield AppUploadAction(self.storage, **{ 'name': self.name, 'manifest': manifestPath, 'package': packagePath }).execute() except (RepositoryDownloadError, ModuleInstallError) as err: print(err) @chain.threaded def cloneRepository(self, repositoryPath): self.repositoryDownloader.download(self.url, repositoryPath) @chain.threaded def installRepository(self): self.moduleInstaller.install() @chain.threaded def createPackage(self, repositoryPath, packagePath): with tarfile.open(packagePath, mode='w:gz') as tar: tar.add(repositoryPath, arcname='')
def execute(self): repositoryPath = tempfile.mkdtemp() manifestPath = os.path.join(repositoryPath, 'manifest-start.json') packagePath = os.path.join(repositoryPath, 'package.tar.gz') self.repositoryDownloader = GitRepositoryDownloader() self.moduleInstaller = PythonModuleInstaller(repositoryPath, manifestPath) print('Repository path: {0}'.format(repositoryPath)) try: yield self.cloneRepository(repositoryPath) yield self.installRepository() yield self.createPackage(repositoryPath, packagePath) yield Upload(self.storage, **{ 'name': self.name, 'manifest': manifestPath, 'package': packagePath }).execute() except (RepositoryDownloadError, ModuleInstallError) as err: print(err)
class UploadRemote(actions.Storage): def __init__(self, storage, path, name): super(UploadRemote, self).__init__(storage) self.url = path self.name = name if not self.url: raise ValueError('Please specify repository URL') if not self.name: rx = re.compile(r'^.*/(?P<name>.*?)(\..*)?$') match = rx.match(self.url) self.name = match.group('name') @coroutine def execute(self): repositoryPath = tempfile.mkdtemp() manifestPath = os.path.join(repositoryPath, 'manifest-start.json') packagePath = os.path.join(repositoryPath, 'package.tar.gz') self.repositoryDownloader = GitRepositoryDownloader() self.moduleInstaller = PythonModuleInstaller(repositoryPath, manifestPath) print('Repository path: {0}'.format(repositoryPath)) try: yield self.cloneRepository(repositoryPath) yield self.installRepository() yield self.createPackage(repositoryPath, packagePath) yield Upload(self.storage, **{ 'name': self.name, 'manifest': manifestPath, 'package': packagePath }).execute() except (RepositoryDownloadError, ModuleInstallError) as err: print(err) @coroutine def cloneRepository(self, repositoryPath): self.repositoryDownloader.download(self.url, repositoryPath) @coroutine def installRepository(self): self.moduleInstaller.install() @coroutine def createPackage(self, repositoryPath, packagePath): tar = tarfile.open(packagePath, mode='w:gz') tar.add(repositoryPath, arcname='')
def installCocaineFramework(self): path = tempfile.mkdtemp() downloader = GitRepositoryDownloader(stream=self.stream) try: log.debug(COCAINE_DOWNLOAD_START.format(COCAINE_PYTHON_FRAMEWORK_URL, path)) downloader.download(COCAINE_PYTHON_FRAMEWORK_URL, path) except RepositoryDownloadError as err: raise ModuleInstallError(err) log.debug(COCAINE_INSTALL_START) python = os.path.join(self.virtualEnvironmentPath, 'bin', 'python') process = subprocess.Popen([python, 'setup.py', 'install', '--without-tools'], cwd=path, stdout=self.stream, stderr=self.stream) process.wait() if process.returncode != 0: raise ModuleInstallError(COCAINE_INSTALL_ERROR) log.debug(COCAINE_INSTALL_FINISH)
def installCocaineFramework(self, venv): log.debug('Downloading cocaine-framework-python ...') cocaineFrameworkUrl = '[email protected]:cocaine/cocaine-framework-python.git' cocaineFrameworkPath = tempfile.mkdtemp() downloader = GitRepositoryDownloader() try: downloader.download(cocaineFrameworkUrl, cocaineFrameworkPath) except RepositoryDownloadError as err: raise ModuleInstallError(err.message) log.debug('Installing cocaine-framework-python ...') python = os.path.join(venv, 'bin', 'python') process = subprocess.Popen([python, 'setup.py', 'install'], cwd=cocaineFrameworkPath, stdout=self.devnull, stderr=self.devnull) process.wait() if process.returncode != 0: raise ModuleInstallError() else: log.debug('Cocaine-framework-python has been successfully installed')
def test_clone(): d = GitRepositoryDownloader() d.download("blabla", tempfile.gettempdir())