示例#1
0
def getRESInstalledProducts():
    if not os.path.exists('/etc/redhat-release'):
        raise Exception("Getting installed products failed")

    try:
        name = Popen(['/usr/lib/suseRegister/bin/parse_release_info', '-si'],
                     stdout=PIPE).communicate()[0]
        version = Popen(
            ['/usr/lib/suseRegister/bin/parse_release_info', '-sr'],
            stdout=PIPE).communicate()[0]
        release = Popen(
            ['/usr/lib/suseRegister/bin/parse_release_info', '-sc'],
            stdout=PIPE).communicate()[0]
        arch = Popen(['uname', '-m'], stdout=PIPE).communicate()[0]
    except:
        raise Exception("Getting installed products failed")

    if ('redhat' in name.lower() or 'centos' in name.lower()
            or 'slesexpandedsupportplatform' in name.lower()):
        name = 'RES'
    if '.' in version:
        version = version[:version.find('.')]
    ret = []
    p = {
        'name': name,
        'version': version.strip(),
        'release': release.strip(),
        'arch': arch.strip(),
        'baseproduct': 'Y'
    }
    ret.append(p)
    return ret
示例#2
0
 def _check_compatibility(self):
     uname = Popen('uname -a', shell=True, stdout=PIPE).stdout.read()
     if os.path.exists(self.RELEASE_ISSUE_PATH):
         #На всякий случай, добавляем содержимое /etc/issue
         issue_file = open(self.RELEASE_ISSUE_PATH)
         uname += issue_file.read()
         issue_file.close()
     uname = uname.lower()
     if 'debian' not in uname and 'ubuntu' not in uname:
         raise Exception('For now this class only supports Debian and Ubuntu Linux')
示例#3
0
 def DeleteUser(self):
     ''' Delete the selected User from the application GUI and from the system '''
     (model, paths) = self.ui.UsersTree.get_selection().get_selected_rows()
     paths.reverse()
     iter = model.get_iter(paths[0])
     User = model.get_value(iter, 0)
     output = Popen(("sudo -S smbpasswd -x " + User).split(),
                    stdin=PIPE,
                    stdout=PIPE).communicate(self.ROOTPASS)[0]
     output = output.lower()
     print(output)
     if (output.find("deleted") >= 0):
         model.remove(iter)
示例#4
0
 def __pdf_to_txt(path):
     null_f = open(devnull, "w")
     contents = Popen(["ps2ascii", path], stdout=PIPE,
                      stderr=null_f).communicate()[0]
     null_f.close()
     abstract_start_position = contents.lower().find("abstract")
     abstract_end_position = contents[abstract_start_position:].lower(
     ).find("\n\n") + abstract_start_position
     len_abstract = len("abstract") + len('\n')
     return sub(
         '\s+', ' ',
         contents[abstract_start_position +
                  len_abstract:abstract_end_position]).strip()
示例#5
0
def checkOCR(args, pdfCount, fileCount):
	if pdfCount == 1:
		ocrMsg = "Has this file been OCRed?"
	else:
		ocrMsg = "Have all the PDF files been OCRed?"
	askOcr = wx.MessageDialog(None, ocrMsg, 'UploadTool', wx.YES_NO | wx.NO_DEFAULT | wx.ICON_WARNING | wx.STAY_ON_TOP)
	if askOcr.ShowModal() == wx.ID_NO:
		if fileCount == 1:
			openFile = Popen(args.Files, shell=True, stdout=PIPE, stderr=PIPE)
			stdout, stderr = openFile.communicate()
			if len(stdout) > 0:
				print (stdout)
			if len(stderr) > 0:
				print (stderr)
		else:
			for openFile in args.Files:
				if openFile.lower().endswith(".pdf"):
					openFile = Popen(openFile, shell=True, stdout=PIPE, stderr=PIPE)
					stdout, stderr = openFile.communicate()
		checkOCR(args, pdfCount, fileCount)
	else:
		return
示例#6
0
def lookup_country_code(addr):
    out = Popen(['geoiplookup', '-f', database, addr], stdout=PIPE).communicate()[0]
    out = out.split(':')[1].strip().split(',')[0]

    return out.lower()
