You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
calculate-utils-2.1-lib/pym/cl_devices.py

67 lines
2.0 KiB

#-*- coding: utf-8 -*-
#Copyright 2008 Calculate Pack, http://www.calculate-linux.ru
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import re
import glob
import cl_utils
#класс для работы с видео устройствами
class Video:
#получить список видеокарт
def getcards(self):
card_names=[]
g_path=cl_utils.getpathenv()
s_cmd='%s lspci | grep VGA' % g_path
lines=os.popen(s_cmd).readlines()
if lines:
for line in lines:
re_res=re.search(\
'[0-9\:\.]+\sVGA compatible controller:(.+)$',line)
if re_res:
card_names.append(re_res.group(1))
if len(card_names)>0:
return card_names
else:
return None
#работа с блочными устройствами
class block_dev:
_dev_list=[]
def __init__(self):
self._getlist()
def _getlist(self):
devlist=[]
for dev in ('sd','hd'):
devlist+=glob.glob('/sys/block/%s*'%dev)
for dev in devlist:
self._dev_list.append(dev.split('/')[-1])
#получить список устройств
def get_listdev(self):
return self._dev_list
#проверить на извлекаемое устройство
def isremovable(self, dev):
if dev in self.get_listdev():
res=int(open('/sys/block/%s/removable'%dev).read().split()[0])
return res
else:
return None