Exemplo n.º 1
0
def mk_launch_cmd(mem: int = None, init: bool = False) -> str:
  GiB = pow(1024, 3)
  free_mem = virtual_memory().available / GiB
  cmd: str = ""
  o_init = " --initSettings"
  
  if mem is None:
    while mem != EXIT:
      try:
        mem = int(input(strs.Q_MEM))
      except ValueError:
        print(strs.E_INT)
        continue
      if mem >= free_mem:
        print(strs.E_NOMEM)
        continue
      if utils.yes_no(strs.Q_MEM_CONF.format(mem)): continue
      break    
  elif type(mem) != int:
    print(strs.E_INT)
    return None
  elif mem >= free_mem:
    print(strs.E_NOMEM)
    return None
  if mem == EXIT: return None

  cmd = LAUNCH_C.format(mem, JAR_NAME)
  if init is True: cmd = cmd + o_init
  return cmd
Exemplo n.º 2
0
def check_eula(p: Path) -> int:
  if not p.exists and utils.safe_mkdir(p):
    print(strs.E_EULA)
  if utils.yes_no("{0}\n{1}".format(EULA_URL, strs.EULA_CHK)):
    try: p.write_text(EULA_F)
    except Exception as err: 
      print(strs.E_WRITE_TEXT.format(p))
      print(err)
      input()
    return 1
  try: p.write_text(EULA_T)
  except:
    print(strs.E_WRITE_TEXT.format(p))
    return 1
  return 0
Exemplo n.º 3
0
    def set_field(self, field, value):
        """Create or update the value of an attr called field, given the
        desired object type.

        """
        if field in self.text + self.opt_text:
            setattr(self, field, _split(value, str.strip,
                                        self.value_sep))
        elif field in self.real + self.opt_real:
            setattr(self, field, _split(value, float, self.value_sep))
        elif field in self.int + self.opt_int:
            setattr(self, field, _split(value, int, self.value_sep))
        elif field in self.boolean + self.opt_boolean:
            setattr(self, field, yes_no(value))
        else:
            setattr(self, field, value.strip())
Exemplo n.º 4
0
def chk_settings() -> Path:
    p: Path = Path(SETTINGS_PATH)
    if not p.exists():
        print(strs.SET_NEXIST)
    else:
        SETTINGS = utils.safe_json_loads(p)
        if SETTINGS != None:
            try:
                p = Path(SETTINGS[K_DIR])
            except KeyError as err:
                print(strs.E_KEY.format(err, p))
                print(strs.E_SET_LOAD)
            else:
                return p

    if not utils.yes_no(strs.SET_GEN):
        if utils.safe_json_dumps(p, INIT_SETTINGS):
            print(strs.E_SET_INIT)
            return None
    else:
        print(strs.SET_EDIT)
        return None
    return Path(DEFAULT_PATH)
Exemplo n.º 5
0
writefile(question,'yeshow_question.txt', target_dir)
writefile(key, 'yeshow_key.txt', target_dir)
writefile(answer, 'yeshow_answer.txt', target_dir)

p_lines, s_lines = newps(p_lines, s_lines)
# print(len(p_lines) == len(s_lines))    #44028


# for Is there questions
question = []
key = []
answer = []
yes_num = 0
for i in range(len(p_lines)):
    a, k, q, q_num, p_line, s_line = yes_no(p_lines[i], s_lines[i])
    answer.extend(a)
    key.extend(k)
    question.extend(q)
    yes_num += q_num
    p_lines[i] = p_line
    s_lines[i] = s_line

print('Number of yes_questions: %d' % yes_num)   # 27127

writefile(question,'yes_question.txt', target_dir)
writefile(key, 'yes_key.txt', target_dir)
writefile(answer, 'yes_answer.txt', target_dir)

