def main(): init() if not gloval.get_outflag(): if reboot.inreboot() == 0: for dev in gloval.get_devices(): Flash(dev).pre_flash() reboot.wrcounter(0) else: count = reboot.rdcounter() if count != 1: ver_compare(count) cycle = str((count + 1) // 2) + '-' + str((count + 1) % 2) flash_devs(cycle) cyclelog_compare(count) os.system('ipmitool sel clear') power_ctl() else: count = 1 while count <= gloval.get_loops() * 2: os.system('ipmitool -H {ip} -U {username} -P {password} sel clear'. format(ip=gloval.get_ip(), username=gloval.get_username(), password=gloval.get_password())) cycle = str((count + 1) // 2) + '-' + str((count + 1) % 2) flash_devs(cycle) power_ctl() wait_sys_up() ver_compare(count) cyclelog_compare(count) count += 1
def main(): # 別のファイルのグローバル変数の初期化 lib.init() # グローバル変数のそのファイル内での呼び出し lib.put() # 今回の使い方 lib.init_mat() lib.put_mat()
def OnNew(self, e): """ File->New creates a new package """ path = self.GetDir() if not path: return os.chdir(path) try: lib.init(False) self.OnOpen(None, False) except: wx.MessageBox("An error occurred creating the project.\n" \ "Make sure a package does not already exist in that folder.", "Error creating project", wx.ICON_WARNING)
def main(): parser = argparse.ArgumentParser('Upload photos to Flickr') add_common_options(parser) args = parser.parse_args() logging.basicConfig(level=logging.DEBUG if args.debug else logging.INFO) init(args.api_key, args.api_secret) album = read_dat('album.dat') photo_data = read_dat('photos.dat') logging.debug('Will upload {0} photos to set: {1}'.format(len(photo_data), album.title)) photos = upload_photos(file_generator(photo_data)) photoset = create_set(photos, title=album.title, description=album.description)
def main(): parser = argparse.ArgumentParser('Upload photos to Flickr') add_common_options(parser) args = parser.parse_args() logging.basicConfig(level=logging.DEBUG if args.debug else logging.INFO) init(args.api_key, args.api_secret) album = read_dat('album.dat') photo_data = read_dat('photos.dat') logging.debug('Will upload {0} photos to set: {1}'.format( len(photo_data), album.title)) photos = upload_photos(file_generator(photo_data)) photoset = create_set(photos, title=album.title, description=album.description)
def regGlobal(): global kb global options global logger global print kb = AttribDict() options = init() logger = Logger() print = ColorPrint()
def main(): parser = argparse.ArgumentParser('Upload photos to Flickr') add_common_options(parser) parser.add_argument('-f', '--description_file', type=str, help='optional description file with photo titles') parser.add_argument('file', nargs='+', help='file(s) to upload') args = parser.parse_args() logging.basicConfig(level=logging.DEBUG if args.debug else logging.INFO) init(args.api_key, args.api_secret) descr = None if args.description_file: descr = load_description_file(args.description_file) photos = upload_photos(file_generator(args.file, descr)) set_name = descr.get('set_name') if set_name: create_set(photos, title=set_name)
#!/usr/bin/env python2.7 import os import lib env = lib.init() unsaved = lib.output(["find", env.project_root, "-name", ".#*"]) if len(unsaved.strip()) > 0: print("Error: Unsaved files") print unsaved exit(1)
import subprocess import time import lib def command(server: lib.Proto, command: str, check: bool = False): logging.info(f"Sending command to the server: {command!r}") response = server.command(command) logging.info(f"Got response: {response!r}") if check and response != "OK": logging.fatal("Got an unexpecting response from the server") exit(1) lib.init("client") parser = argparse.ArgumentParser(description="PTD client") # fmt: off parser.add_argument("-c", "--config", metavar="FILE", type=str, help=""" Client configuration file path. Note that the same options could be configured through the command line. """) parser.add_argument("-p", "--serverPort", metavar="PORT",
import sys import os sys.path.append(os.path.split(os.path.realpath(__file__))[0]) import lib import arch import context import msg import option import util from handler import handler lib.init() arch.init() __version__ = lib.version()
#!/usr/bin/env python3 from pywebostv.controls import SystemControl from lib import init client = init() system = SystemControl(client) system.notify("Powering down", block=True) system.power_off() # off.py ends here
self._last_log = read_log(self._config.ptd_logfile, f"{self._mode}-{self._mark}") self._mode = None self._mark = None return "OK" if cmd[0] == "get-last-log": return "base64 " + base64.b64encode( self._last_log.encode()).decode() if cmd[0] == "get-log": with open(self._config.ptd_logfile, "rb") as f: data = f.read() return "base64 " + base64.b64encode(data).decode() return "Error: unknown command" lib.init("ptd-server") parser = argparse.ArgumentParser( description="Server for communication with PTD") # fmt: off parser.add_argument("-p", "--serverPort", metavar="PORT", type=int, help="Server port", default=4950) parser.add_argument("-i", "--ipAddress", metavar="IP", type=str,
def create_table(comp, dep1_s, dep2_s): global tab_folder print "Component " + comp AC_BITS = 10 table_folder = tab_folder + "/" + str(comp) os.system("mkdir " + table_folder) lib.index_file = open(table_folder + "/index.txt", "w") lib.init(comp, in_folder, tab_folder, dep1_s, dep2_s) lib.dep1, SIZE1 = lib.parse_dep(dep1_s, lib.apc_bins) lib.dep2, SIZE2 = lib.parse_dep(dep2_s, lib.apc_bins) #id_str = sys.argv[1] +"_" + comp + "_" + images_s + "_" + images_e + "[" + str(dep1) + "," + str(dep2) + "]" # get SIZE1_length code based on learning set co = {} #co for code oc = {} #oc for occur, then becomes difference oc_default = {} co_default = {} pos = 1 l_total_bits = 0 l_run_length_bits = 0 l_dc_s = 0 l_dc_b = 0 l_ac_b = 0 for i in range(1, 64): co[i] = {} oc[i] = {} for p in range(SIZE1 + 1): oc[i][p] = {} co[i][p] = {} for pp in range(SIZE2 + 1): oc[i][p][pp] = {} # positive sign for z in range(16): for b in range(1, AC_BITS + 1): oc[i][p][pp][(z<<4) + b] = 0 oc[i][p][pp][(z<<4)+15] = 0 # for +-7, independantly oc[i][p][pp][(z<<4)+14] = 0 # for +-6, independantly oc[i][p][pp][(z<<4)+13] = 0 # for +-5, independantly oc[i][p][pp][(z<<4)+12] = 0 # for +-3, independantly oc[i][p][pp][0] = 0 # 0 for EOB oc[i][p][pp][0xf0] = 0 # negative sign for z in range(16): for b in range(1, AC_BITS + 1): oc[i][p][pp][(1<<8)+(z<<4) + b] = 0 oc[i][p][pp][(1<<8)+(z<<4)+15] = 0 # for +-7, independantly oc[i][p][pp][(1<<8)+(z<<4)+14] = 0 # for +-6, independantly oc[i][p][pp][(1<<8)+(z<<4)+13] = 0 # for +-5, independantly oc[i][p][pp][(1<<8)+(z<<4)+12] = 0 # for +-3, independantly oc[i][p][pp][(1<<8)+0] = 0 # 0 for EOB oc[i][p][pp][(1<<8)+0xf0] = 0 for z in range(16): for b in range(1, AC_BITS + 1): oc_default[(z<<4) + b] = 0 oc_default[(z<<4)+15] = 0 # for +-7, independantly oc_default[(z<<4)+14] = 0 # for +-6, independantly oc_default[(z<<4)+13] = 0 # for +-5, independantly oc_default[(z<<4)+12] = 0 # for +-3, independantly oc_default[0] = 0 # 0 for EOB oc_default[0xf0] = 0 # negative sign for z in range(16): for b in range(1, AC_BITS + 1): oc_default[(1<<8)+(z<<4) + b] = 0 oc_default[(1<<8)+(z<<4)+15] = 0 # for +-7, independantly oc_default[(1<<8)+(z<<4)+14] = 0 # for +-6, independantly oc_default[(1<<8)+(z<<4)+13] = 0 # for +-5, independantly oc_default[(1<<8)+(z<<4)+12] = 0 # for +-3, independantly oc_default[(1<<8)+0] = 0 # 0 for EOB oc_default[(1<<8)+0xf0] = 0 oc_dc = {} co_dc = {} oc_default_dc = {} co_default_dc = {} for i in range(36): oc_dc[i] = {} for j in range(23): oc_dc[i][j] = 0 for j in range(23): oc_default_dc[j] = 0 files = glob.glob(in_folder + "/*.block") ratio = 0 print "\tTraining: " print "\t", for f in files: ratio += 1 print str(ratio*100/len(files)) + "%", sys.stdout.flush() block = lib.get_blocks_all_in_bits(f, comp) block_o = lib.get_blocks_with_dc_in_diff(f, comp) for ii in range(len(block)): x, dc_s_bits, dc_bits, r, coef_bits = lib.get_bits_detail(block[ii], lib.code, comp=="0") l_ac_b += coef_bits l_run_length_bits += r l_dc_s += dc_s_bits l_dc_b += dc_bits l_total_bits += x # for dc symbol: b = block[ii] b_o = block_o[ii] dc_de = lib.get_dc_dependency(block_o, block, ii) dc_diff = b_o[0] dc_diff_bits = b[0] if dc_diff < 0: dc_diff_bits = -dc_diff_bits oc_dc[dc_de][dc_diff_bits+11] += 1 #oc_dc[lib.get_previous_block(block, ii) [0]][b[0]] += 1 #oc_dc[lib.get_previous_blocks_coef_for_DC(block, ii)][b[0]] += 1 r = 0 pos = 1 for i in range(1, 64): if b[i] == 0: r += 1 continue while (r > 15): lib.record_code(block, block_o, ii, 0xf0, pos, pos + 15, oc, 0, 0) pos += 16 r -= 16 offset = 0 if b_o[i] < 0: offset = (1<<8) if b[i]==2: if abs(b_o[i])==3: lib.record_code(block, block_o, ii, offset+(r << 4) + 12, pos, i, oc, 0, 0) else: lib.record_code(block, block_o, ii, offset+(r << 4) + b[i], pos, i, oc, 0, 0) elif b[i]==3: if abs(b_o[i])==5: lib.record_code(block, block_o, ii, offset+(r << 4) + 13, pos, i, oc, 0, 0) elif abs(b_o[i])==6: lib.record_code(block, block_o, ii, offset+(r << 4) + 14, pos, i, oc, 0, 0) elif abs(b_o[i])==7: lib.record_code(block, block_o, ii, offset+(r << 4) + 15, pos, i, oc, 0, 0) else: lib.record_code(block, block_o, ii, offset+(r << 4) + b[i], pos, i, oc, 0, 0) else: lib.record_code(block, block_o, ii, offset+(r << 4) + b[i], pos, i, oc, 0, 0) pos = i + 1 r = 0 if r > 0: lib.record_code(block, block_o, ii, 0, pos, 63, oc, 0, 0) if l_dc_s + l_dc_b + l_run_length_bits + l_ac_b != l_total_bits: lib.fprint("train set not equal") lib.fprint("TRAIN SET:\tdc symbol length:" + str(l_dc_s) + "\tdc actual bits:" + str(l_dc_b) + "\trun length bits:" + str(l_run_length_bits) + "\tactual AC bits:" + str(l_ac_b) + "\ttotal bits:" + str(l_total_bits)) lib.fprint("generating DC tables...") for i in range(36): if comp == '0': co_dc[i] = lib.huff_encode_plus_extra_better_DC(oc_dc[i], lib.bits_dc_luminance) else: co_dc[i] = lib.huff_encode_plus_extra_better_DC(oc_dc[i], lib.bits_dc_chrominance) save_code_table(co_dc[i], oc_dc[i], "DC", i, "", table_folder) for x in oc_dc[i]: oc_default_dc[x] += oc_dc[i][x] co_default_dc = lib.huff_encode_plus_extra_better_DC(oc_default_dc, lib.bits_dc_luminance) save_code_table(co_default_dc, oc_default_dc, "DC", 100, "", table_folder) lib.fprint("generating AC tables...") max_len = -1 for i in range(1, 64): #print i for p in range(SIZE1 + 1): for pp in range(SIZE2 + 1): co[i][p][pp], max_len_ = lib.huff_encode_plus_extra_all(oc[i][p][pp], lib.code) save_code_table(co[i][p][pp], oc[i][p][pp], i, p, pp, table_folder) if max_len_ > max_len: max_len = max_len_ for x in oc[i][p][pp]: oc_default[x] += oc[i][p][pp][x] co_default, max_len_ = lib.huff_encode_plus_extra_all(oc_default, lib.code) lib.fprint("default table max: " +str(max_len_)) save_code_table(co_default, oc_default, 100,100,100,table_folder) lib.fprint("max length symbols: %d"%(max_len)) lib.index_file.close() print "\n\tTraining DONE"
def main(argv): """ Main function of execution """ opts, args = parse(argv) # Setup logging logging.basicConfig(level=opts.verbose, format=LOG_FORMAT, datefmt=DATE) # Change dir if necessary if opts.folder: if not os.path.exists(opts.folder): logging.info('Creating non-existant directory: %s' % opts.folder) os.mkdir(opts.folder) os.chdir(opts.folder) # Start parsing arguments if len(args) == 0: # try: if 1: import frontend app = frontend.CreatorApp(0) app.MainLoop() return elif args[0].lower() == 'init': lib.init(opts.overwrite) sys.exit() elif len(args) < 2 or (args[0] == 'set' and len(args) < 3): parse(['--help']) # Parse e = Package() if os.path.exists(wpkg.package.INFO_FILENAME): try: e.from_file(wpkg.package.INFO_FILENAME) except: pass else: print os.getcwd() raise IOError, 'info.xml does not exist' # Convert parameters to variable names args[1] = args[1].replace('-','_') args[0] = args[0].lower() for i in range(0,len(args)): args[i] = args[i].replace('\\n','\n') # Set the values if args[0] == 'show': x = e.get_property(args[1])#.to_string() if isinstance(x, List): # Received a list if x == []: print None else: print x else: # Just a string print x elif args[0] == 'clear': if isinstance(e.get_property(args[1]), List): e.set_property(args[1], []) else: e.set_property(args[1], '') e.write() elif args[0] == 'set': x = e.get_property(args[1])#.to_string() if isinstance(x, PackageList): x.clear() for package in ''.join(args[2:]).split(';'): name, version = package.split(',') pkg = PackageShort(name, version) x.append(pkg) elif isinstance(e.get_property(args[1]), List): e.set_property(args[1], args[2:]) else: e.set_property(args[1], ' '.join(args[2:])) e.write() # Write the package info.xml file elif args[0] == 'append': e.append_property(args[1], args[2:]) e.write() elif args[0] == 'script': lib.set_script(args[1], args[2], opts.overwrite)
#!/usr/bin/env pthon2 # -*- coding: utf-8 -*- # Version Python 2.7.* import os, sys, subprocess, time from lib import Fore, Back, Style, init subprocess.call("clear && clear", shell=True) nodir = open("exclude","r") exc = nodir.read() nodir.close() init(autoreset=True) data = (time.strftime("%d_%m_%Y")) directory = "$(pwd)" id1 = os.system ("grep -wom1 'sudo' $HOME/.bash_history > id") file = open("id", "r") root1 = file.read(4 - 0) if os.stat("id").st_size == 0: id2 = os.system ("grep -wom1 'su' $HOME/.bash_history > id") file = open("id", "r") root2 = file.read(4 - 0) print print (Fore.GREEN + " ______ ____ ____ __ ___ ____ __ __ _____ ______ __ __ ") print (Fore.GREEN + " (_ _ \ ( ) / ___)() ) / __)/ __ \ ) ) ( ( / ___/( __ \) \ / ( ")