def _package(self, pkg, output_file, with_deps): # pylint: disable=too-many-branches total_files = len(pkg.pkgfiles) if self.errors_only and pkg.res == total_files: return info('%s/%s' % (pkg.cat, pkg.name), output=output_file) if pkg.res == total_files: res_str = color.green('%i/%i' % (pkg.res, total_files)) else: res_str = color.yellow('%i/%i' % (pkg.res, total_files)) print(' Checked: %s files' % res_str, file=output_file) if pkg.res == total_files: print('', file=output_file) return for file_ in pkg.pkgfiles: if not file_.status: continue for error in file_.status: if error == 'EMTIME': out_str = '%s: %s' % (color.red('MTIME'), file_.name) if is_verbose(): out_str += " (recorded '%i'!= actual '%i')" % (file_.mtime, file_.status['EMTIME']) elif error == 'ECHKSUM': out_str = '%s: %s' % (color.red('MD5-DIGEST'), file_.name) if is_verbose(): out_str += " (recorded '%s'!= actual '%s')" % (file_.md5sum, file_.status['ECHKSUM']) elif error == 'ENOENT': out_str = '%s: %s' % (color.red('AFK'), file_.name) else: out_str = '%s: %s' % (color.red('UNKNOWN'), file_.name) print(' ' + out_str, file=output_file) print('', file=output_file)
def POST(self): key = xutils.get_argument("key") value = xutils.get_argument("value") type = xutils.get_argument("type") xutils.info("UpdateConfig", "%s,%s,%s" % (type, key, value)) if key == "BASE_TEMPLATE": xmanager.reload() if key in ("FS_HIDE_FILES", "DEBUG_HTML_BOX", "RECORD_LOCATION"): value = value.lower() in ("true", "yes", "on") if key == "DEBUG": setattr(xconfig, key, value == "True") web.config.debug = xconfig.DEBUG if key in ("RECENT_SEARCH_LIMIT", "RECENT_SIZE", "PAGE_SIZE", "TRASH_EXPIRE"): value = int(value) if type == "int": value = int(value) if type == "bool": value = value.lower() in ("true", "yes", "on") if key in USER_CONFIG_KEY_SET: set_user_config(key, value) else: set_sys_config(key, value) return dict(code="success")
def delete(self, target_dir=None): if target_dir is None or target_dir == "current": target_dir = get_current_target(config=self.cfg) # check in config cfg = load_config() if cfg['ask_delete'] and not userquery("Are you sure you want to delete %s" % target_dir): info("Abort") return vinfo("Deleting %s" % target_dir) try: XTargetBuilder.delete(self, target_dir) except XTargetError, e: if e.log: error(e.log) die(str(e))
def process(self, compare, output_file=sys.stdout): info('Target comparison: %s -> %s' % (compare.old, compare.new), output=output_file) print('', file=output_file) for pkg_id, pkg in compare.pkg_diff.iteritems(): pkg_name = pkg_id.rsplit(':', 1) if pkg_name is None: die('Internal error when parsing comparison results') out_str = pkg_name[0] if pkg_name[1] != 'None': out_str += '(%s)\n' % pkg_name[1] else: out_str += '\n' out_str += self._process_version(pkg.get('old'), pkg.get('new')) out_str += self._process_flags(pkg.get('use')) info(out_str, output=output_file)
def delete(self, target_dir=None): if target_dir is None or target_dir == "current": target_dir = get_current_target(config=self.cfg) # check in config cfg = load_config() if cfg['ask_delete'] and not userquery( "Are you sure you want to delete %s" % target_dir): info("Abort") return vinfo("Deleting %s" % target_dir) try: XTargetBuilder.delete(self, target_dir) except XTargetError, e: if e.log: error(e.log) die(str(e))
def rm_expired_files(dirname, expired_time, depth=0): if depth > MAX_DEPTH: xutils.error("DiskClean", "too deep path, dirname: %s" % dirname) return xutils.info("DiskClean", "check dirname `%s`" % dirname) now = time.time() for fname in os.listdir(dirname): fpath = os.path.join(dirname, fname) if os.path.islink(fpath): continue if os.path.isdir(fpath): rm_expired_files(fpath, expired_time, depth + 1) if is_empty_dir(fpath): xutils.rmfile(fpath) st = os.stat(fpath) if now - st.st_ctime >= expired_time: xutils.info("DiskClean", "%s is expired" % fname) xutils.rmfile(fpath)
def POST(self): key = xutils.get_argument("key") value = xutils.get_argument("value") type = xutils.get_argument("type") xutils.info("UpdateConfig", "%s,%s,%s" % (type, key, value)) if key == "BASE_TEMPLATE": xmanager.reload() if key in ("FS_HIDE_FILES", "DEBUG_HTML_BOX", "RECORD_LOCATION"): value = value.lower() in ("true", "yes", "on") if key == "DEBUG": setattr(xconfig, key, value == "True") web.config.debug = xconfig.DEBUG if key in ("RECENT_SEARCH_LIMIT", "RECENT_SIZE", "PAGE_SIZE", "TRASH_EXPIRE"): value = int(value) if key == "LANG": web.setcookie("lang", value) setattr(xconfig, key, value) cacheutil.hset('sys.config', key, value) return dict(code="success")
def __init__(self, config=None, type_=XBUILDER_DEFTYPE): self.log_fd = None self.build_info = {} self.plugin_list = [] if config and not os.path.isfile(config): raise XUtilsError("Can't find config file %s" % config) if type_ not in XBUILDER_TYPES: raise XUtilsError('Unkown build type %s' % type_) self.type = type_ self.config(config) workdir = self.cfg['build']['workdir'] if self.cfg['build']['clean_workdir']: info('Cleaning workdir') shutil.rmtree(workdir, ignore_errors=True) try: os.makedirs(workdir) except OSError as e: if e.errno != errno.EEXIST: raise self.log_file = os.path.join(workdir, XBUILDER_LOGFILE) self.log_fd = open(self.log_file, 'a') self.target_builder = XTargetBuilder(arch=r'*', stdout=self.log_fd, stderr=self.log_fd) self.xportage = XPortage(root='/') self.info('Loading plugins:', eol=False) for plugin in self.cfg['build']['plugins']: self.out('%s' % plugin, eol=False) p = __import__('xbuilder.plugins.%s' % plugin, fromlist=['register']) p.register(self) self.out('')
try: XTargetBuilder.__init__(self, arch, sync, stdout, stderr, config) except XTargetError, e: die(str(e)) self._arch_given = bool(arch) def list_profiles(self, pkg_atom=None): verbose = is_verbose() try: tgt_list = XTargetBuilder.list_profiles_ng(self, pkg_atom, version=verbose, filter=self._arch_given) except XTargetError, e: die(str(e)) info("Available targets:") try: if verbose: for target, starred in tgt_list: target_info = self.xportage.portdb.aux_get(target, ["KEYWORDS", "IUSE"]) archs = [] for kword in target_info[0].split(): if kword[0] == '~': archs.append(color.yellow(kword)) else: archs.append(color.green(kword)) if starred: tgt_visible = color.green(" * ") else: tgt_visible = " " print " %s=%-30s ARCH=\"%s\" USE=\"%s\"" % (tgt_visible, target, " ".join(archs), target_info[1])
def log(msg): # six.print_(time.strftime("%Y-%m-%d %H:%M:%S"), msg) xutils.info("INIT", msg)
def info(self, msg, eol=True): info(msg, eol) if eol: print(msg, file=self.log_fd) else: print(msg, file=self.log_fd, end='')
def _orphans(self, orphans, output_file): info('Orphan files ' + color.yellow('(%i)' % len(orphans)), output=output_file) for orphan in orphans: print(' %s' % orphan, file=output_file)
def _collisions(self, collisions, output_file): info('Packages file collision', output=output_file) for file_ in collisions: out_str = ' %s: %s' % (file_, ' '.join(collisions[file_])) print(out_str, file=output_file) print('', file=output_file)
def _header(self, output_file): info('Target VDB report', output=output_file) print('', file=output_file)
XTargetBuilder.__init__(self, arch, sync, stdout, stderr, config) except XTargetError, e: die(str(e)) self._arch_given = bool(arch) def list_profiles(self, pkg_atom=None): verbose = is_verbose() try: tgt_list = XTargetBuilder.list_profiles_ng(self, pkg_atom, version=verbose, filter=self._arch_given) except XTargetError, e: die(str(e)) info("Available targets:") try: if verbose: for target, starred in tgt_list: target_info = self.xportage.portdb.aux_get( target, ["KEYWORDS", "IUSE"]) archs = [] for kword in target_info[0].split(): if kword[0] == '~': archs.append(color.yellow(kword)) else: archs.append(color.green(kword)) if starred: tgt_visible = color.green(" * ") else: tgt_visible = " "