p_lines, s_lines = newps(p_lines, s_lines)
# print(len(p_lines) == len(s_lines))    #44028
Exemplo n.º 6
0
def main():
	args = docopt.docopt(__doc__, version=__version__)
	log_level = 'DEBUG' if args['--debug'] else 'INFO'
	if sys.platform == 'win32':
		log_fn = 'c:/atxpkg/atxpkg.log'
	else:
		log_fn = '/tmp/atxpkg/atxpkg.log'
	utils.logging_setup(log_level, log_fn, print_=True)
	logging.info('*' * 40)
	logging.info('starting atxpkg v%s' % __version__)
	logging.debug('args: %s' % dict(args))
	if sys.platform == 'win32':
		logging.debug('detected win32')
		db_fn = 'c:/atxpkg/installed.json'
		repos_fn = 'c:/atxpkg/repos.txt'
		prefix = 'c:'
		cache_dir = 'c:/atxpkg/cache'
	else:
		logging.debug('detected non-win32')
		db_fn = '/tmp/atxpkg/installed.json'
		repos_fn = '/tmp/atxpkg/repos.txt'
		prefix = ''
		cache_dir = '/tmp/atxpkg/cache'
	repos = utils.get_repos(repos_fn)
	repos.append(cache_dir)
	#logging.debug(str(args))
	prefix = args['--prefix'] if args['--prefix'] else ''
	if not os.path.isfile(db_fn):
		logging.info('%s not found, creating empty one' % db_fn)
		with open(db_fn, 'w') as f:
			f.write('{}')
	if not os.path.isdir(cache_dir):
		logging.info('%s not found, creating empty one' % cache_dir)
		os.makedirs(cache_dir)
	installed_packages = utils.get_installed_packages(db_fn)
	force = args['--force']
	yes, no = args['--yes'], args['--no']
	if args['install']:
		available_packages = utils.get_available_packages(repos)
		for package in args['<package>']:
			package_name = utils.get_package_name(package)
			if package_name not in available_packages:
				raise Exception('unable to find package %s' % package_name)
			if package_name in installed_packages and not force:
				raise Exception('package %s already installed' % package_name)
		for package in args['<package>']:
			package_name = utils.get_package_name(package)
			package_version = utils.get_package_version(package)
			if package_version:
				url = utils.get_specific_version_url(available_packages[package_name], package_version)
			else:
				url = utils.get_max_version_url(available_packages[package_name])
			ver = utils.get_package_version(utils.get_package_fn(url))
			print('install %s-%s' % (package_name, ver))
		if no or not (yes or utils.yes_no('continue?', default='y')):
			return
		for package in args['<package>']:
			package_name = utils.get_package_name(package)
			package_version = utils.get_package_version(package)
			if package_version:
				url = utils.get_specific_version_url(available_packages[package_name], package_version)
			else:
				url = utils.get_max_version_url(available_packages[package_name])
			local_fn = utils.download_package(url, cache_dir)
			if not args['--downloadonly']:
				package_info = utils.install_package(local_fn, prefix, force)
				installed_packages[package_name] = package_info
				utils.save_installed_packages(installed_packages, db_fn)
	elif args['update']:
		available_packages = utils.get_available_packages(repos)
		if args['<package>']:
			packages = args['<package>']
			for package in packages:
				if '..' in package:
					package_old, package_new = package.split('..')
					package_name_old = utils.get_package_name(package_old)
					package_name_new = utils.get_package_name(package_new)
				else:
					package_name_old = package_name_new = utils.get_package_name(package)

				if package_name_old not in installed_packages:
					raise Exception('package %s not installed' % package_name_old)
		else:
			packages = installed_packages.keys()
		packages_to_update = set()
		for package in packages:
			if '..' in package:
				package_old, package_new = package.split('..')
				package_name_old = utils.get_package_name(package_old)
				package_name_new = utils.get_package_name(package_new)
				package_version = utils.get_package_version(package_new)
			else:
				package_name_old = package_name_new = utils.get_package_name(package)
				package_version = utils.get_package_version(package)
			if package_name_new not in available_packages:
				logging.warning('%s not available in any repository' % package_name_new)
				continue
			if package_version:
				url = utils.get_specific_version_url(available_packages[package_name_new], package_version)
			else:
				url = utils.get_max_version_url(available_packages[package_name_new])
			ver_cur = installed_packages[package_name_old]['version']
			ver_avail = utils.get_package_version(utils.get_package_fn(url))
			if package_name_old != package_name_new or ver_avail != ver_cur or force:
				print('update %s-%s -> %s-%s' % (package_name_old, ver_cur, package_name_new, ver_avail))
				packages_to_update.add(package)
		if not packages_to_update:
			print('nothing to update')
			return
		if no or not (yes or utils.yes_no('continue?', default='y')):
			return
		for package in packages_to_update:
			if '..' in package:
				package_old, package_new = package.split('..')
				package_name_old = utils.get_package_name(package_old)
				package_name_new = utils.get_package_name(package_new)
				package_version = utils.get_package_version(package_new)
			else:
				package_name_old = package_name_new = utils.get_package_name(package)
				package_version = utils.get_package_version(package)
			if package_version:
				url = utils.get_specific_version_url(available_packages[package_name_new], package_version)
			else:
				url = utils.get_max_version_url(available_packages[package_name_new])
			ver_cur = installed_packages[package_name_old]['version']
			ver_avail = utils.get_package_version(utils.get_package_fn(url))
			if package_name_old != package_name_new or ver_avail != ver_cur or force:
				local_fn = utils.download_package(url, cache_dir)
				if not args['--downloadonly']:
					package_info = utils.update_package(local_fn, package_name_old, installed_packages[package_name_old], prefix, force)
					del installed_packages[package_name_old]
					installed_packages[package_name_new] = package_info
					utils.save_installed_packages(installed_packages, db_fn)
	elif args['merge_config']:
		if args['<package>']:
			packages = args['<package>']
			for package in packages:
				package_name = utils.get_package_name(package)
				if package_name not in installed_packages:
					raise Exception('package %s not installed' % package_name)
		else:
			packages = installed_packages.keys()
		for package in packages:
			package_name = utils.get_package_name(package)
			if package_name not in installed_packages:
				raise Exception('package %s not installed' % package_name)
		for package in packages:
			utils.mergeconfig_package(package, installed_packages, prefix)
	elif args['remove']:
		for package_name in args['<package>']:
			if package_name not in installed_packages:
				raise Exception('package %s not installed' % package_name)
		for package_name in args['<package>']:
			package_version = installed_packages[package_name]['version']
			print('remove %s-%s' % (package_name, package_version))
		if no or not (yes or utils.yes_no('continue?', default='n')):
			return
		for package_name in args['<package>']:
			utils.remove_package(package_name, installed_packages, prefix)
			del installed_packages[package_name]
			utils.save_installed_packages(installed_packages, db_fn)
	elif args['list_available']:
		available_packages = utils.get_available_packages(repos)
		for package_name in sorted(available_packages.keys()):
			print(package_name)
	elif args['list_installed']:
		for package_name, package_info in installed_packages.items():
			package_version = package_info['version']
			print('%s-%s' % (package_name, package_version))
	elif args['show_untracked']:
		recursive = args['--recursive']
		fn_to_package_name = utils.gen_fn_to_package_name_mapping(installed_packages, prefix)
		if args['<path>']:
			paths = set([args['<path>'], ])
		else:
			paths = set()
			for fn in fn_to_package_name.keys():
				paths.add(os.path.dirname(fn))
		while paths:
			for path in paths.copy():
				for fn in os.listdir(path):
					if os.path.isdir('%s/%s' % (path, fn)) and not os.path.islink('%s/%s' % (path, fn)):
						if recursive:
							paths.add('%s/%s' % (path, fn))
						else:
							continue
					if '%s/%s' % (path, fn) in fn_to_package_name:
						continue
					print('%s/%s' % (path, fn))
				paths.remove(path)
	elif args['clean_cache']:
		utils.clean_cache(cache_dir)
	logging.debug('exit')
	return 0