示例#7
0
    def __init__(self, dist=None, base_dir="/usr/share/python-apt/templates"):
        self.metarelease_uri = ''
        self.templates = []
        self.arch = apt_pkg.config.find("APT::Architecture")

        location = None
        match_loc = re.compile(r"^#LOC:(.+)$")
        match_mirror_line = re.compile(
            r"^(#LOC:.+)|(((http)|(ftp)|(rsync)|(file)|(mirror)|(https))://"
            r"[A-Za-z0-9/\.:\-_@]+)$")
        #match_mirror_line = re.compile(r".+")

        if not dist:
            try:
                dist = Popen(["lsb_release", "-i", "-s"],
                             universal_newlines=True,
                             stdout=PIPE).communicate()[0].strip()
            except (OSError, IOError) as exc:
                if exc.errno != errno.ENOENT:
                    logging.warning('lsb_release failed, using defaults:' %
                                    exc)
                dist = "Debian"

        self.dist = dist

        map_mirror_sets = {}

        dist_fname = "%s/%s.info" % (base_dir, dist)
        csv_fname = "/usr/share/distro-info/{}.csv".format(dist.lower())

        template = None
        component = None
        for line in _expand_template(dist_fname, csv_fname):
            tokens = line.split(':', 1)
            if len(tokens) < 2:
                continue
            field = tokens[0].strip()
            value = tokens[1].strip()
            if field == 'ChangelogURI':
                self.changelogs_uri = _(value)
            elif field == 'MetaReleaseURI':
                self.metarelease_uri = value
            elif field == 'Suite':
                self.finish_template(template, component)
                component = None
                template = Template()
                template.name = value
                template.distribution = dist
                template.match_name = "^%s$" % value
            elif field == 'MatchName':
                template.match_name = value
            elif field == 'ParentSuite':
                template.child = True
                for nanny in self.templates:
                    # look for parent and add back ref to it
                    if nanny.name == value:
                        template.parents.append(nanny)
                        nanny.children.append(template)
            elif field == 'Available':
                template.available = apt_pkg.string_to_bool(value)
            elif field == 'Official':
                template.official = apt_pkg.string_to_bool(value)
            elif field == 'RepositoryType':
                template.type = value
            elif field == 'BaseURI' and not template.base_uri:
                template.base_uri = value
            elif field == 'BaseURI-%s' % self.arch:
                template.base_uri = value
            elif field == 'MatchURI' and not template.match_uri:
                template.match_uri = value
            elif field == 'MatchURI-%s' % self.arch:
                template.match_uri = value
            elif (field == 'MirrorsFile'
                  or field == 'MirrorsFile-%s' % self.arch):
                # Make the path absolute.
                value = os.path.isabs(value) and value or \
                        os.path.abspath(os.path.join(base_dir, value))
                if value not in map_mirror_sets:
                    mirror_set = {}
                    try:
                        with open(value) as value_f:
                            mirror_data = list(
                                filter(match_mirror_line.match,
                                       [x.strip() for x in value_f]))
                    except Exception:
                        print("WARNING: Failed to read mirror file")
                        mirror_data = []
                    for line in mirror_data:
                        if line.startswith("#LOC:"):
                            location = match_loc.sub(r"\1", line)
                            continue
                        (proto, hostname, dir) = split_url(line)
                        if hostname in mirror_set:
                            mirror_set[hostname].add_repository(proto, dir)
                        else:
                            mirror_set[hostname] = Mirror(
                                proto, hostname, dir, location)
                    map_mirror_sets[value] = mirror_set
                template.mirror_set = map_mirror_sets[value]
            elif field == 'Description':
                template.description = _(value)
            elif field == 'Component':
                if (component and not template.has_component(component.name)):
                    template.components.append(component)
                component = Component(value)
            elif field == 'CompDescription':
                component.set_description(_(value))
            elif field == 'CompDescriptionLong':
                component.set_description_long(_(value))
            elif field == 'ParentComponent':
                component.set_parent_component(value)
        self.finish_template(template, component)
        template = None
        component = None