def __init__(self, num_disks, number=None): self.disks = list() self.disks_by_name = dict() self.disk_names = list() disk_names = ["orange", "yellow", "green", "blue", "purple"] for idx in range(num_disks): disk = Disk() disk_name = disk_names[idx] self.disks.append(disk) self.disks_by_name[disk_names[idx]] = disk self.disk_names.append(disk_name) if number is not None: pos = self.num_disk_positions rest = number for disk_name in reversed(disk_names): disk = self.disks_by_name[disk_name] disk_idx = disk_names.index(disk_name) pole_idx = rest // pos**disk_idx disk.pole = pole_idx rest = rest - pole_idx * pos**disk_idx
def add_disk(self, disk_pos_x) -> bool: """ Add new disk to the game board using the horizontal position of the mouse click. Then check if that new disk has won the game. returns True if the new disk has won the game. """ col = (disk_pos_x // 100) # the colomn index on the board list row = find_row(self.game_board[col] ) #find the first non empty row in the given column if row < 6: self.curr_disk = Disk(self.win, disk_pos_x, row, col, self.curr_colour) #create disk object self.game_board[col][ row] = self.curr_disk #insert disk in the proper location on the board self.curr_disk.set_up_disk( self.game_board ) #connect the disk to all surrounding disks on the board while (self.curr_disk.get_set() != True): self.game_view.time_delay() self.update_view(False) if (self.curr_disk.check_win() ): #check if the disk has won the game return True return False return False
def run(self): notify_email = properties["notify_email"] cpu = Cpu(properties["cpu_monitor_rate"], properties["cpu_over_max_count"], notify_email) disk = Disk(properties["all_disk_max_capacity"], properties["single_file_max_capacity"], properties["all_disk_warn_capacity"], properties["direct_remove_file_suffix"], properties["mem_warn_capacity"], log, notify_email) ytj = YTJService(log) second = int(properties["check_interval"]) while 1: try: # cpu.monitor() log.info("cpu health") except Exception as e: log.error("cpu检测脚本出错%s", e.with_traceback(sys.exc_info()[2])) try: # disk.cpu_system_info() log.info("disk health") except Exception as e: log.error("磁盘检测脚本出错%s", e.with_traceback(sys.exc_info()[2])) try: ytj.check() log.info("ytj health") except Exception as e: log.error("磁盘ytj脚本出错%s", e.with_traceback(sys.exc_info()[2])) time.sleep(second)
def gauss(): """ The driver for the generator based implementation """ from Disk import Disk from Gaussian import Gaussian from Mersenne import Mersenne # inputs N = 10**7 box = [(-1, -1), (1, 1)] B = functools.reduce(operator.mul, ((right - left) for left, right in zip(*box))) # the point cloud generator generator = Mersenne() # the region of integration disk = Disk(center=(0, 0), radius=1) # the integrand gaussian = Gaussian(mean=(0, 0), spread=1 / 3) # the integration algorithm # build the point sample sample = generator.points(N, box) # select the interior points interior = disk.interior(sample) # compute the integral integral = B / N * sum(gaussian.eval(interior)) # print out the estimate of the integral print("integral: {0:.8f}".format(integral)) return
def gauss(): """ The driver for the object oriented solution """ from Disk import Disk from Mersenne import Mersenne # inputs N = 10**5 box = [(0,0), (1,1)] # the point cloud generator cloud = Mersenne() # the region of integration disk = Disk(center=(0,0), radius=1) # the integration algorithm total = 0 interior = 0 while total < N: point = cloud.point(box) if disk.interior(point): interior += 1 total += 1 # print out the estimate of #@$\pi$@ print("pi: {0:.8f}".format(4*interior/N)) return
def load_components(self): ''' Loads all essentials components''' # print("Loading components") self.table_of_pages = TableOfPages(self.mem_vir_size, self.page_size, self.num_prog) self.ram = Ram(self.mem_fis_size, self.page_size, self.subtitution, self.num_prog) self.tlb = Tlb(self.num_line, self.subs, self.corr, self.num_prog) self.disk = Disk(self.num_prog)
def testDisk(): from Disk import Disk disk = Disk(center=(0, 0), radius=1) points = [(0, 0), (.5, .5), (1, 1)] print(count(disk.contains(points))) return
def get_all_disks(self): for disk in self.allDisks.split(): self.disksList.update({ disk: Disk( Utils.produce_command( "sudo fdisk -l | grep /dev/sda: |awk '{print $3$4}'"), Utils.produce_command("cat /sys/block/sd?/device/vendor")) })
def reset_disks(self): self.disks.clear() self.clear_towers() self.moves = 0 for index in range(self.numDisks, 0, -1): disk = Disk(index, self.towerS) # print(self.towerS.get_min_disk_index()) self.towerS.add_disk(disk) self.disks.append(disk)
def __init__(self, n=3, start="A", workspace="B", destination="C"): self.startp = Pole(start, 0, 0) self.workspacep = Pole(workspace, 150, 0) self.destinationp = Pole(destination, 300, 0) self.startp.showpole() self.workspacep.showpole() self.destinationp.showpole() for i in range(n): self.startp.pushdisk( Disk("d" + str(i), 0, i * 150, 20, (n - i) * 30))
def __init__(self, screen_rect, window): self.score = {'Red': 0, 'Blue': 0} self.players = [] self.players_threads = [] self.game_objects = [] self.screen_rect = screen_rect self.window = window self.player_size = (pygame.image.load('images/player1_1.png')).get_rect() self.center_field = {'x': WINDOW_WIDTH / 2, 'y': WINDOW_HEIGHT / 2} self.disk = Disk(self)
def test_Disk_10_InitialSync(self): test_Disk.disk = Disk({ 'login': '******', 'auth': self.token, 'path': '~/yd', 'start': True, 'ro': False, 'ow': False, 'exclude': ['excluded_folder'] }) sleep(50) self.assertTrue(self.disk.status == 'idle')
def test_Disk_00_notStarted(self): test_Disk.disk = Disk({ 'login': '******', 'auth': self.token, 'path': '~/yd', 'start': False, 'ro': False, 'ow': False, 'exclude': ['excluded_folder'] }) sleep(2) self.assertTrue(self.disk.status == 'none') self.assertEqual(self.disk.exit(), 0)
def test_Disk_01_noAccess(self): test_Disk.disk = Disk({ 'login': '******', 'auth': self.token, 'path': '/root', 'start': True, 'ro': False, 'ow': False, 'exclude': ['excluded_folder'] }) sleep(2) self.assertTrue(self.disk.status == 'fault') self.assertEqual(self.disk.exit(), 0)
def getDisks(self): """ Enumerate all the disks present on the system, updating the cmdb object accordingly Create a disk instance for each disk on the system, populate the attributes and add it to the cmdb's hardDisks collection @return: cmdb.hardDisks """ disks = j.cloud.cmdtools.inventoryScan.getDisks() currentAvailableDisks = list() for name, value in disks.iteritems(): size = int(float(value['size']) * 1024) if value['unit'] == 'GB' else int( float(value['size'])) partitions = value['partitions'] currentAvailableDisks.append(name) if name in self.cmdb.disks.keys(): self.cmdb.disks[name].name = name self.cmdb.disks[name].size = size else: disk = Disk() disk.name = name disk.size = size self.cmdb.disks[name] = disk if partitions: disk = self.cmdb.disks[name] disk.partitions = list() for part in partitions: partition = Partition( part['Type'], part['number'], part['start'], part['end'], int(float(part['size'][0:-3])), part['mountpoint'] if 'mountpoint' in part else '', part['used'] if 'used' in part else 0.0, part['name'] if 'name' in part else '', part['flag'] if 'flag' in part else '') if 'devices' in part: partition.raid = PartitionRaid( part['level'], part['state'], part['devices'], part['activeDevices'], part['failedDevices'], part['totalDevices'], part['raidDevices'], part['spareDevices'], part['backendsize']) disk.partitions.append(partition) for disk in self.cmdb.disks.keys(): if disk not in currentAvailableDisks: del self.cmdb.disks[disk] self.cmdb.dirtyProperties.add('disks') return disks
def reconstruct_disk(self, disk_num): print("Reconstructing Disk") if (self.num_disks - len(self.disks)) > 1: raise DiskReconstructException( "Cannot reconstruct disk: too many disks missing") new_disk = Disk(disk_num, self.disk_cap) for i in range(len(self.disks[0])): block = [] for j in range(len(self.disks)): block.append(self.disks[j].read(i)) self.validate_parity( block + [format(self.calculate_parity(block), bin_format)]) new_disk.write(format(self.calculate_parity(block), bin_format)) self.disks.insert(disk_num, new_disk) self.validate_disks()
def gauss(): """ The driver for the generator based implementation """ from Disk import Disk from Mersenne import Mersenne # inputs N = 10**5 box = [(0, 1), (0, 1)] # the point cloud cloud = Mersenne() # the region of integration disk = Disk(center=(0, 0), radius=1) # the integration algorithm # build the point sample sample = cloud.points(N, box) # count the interior points interior = count(disk.interior(sample)) # print the estimate of π print("π: {:.8f}".format(4 * interior / N)) return
def gauss(): """ The driver for the object oriented solution """ from Disk import Disk from Mersenne import Mersenne # inputs N = 10**5 box = [(0, 1), (0, 1)] # the point cloud generator cloud = Mersenne() # the region of integration disk = Disk(center=(0, 0), radius=1) # the integration algorithm interior = 0 for i in range(N): point = cloud.point(box) if disk.interior(point): interior += 1 # print the estimate of π print("π: {:.8f}".format(4 * interior / N)) return
import sys from Disk import Disk from Simple_Filesystem import Simple_Filesystem disk = Disk(10000) fs = Simple_Filesystem(disk) no_args = len(sys.argv) image_name = sys.argv[1] command = sys.argv[2] if command == "mkdisk": fs.format() disk.save(image_name) elif command == "mkfile": disk.load(image_name) fs.create_file(sys.argv[3]) disk.save(image_name) elif command == "list": disk.load(image_name) number_of_files, files = fs.get_files() print('%d file(s)' % number_of_files) for filename in files.keys(): print(filename) elif command in 'remove': filename = sys.argv[3] disk.load(image_name) number_of_files, files = fs.get_files() if filename in files: fs.delete_file(files[filename]) else:
def __init__(self, num_disks, disk_cap=0): self.num_disks = num_disks self.disk_cap = disk_cap for i in range(num_disks): self.disks.append(Disk(i, disk_cap))
from Disk import Disk from Loader import Loader try: disk = Disk() loader = Loader() # for index in disk.memory: # print(index) except Exception as ex: print(ex.args)
confHome = expanduser(path_join('~', '.config', appName)) config = Config(path_join(confHome, 'client.conf')) if not config.loaded: makedirs(confHome, exist_ok=True) config.changed = True config.setdefault('type', 'std') config.setdefault('disks', {}) if config.changed: config.save() # Setup localization translation(appName, '/usr/share/locale', fallback=True).install() disks = [] while True: for user in config['disks'].values(): disks.append(Disk(user)) if disks: break else: from OAuth import getToken, getLogin print(_('No accounts configured')) if input(_('Do you want to configure new account (Y/n):')).lower( ) not in ('', 'y'): appExit(_('Exit.')) else: while True: path = '' while not pathExists(path): path = input( _('Enter the path to local folder ' 'which will by synchronized with cloud disk. (Default: ~/YandexDisk):'