#!/usr/bin/env python # -*- mode: python; -*- #============================================================================ # This library is free software; you can redistribute it and/or # modify it under the terms of version 2.1 of the GNU Lesser General Public # License as published by the Free Software Foundation. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #============================================================================ # Copyright (C) 2008 FUJITSU Limited # Based on the blkif.py #============================================================================ """Support for VSCSI Devices. """ import os import os.path import sys import re import string from xen.util import utils SYSFS_SCSI_PATH = "/bus/scsi/devices" SYSFS_SCSI_DEV_VENDOR_PATH = '/vendor' SYSFS_SCSI_DEV_MODEL_PATH = '/model' SYSFS_SCSI_DEV_TYPEID_PATH = '/type' SYSFS_SCSI_DEV_REVISION_PATH = '/rev' SYSFS_SCSI_DEV_SCSILEVEL_PATH = '/scsi_level' def _vscsi_get_devname_by(name, scsi_devices): """A device name is gotten by the HCTL. (e.g., '0:0:0:0' to '/dev/sda') """ try: search = re.compile(r'' + name + '$', re.DOTALL) except Exception, e: raise VmError("vscsi: invalid expression. " + str(e)) for hctl, devname, sg, scsi_id in scsi_devices: if search.match(hctl): return (hctl, devname) return (None, None) def _vscsi_get_hctl_by(phyname, scsi_devices): """An HCTL is gotten by the device name or the scsi_id. (e.g., '/dev/sda' to '0:0:0:0') """ if re.match('/dev/sd[a-z]+([1-9]|1[0-5])?$', phyname): # sd driver name = re.sub('(^/dev/)|([1-9]|1[0-5])?$', '', phyname) elif re.match('/dev/sg[0-9]+$', phyname): # sg driver name = re.sub('^/dev/', '', phyname) elif re.match('/dev/st[0-9]+$', phyname): # st driver name = re.sub('^/dev/', '', phyname) else: # scsi_id -gu name = phyname for hctl, devname, sg, scsi_id in scsi_devices: if name in [devname, sg, scsi_id]: return (hctl, devname) return (None, None) def _vscsi_get_scsiid(sg): scsi_id = os.popen('/sbin/scsi_id -gu -s /class/scsi_generic/' + sg).read().split() if len(scsi_id): return scsi_id[0] return None def _vscsi_get_scsidevices_by_lsscsi(option = ""): """ get all scsi devices information by lsscsi """ devices = [] for scsiinfo in os.popen('{ lsscsi -g %s; } 2>/dev/null' % option).readlines(): s = scsiinfo.split() hctl = s[0][1:-1] try: devname = s[-2].split('/dev/')[1] except IndexError: devname = None try: sg = s[-1].split('/dev/')[1] scsi_id = _vscsi_get_scsiid(sg) except IndexError: sg = None scsi_id = None devices.append([hctl, devname, sg, scsi_id]) return devices def _vscsi_get_scsidevices_by_sysfs(): """ get all scsi devices information by sysfs """ devices = [] sysfs_mnt = utils.find_sysfs_mount() for dirpath, dirnames, files in os.walk(sysfs_mnt + SYSFS_SCSI_PATH): for hctl in dirnames: paths = os.path.join(dirpath, hctl) devname = None sg = None scsi_id = None for f in os.listdir(paths): realpath = os.path.realpath(os.path.join(paths, f)) if re.match('^block', f) or \ re.match('^tape', f) or \ re.match('^scsi_changer', f) or \ re.match('^onstream_tape', f): devname = os.path.basename(realpath) if re.match('^scsi_generic', f): sg = os.path.basename(realpath) scsi_id = _vscsi_get_scsiid(sg) devices.append([hctl, devname, sg, scsi_id]) return devices def vscsi_get_scsidevices(): """ get all scsi devices information """ devices = _vscsi_get_scsidevices_by_lsscsi("") if devices: return devices return _vscsi_get_scsidevices_by_sysfs() def vscsi_get_hctl_and_devname_by(target, scsi_devices = None): if scsi_devices is None: if len(target.split(':')) == 4: scsi_devices = _vscsi_get_scsidevices_by_lsscsi(target) elif target.startswith('/dev/'): scsi_devices = _vscsi_get_scsidevices_by_lsscsi("| grep %s" % target) else: scsi_devices = _vscsi_get_scsidevices_by_lsscsi("") if not scsi_devices: scsi_devices = _vscsi_get_scsidevices_by_sysfs() if len(target.split(':')) == 4: return _vscsi_get_devname_by(target, scsi_devices) else: return _vscsi_get_hctl_by(target, scsi_devices) def get_scsi_vendor(pHCTL): try: sysfs_mnt = utils.find_sysfs_mount() sysfs_scsi_dev_path = \ os.path.join(sysfs_mnt + SYSFS_SCSI_PATH, pHCTL) scsi_vendor = \ os.popen('cat ' + sysfs_scsi_dev_path + \ SYSFS_SCSI_DEV_VENDOR_PATH).read() return scsi_vendor.splitlines()[0] except: return None def get_scsi_model(pHCTL): try: sysfs_mnt = utils.find_sysfs_mount() sysfs_scsi_dev_path = \ os.path.join(sysfs_mnt + SYSFS_SCSI_PATH, pHCTL) scsi_model = \ os.popen('cat ' + sysfs_scsi_dev_path + \ SYSFS_SCSI_DEV_MODEL_PATH).read() return scsi_model.splitlines()[0] except: return None def get_scsi_typeid(pHCTL): try: sysfs_mnt = utils.find_sysfs_mount() sysfs_scsi_dev_path = \ os.path.join(sysfs_mnt + SYSFS_SCSI_PATH, pHCTL) scsi_typeid = \ os.popen('cat ' + sysfs_scsi_dev_path + \ SYSFS_SCSI_DEV_TYPEID_PATH).read() return int(scsi_typeid.splitlines()[0]) except: return None def get_scsi_revision(pHCTL): try: sysfs_mnt = utils.find_sysfs_mount() sysfs_scsi_dev_path = \ os.path.join(sysfs_mnt + SYSFS_SCSI_PATH, pHCTL) scsi_revision = \ os.popen('cat ' + sysfs_scsi_dev_path + \ SYSFS_SCSI_DEV_REVISION_PATH).read() return scsi_revision.splitlines()[0] except: return None def get_scsi_scsilevel(pHCTL): try: sysfs_mnt = utils.find_sysfs_mount() sysfs_scsi_dev_path = \ os.path.join(sysfs_mnt + SYSFS_SCSI_PATH, pHCTL) scsi_scsilevel = \ os.popen('cat ' + sysfs_scsi_dev_path + \ SYSFS_SCSI_DEV_SCSILEVEL_PATH).read() return int(scsi_scsilevel.splitlines()[0]) except: return None def get_all_scsi_devices(): scsi_devs = [] for scsi_info in vscsi_get_scsidevices(): scsi_dev = { 'physical_HCTL': scsi_info[0], 'dev_name': None, 'sg_name': scsi_info[2], 'scsi_id': None } if scsi_info[1] is not None: scsi_dev['dev_name'] = scsi_info[1] if scsi_info[3] is not None: scsi_dev['scsi_id'] = scsi_info[3] scsi_dev['vendor_name'] = \ get_scsi_vendor(scsi_dev['physical_HCTL']) scsi_dev['model'] = \ get_scsi_model(scsi_dev['physical_HCTL']) scsi_dev['type_id'] = \ get_scsi_typeid(scsi_dev['physical_HCTL']) scsi_dev['revision'] = \ get_scsi_revision(scsi_dev['physical_HCTL']) scsi_dev['scsi_level'] = \ get_scsi_scsilevel(scsi_dev['physical_HCTL']) try: lsscsi_info = os.popen('lsscsi %s 2>/dev/null' % scsi_dev['physical_HCTL']).read().split() scsi_dev['type'] = lsscsi_info[1] except: scsi_dev['type'] = None scsi_devs.append(scsi_dev) return scsi_devs 57 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
/* Copyright 2017 Fred Sundvik
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#if defined(VISUALIZER_ENABLE)
#include "default_animations.h"
#include "visualizer.h"
#ifdef LCD_ENABLE
#include "lcd_keyframes.h"
#endif
#ifdef LCD_BACKLIGHT_ENABLE
#include "lcd_backlight_keyframes.h"
#endif
#ifdef BACKLIGHT_ENABLE
#include "led_backlight_keyframes.h"
#endif
#include "visualizer_keyframes.h"
#if defined(LCD_ENABLE) || defined(LCD_BACKLIGHT_ENABLE) || defined(BACKLIGHT_ENABLE)
static bool keyframe_enable(keyframe_animation_t* animation, visualizer_state_t* state) {
#ifdef LCD_ENABLE
lcd_keyframe_enable(animation, state);
#endif
#ifdef LCD_BACKLIGHT_ENABLE
lcd_backlight_keyframe_enable(animation, state);
#endif
#ifdef BACKLIGHT_ENABLE
led_backlight_keyframe_enable(animation, state);
#endif
return false;
}
static bool keyframe_disable(keyframe_animation_t* animation, visualizer_state_t* state) {
#ifdef LCD_ENABLE
lcd_keyframe_disable(animation, state);
#endif
#ifdef LCD_BACKLIGHT_ENABLE
lcd_backlight_keyframe_disable(animation, state);
#endif
#ifdef BACKLIGHT_ENABLE
led_backlight_keyframe_disable(animation, state);
#endif
return false;
}
static bool keyframe_fade_in(keyframe_animation_t* animation, visualizer_state_t* state) {
bool ret = false;
#ifdef LCD_BACKLIGHT_ENABLE
ret |= lcd_backlight_keyframe_animate_color(animation, state);
#endif
#ifdef BACKLIGHT_ENABLE
ret |= led_backlight_keyframe_fade_in_all(animation, state);
#endif
return ret;
}
static bool keyframe_fade_out(keyframe_animation_t* animation, visualizer_state_t* state) {
bool ret = false;
#ifdef LCD_BACKLIGHT_ENABLE
ret |= lcd_backlight_keyframe_animate_color(animation, state);
#endif
#ifdef BACKLIGHT_ENABLE
ret |= led_backlight_keyframe_fade_out_all(animation, state);
#endif
return ret;
}
// Don't worry, if the startup animation is long, you can use the keyboard like normal
// during that time
keyframe_animation_t default_startup_animation = {
#if LCD_ENABLE
.num_frames = 3,
#else
.num_frames = 2,
#endif
.loop = false,
.frame_lengths = {
0,
#if LCD_ENABLE
0,
#endif
gfxMillisecondsToTicks(5000)},
.frame_functions = {
keyframe_enable,
#if LCD_ENABLE
lcd_keyframe_draw_logo,
#endif
keyframe_fade_in,
},
};
keyframe_animation_t default_suspend_animation = {
#if LCD_ENABLE
.num_frames = 3,
#else
.num_frames = 2,
#endif
.loop = false,
.frame_lengths = {
#if LCD_ENABLE
0,
#endif
gfxMillisecondsToTicks(1000),
0},
.frame_functions = {
#if LCD_ENABLE
lcd_keyframe_display_layer_text,
#endif
keyframe_fade_out,
keyframe_disable,
},
};
#endif
#if defined(BACKLIGHT_ENABLE)
#define CROSSFADE_TIME 1000
#define GRADIENT_TIME 3000
keyframe_animation_t led_test_animation = {
.num_frames = 14,
.loop = true,
.frame_lengths = {
gfxMillisecondsToTicks(1000), // fade in
gfxMillisecondsToTicks(1000), // no op (leds on)
gfxMillisecondsToTicks(1000), // fade out
gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade
gfxMillisecondsToTicks(GRADIENT_TIME), // left to rigt (outside in)
gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade
gfxMillisecondsToTicks(GRADIENT_TIME), // top_to_bottom
0, // mirror leds
gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade
gfxMillisecondsToTicks(GRADIENT_TIME), // left_to_right (mirrored, so inside out)
gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade
gfxMillisecondsToTicks(GRADIENT_TIME), // top_to_bottom
0, // normal leds
gfxMillisecondsToTicks(CROSSFADE_TIME), // crossfade
},
.frame_functions = {
led_backlight_keyframe_fade_in_all,
keyframe_no_operation,
led_backlight_keyframe_fade_out_all,
led_backlight_keyframe_crossfade,
led_backlight_keyframe_left_to_right_gradient,
led_backlight_keyframe_crossfade,
led_backlight_keyframe_top_to_bottom_gradient,
led_backlight_keyframe_mirror_orientation,
led_backlight_keyframe_crossfade,
led_backlight_keyframe_left_to_right_gradient,
led_backlight_keyframe_crossfade,
led_backlight_keyframe_top_to_bottom_gradient,
led_backlight_keyframe_normal_orientation,
led_backlight_keyframe_crossfade,
},
};
#endif
#endif