def download(self, package, version): self._print('start to download') try: if SHOW_TIME: start_time = datetime.utcnow() addr = self._get_repo(package) rpcclient = RPCClient(addr, REPOSITORY_PORT) if not version: version = rpcclient.request('version', package=package) if not version: show_error( self, 'failed to download, invalid version, package=%s, ' % str(package)) return ret = rpcclient.request('download', package=package, version=version) if ret: if SHOW_TIME: self._print('download, time=%d sec' % (datetime.utcnow() - start_time).seconds) if DEBUG: self._download_cnt += 1 self._print('download, count=%d' % self._download_cnt) return ret except: show_error(self, 'failed to download')
def install(self, uid, package, version, typ, content): self._print('start to install') try: if SHOW_TIME: start_time = datetime.utcnow() addr = self._get_installer(uid) rpcclient = RPCClient(addr, INSTALLER_PORT) res = rpcclient.request('install', uid=uid, package=package, version=version, typ=typ, content=content) if not res: show_error(self, 'failed to install') return if typ == APP: addr = self._get_recorder(package) rpcclient = RPCClient(addr, RECORDER_PORT) info = rpcclient.request('install', package=package) if not info: show_error( self, 'failed to install, invalid update install table') return if SHOW_TIME: self._print('install, time=%d sec' % (datetime.utcnow() - start_time).seconds) if DEBUG: self._install_cnt += 1 self._print('install, count=%d' % self._install_cnt) return res except: show_error(self, 'failed to install')
def install(self, uid, package, version): addr = self._get_repo(package) rpcclient = RPCClient(addr, REPOSITORY_PORT) if not version: version = rpcclient.request('version', package=package) if not version: show_error(self, 'failed to install, invalid version, uid=%s, package=%s' % (uid, package)) return ret = rpcclient.request('download', package=package, version=version) return ret
def login(user, password): user = str(user) pwd = get_md5(str(password)) addr = _get_frontend() rpcclient = RPCClient(addr, FRONTEND_PORT) uid, key = rpcclient.request('login', user=user, pwd=pwd) return (str(uid), str(key))
def has_package(self, uid, package, typ): self._print('has_package, package=%s' % str(package)) addr = self._get_installer(uid) rpcclient = RPCClient(addr, INSTALLER_PORT) return rpcclient.request('has_package', uid=uid, package=package, typ=typ)
def has_package(self, uid, package): self._print('has_package starts , package=%s' % str(package)) addr = self._get_backend() rpcclient = RPCClient(addr, BACKEND_PORT) res = rpcclient.request('has_package', uid=uid, package=package, typ=APP) if res: return True return False
def _alloc_installer(self, uid): self._print('alloc_installer->uid=%s' % str(uid)) addr = self._get_allocator(uid) rpcclient = RPCClient(addr, ALLOCATOR_PORT) if rpcclient.request('alloc_installer', uid=uid): return True else: show_error(self, 'failed to allocate installer') return False
def uninstall(uid, package, typ): addr = _get_frontend() rpcclient = RPCClient(addr, FRONTEND_PORT) ret = rpcclient.request('uninstall', uid=uid, package=package, typ=typ) if not ret: log_err( 'util', 'failed to uninstall, uid=%s, package=%s, typ=%s' % (str(uid), str(package), str(typ))) return return ret
def _update(self, uid, category, package, title, description): self._print('update, cat=%s, desc=%s' % (str(category), str(description))) addr = self._get_recorder(package) rpcclient = RPCClient(addr, RECORDER_PORT) return rpcclient.request('upload', uid=uid, category=category, package=package, title=title, description=description)
def get_author(self, package): self._print('get_author starts, package=%s' % str(package)) try: uid = self._recorder.get_uid(package) if uid: addr = self._get_backend() rpcclient = RPCClient(addr, BACKEND_PORT) name = rpcclient.request('get_name', uid=uid) if name: return str(name) except: show_error(self, 'get_author failed')
def uninstall(self, uid, package, typ): self._print('start to uninstall') addr = self._get_installer(uid) rpcclient = RPCClient(addr, INSTALLER_PORT) res = rpcclient.request('uninstall', uid=uid, package=package, typ=typ) if not res: show_error(self, 'failed to uninstall') return if DEBUG: self._uninstall_cnt += 1 self._print('uninstall, count=%d' % self._uninstall_cnt) return res
def uninstall(self, uid, package): try: addr = self._get_backend() rpcclient = RPCClient(addr, BACKEND_PORT) res = rpcclient.request('uninstall', uid=uid, package=package, typ=APP) if not res: show_error(self, 'failed to uninstall, invalid return res') return if DEBUG: self._uninstall_cnt += 1 self._print('uninstall, count=%d' % self._uninstall_cnt) return res except: show_error(self, 'failed to uninstall')
def download(self, package, version): self._print('download, package=%s, version=%s' %(str(package), str(version))) try: addr = self._get_backend() rpcclient = RPCClient(addr, BACKEND_PORT) info = rpcclient.request('download', package=package, version=version) if not info: show_error(self, 'failed to download, invalid return info') return if DEBUG: self._download_cnt += 1 self._print('download, count=%d' % self._install_cnt) return zlib.decompress(info) except: show_error(self, 'failed to download')
def get_installed_packages(self, uid): self._print('get_installed_packages starts') try: addr = self._get_backend() rpcclient = RPCClient(addr, BACKEND_PORT) res = rpcclient.request('get_installed_packages', uid=uid, typ=APP) if res: result = [] for i in res: result.append(str(i)) return result else: return '' except: show_error(self, 'failed to get installed packages')
def upload_package(buf, uid, package, version, typ, key): addr = _get_frontend() rpcclient = RPCClient(addr, FRONTEND_PORT, uid, key) ret = rpcclient.request('upload', uid=uid, package=package, version=version, buf=buf, typ=typ) if ret: return True else: log_err( 'util', 'failed to upload, uid=%s, package=%s, version=%s, typ=%s' % (str(uid), str(package), str(version), str(typ))) return False
def _get_installer(self, uid): self._print('start to get instsaller addr') try: cache = self._cache addr = cache.get(uid) if addr: return addr else: address = self._get_allocator(uid) rpcclient = RPCClient(address, ALLOCATOR_PORT) addr = rpcclient.request('get_installer', uid=uid) if len(cache) >= CACHE_MAX: cache.popitem() cache.update({uid: addr}) return addr except: show_error(self, 'failed to get instsaller addr')
def install(uid, package, version, typ): addr = _get_frontend() rpcclient = RPCClient(addr, FRONTEND_PORT) if typ == DRIVER: content = None ret = rpcclient.request('install', uid=uid, package=package, version=version, typ=typ, content=content) if not ret: log_err( 'util', 'failed to install, uid=%s, package=%s, version=%s, typ=%s' % (str(uid), str(package), str(version), str(typ))) return return ret
def login(self, user, password): self._print('login starts') try: if SHOW_TIME: start_time = datetime.utcnow() pwd = get_md5(password) addr = self._get_user_backend(user) rpcclient = RPCClient(addr, BACKEND_PORT) uid, key = rpcclient.request('login', user=user, pwd=pwd) if SHOW_TIME: self._print('login , time=%d sec' % (datetime.utcnow() - start_time).seconds) if uid and key: if DEBUG: self._login_cnt += 1 self._print('login, count=%d' % self._login_cnt) return (uid, key) except: show_error(self, 'failed to login')
def install(self, uid, package, version, typ, content): self._print('install, package=%s, vetsion=%s' %(str(package), str(version))) try: if SHOW_TIME: start_time = datetime.utcnow() addr = self._get_backend() rpcclient = RPCClient(addr, BACKEND_PORT) info = rpcclient.request('install', uid=uid, package=package, version=version, typ=typ, content=content) if not info: show_error(self, 'failed to install, invalid return info') return if SHOW_TIME: self._print('install , time=%d sec' % (datetime.utcnow() - start_time).seconds) if DEBUG: self._install_cnt += 1 self._print('install, count=%d' % self._install_cnt) return info except: show_error(self, 'failed to install')
def register(self, user, password, email): self._print('register starts') self._lock.acquire() try: if SHOW_TIME: start_time = datetime.utcnow() pwd = get_md5(password) addr = self._get_user_backend(user) rpcclient = RPCClient(addr, BACKEND_PORT) res = rpcclient.request('register', user=user, pwd=pwd, email=email) if SHOW_TIME: self._print('register , time=%d sec' % (datetime.utcnow() - start_time).seconds) if res: if DEBUG: self._register_cnt += 1 self._print('register, count=%d' % self._register_cnt) return True else: show_error(self, 'failed to register %s' % str(user)) return False finally: self._lock.release()
def upload(self, uid, package, version, buf, typ): self._print('start to upload, uid=%s, package=%s' % (str(uid), str(package))) try: if SHOW_TIME: start_time = datetime.utcnow() try: desc = self._scanner.scan(buf) except: show_error(self, 'failed to scan package %s' % str(package)) return if not desc: show_error(self, 'no description, package=%s' % str(package)) return args = yaml.load(desc) if not args: show_error( self, 'failed to load description, package=%s' % str(package)) return if typ == APP: if not args.get('category') or not args.get( 'title') or not args.get('description'): show_error(self, 'invalid description') return cat = check_category(args['category']) if not cat: show_error(self, 'invalid category, package=%s' % str(package)) return if typ == DRIVER: if not args.get('title') or not args.get('description'): show_error(self, 'invalid description') return addr = self._get_repo(package) rpcclient = RPCClient(addr, REPOSITORY_PORT) res = rpcclient.request('upload', uid=uid, package=package, version=version, buf=buf) if SHOW_TIME: self._print('upload, upload package to repo, time=%d sec' % (datetime.utcnow() - start_time).seconds) start_time = datetime.utcnow() if not res: show_error( self, '%s failed to upload %s to repo' % (str(uid), str(package))) return if SHOW_TIME: self._print('upload, analyze yaml, time=%d sec' % (datetime.utcnow() - start_time).seconds) start_time = datetime.utcnow() if typ == APP: res = self._update(uid, cat, package, args.get('title'), args.get('description')) if res: if DEBUG: self._upload_cnt += 1 self._print('upload, count=%d' % self._upload_cnt) if SHOW_TIME: self._print('upload, update recorder, time=%d sec' % (datetime.utcnow() - start_time).seconds) return res except: show_error(self, 'failed to upload %s' % str(package))
def get_installed_packages(self, uid, typ): self._print('start to get installed packages') addr = self._get_installer(uid) rpcclient = RPCClient(addr, INSTALLER_PORT) return rpcclient.request('get_packages', uid=uid, typ=typ)