Exemplo n.º 7
0
def main():
    args = docopt.docopt(__doc__, version=__version__)
    log_level = 'DEBUG' if args['--debug'] else 'INFO'
    if sys.platform == 'win32':
        log_fn = 'c:/atxpkg/atxpkg.log'
    else:
        log_fn = '/tmp/atxpkg/atxpkg.log'
    utils.logging_setup(log_level, log_fn, print_=True)
    logging.info('*' * 40)
    logging.info('starting atxpkg v%s' % __version__)
    logging.debug('args: %s' % dict(args))
    if sys.platform == 'win32':
        logging.debug('detected win32')
        db_fn = 'c:/atxpkg/installed.json'
        repos_fn = 'c:/atxpkg/repos.txt'
        prefix = 'c:'
        cache_dir = 'c:/atxpkg/cache'
    else:
        logging.debug('detected non-win32')
        db_fn = '/tmp/atxpkg/installed.json'
        repos_fn = '/tmp/atxpkg/repos.txt'
        prefix = ''
        cache_dir = '/tmp/atxpkg/cache'
    repos = utils.get_repos(repos_fn)
    repos.append(cache_dir)
    #logging.debug(str(args))
    prefix = args['--prefix'] if args['--prefix'] else ''
    if not os.path.isfile(db_fn):
        logging.info('%s not found, creating empty one' % db_fn)
        with open(db_fn, 'w') as f:
            f.write('{}')
    if not os.path.isdir(cache_dir):
        logging.info('%s not found, creating empty one' % cache_dir)
        os.makedirs(cache_dir)
    installed_packages = utils.get_installed_packages(db_fn)
    force = args['--force']
    yes, no = args['--yes'], args['--no']
    if args['install']:
        available_packages = utils.get_available_packages(repos)
        for package in args['<package>']:
            package_name = utils.get_package_name(package)
            if package_name not in available_packages:
                raise Exception('unable to find package %s' % package_name)
            if package_name in installed_packages and not force:
                raise Exception('package %s already installed' % package_name)
        for package in args['<package>']:
            package_name = utils.get_package_name(package)
            package_version = utils.get_package_version(package)
            if package_version:
                url = utils.get_specific_version_url(
                    available_packages[package_name], package_version)
            else:
                url = utils.get_max_version_url(
                    available_packages[package_name])
            ver = utils.get_package_version(utils.get_package_fn(url))
            print('install %s-%s' % (package_name, ver))
        if no or not (yes or utils.yes_no('continue?', default='y')):
            return
        for package in args['<package>']:
            package_name = utils.get_package_name(package)
            package_version = utils.get_package_version(package)
            if package_version:
                url = utils.get_specific_version_url(
                    available_packages[package_name], package_version)
            else:
                url = utils.get_max_version_url(
                    available_packages[package_name])
            local_fn = utils.download_package(url, cache_dir)
            if not args['--downloadonly']:
                package_info = utils.install_package(local_fn, prefix, force)
                installed_packages[package_name] = package_info
                utils.save_installed_packages(installed_packages, db_fn)
                logging.info('%s-%s is now installed' %
                             (package_name, package_version))
    elif args['update']:
        available_packages = utils.get_available_packages(repos)
        if args['<package>']:
            packages = args['<package>']
            for package in packages:
                if '..' in package:
                    package_old, package_new = package.split('..')
                    package_name_old = utils.get_package_name(package_old)
                    package_name_new = utils.get_package_name(package_new)
                else:
                    package_name_old = package_name_new = utils.get_package_name(
                        package)

                if package_name_old not in installed_packages:
                    raise Exception('package %s not installed' %
                                    package_name_old)
        else:
            packages = installed_packages.keys()
        packages_to_update = set()
        for package in packages:
            if '..' in package:
                package_old, package_new = package.split('..')
                package_name_old = utils.get_package_name(package_old)
                package_name_new = utils.get_package_name(package_new)
                package_version = utils.get_package_version(package_new)
            else:
                package_name_old = package_name_new = utils.get_package_name(
                    package)
                package_version = utils.get_package_version(package)
            if package_name_new not in available_packages:
                logging.warning('%s not available in any repository' %
                                package_name_new)
                continue
            if package_version:
                url = utils.get_specific_version_url(
                    available_packages[package_name_new], package_version)
            else:
                url = utils.get_max_version_url(
                    available_packages[package_name_new])
            ver_cur = installed_packages[package_name_old]['version']
            ver_avail = utils.get_package_version(utils.get_package_fn(url))
            if package_name_old != package_name_new or ver_avail != ver_cur or force:
                print('update %s-%s -> %s-%s' %
                      (package_name_old, ver_cur, package_name_new, ver_avail))
                packages_to_update.add(package)
        if not packages_to_update:
            print('nothing to update')
            return
        if no or not (yes or utils.yes_no('continue?', default='y')):
            return
        for package in packages_to_update:
            if '..' in package:
                package_old, package_new = package.split('..')
                package_name_old = utils.get_package_name(package_old)
                package_name_new = utils.get_package_name(package_new)
                package_version = utils.get_package_version(package_new)
            else:
                package_name_old = package_name_new = utils.get_package_name(
                    package)
                package_version = utils.get_package_version(package)
            if package_version:
                url = utils.get_specific_version_url(
                    available_packages[package_name_new], package_version)
            else:
                url = utils.get_max_version_url(
                    available_packages[package_name_new])
            ver_cur = installed_packages[package_name_old]['version']
            ver_avail = utils.get_package_version(utils.get_package_fn(url))
            if package_name_old != package_name_new or ver_avail != ver_cur or force:
                local_fn = utils.download_package(url, cache_dir)
                if not args['--downloadonly']:
                    package_info = utils.update_package(
                        local_fn, package_name_old,
                        installed_packages[package_name_old], prefix, force)
                    del installed_packages[package_name_old]
                    installed_packages[package_name_new] = package_info
                    utils.save_installed_packages(installed_packages, db_fn)
                    logging.info('%s-%s updated to %s-%s' %
                                 (package_name_old, ver_cur, package_name_new,
                                  ver_avail))
    elif args['merge_config']:
        if args['<package>']:
            packages = args['<package>']
            for package in packages:
                package_name = utils.get_package_name(package)
                if package_name not in installed_packages:
                    raise Exception('package %s not installed' % package_name)
        else:
            packages = installed_packages.keys()
        for package in packages:
            package_name = utils.get_package_name(package)
            if package_name not in installed_packages:
                raise Exception('package %s not installed' % package_name)
        for package in packages:
            utils.mergeconfig_package(package, installed_packages, prefix)
    elif args['remove']:
        for package_name in args['<package>']:
            if package_name not in installed_packages:
                raise Exception('package %s not installed' % package_name)
        for package_name in args['<package>']:
            package_version = installed_packages[package_name]['version']
            print('remove %s-%s' % (package_name, package_version))
        if no or not (yes or utils.yes_no('continue?', default='n')):
            return
        for package_name in args['<package>']:
            utils.remove_package(package_name, installed_packages, prefix)
            del installed_packages[package_name]
            utils.save_installed_packages(installed_packages, db_fn)
    elif args['list_available']:
        available_packages = utils.get_available_packages(repos)
        for package_name in sorted(available_packages.keys()):
            print(package_name)
    elif args['list_installed']:
        for package_name, package_info in installed_packages.items():
            package_version = package_info['version']
            print('%s-%s' % (package_name, package_version))
    elif args['show_untracked']:
        recursive = args['--recursive']
        fn_to_package_name = utils.gen_fn_to_package_name_mapping(
            installed_packages, prefix)
        if args['<path>']:
            paths = set([
                args['<path>'],
            ])
        else:
            paths = set()
            for fn in fn_to_package_name.keys():
                paths.add(os.path.dirname(fn))
        while paths:
            for path in paths.copy():
                for fn in os.listdir(path):
                    if os.path.isdir(
                            '%s/%s' %
                        (path, fn)) and not os.path.islink('%s/%s' %
                                                           (path, fn)):
                        if recursive:
                            paths.add('%s/%s' % (path, fn))
                        else:
                            continue
                    if '%s/%s' % (path, fn) in fn_to_package_name:
                        continue
                    print('%s/%s' % (path, fn))
                paths.remove(path)
    elif args['clean_cache']:
        utils.clean_cache(cache_dir)
    elif args['check']:
        if args['<package>']:
            packages = args['<package>']
            for package in packages:
                if not package in installed_packages.keys():
                    packages = []
                    print('%s not installed' % package)
        else:
            packages = installed_packages.keys()
        if packages:
            for package in packages:
                for fn in installed_packages[package]['md5sums']:
                    if not os.path.isfile('%s/%s' % (prefix, fn)):
                        logging.info('%s/%s does not exist' % (prefix, fn))
                    else:
                        if utils.get_md5sum(
                                '%s/%s' % (prefix, fn)
                        ) != installed_packages[package]['md5sums'][fn]:
                            logging.info('sum of %s/%s differs' % (prefix, fn))
                print('check of %s complete' % package)
                logging.info('check of %s complete' % package)
    logging.debug('exit')
    return 0