def run(self): try: self.node.set_log_level(self.level, self.class_name) except common.ArgumentError as e: print_(str(e), file=sys.stderr) exit(1)
def logprint(*args, **kwargs): """ Send a message to both stdout and the appropriate logs. This behaves like Python3's print statement, plus takes additional named parameters: :param level: the log level. This determines which log handlers will store the log message. The log is always sent to stdout. :param color: one of the constants.TerminalColor values or None. :param exc_info: None to not print exception information. True for the last exception, or a tuple of exception information. """ data = six.StringIO() kwargs = (kwargs or {}).copy() level = kwargs.pop('level', logging.DEBUG) color = kwargs.pop('color', None) exc_info = kwargs.pop('exc_info', None) kwargs['file'] = data six.print_(*args, **kwargs) data = data.getvalue().rstrip() if exc_info and not isinstance(exc_info, tuple): exc_info = sys.exc_info() data += '\n' + ''.join(traceback.format_exception(*exc_info)).rstrip() logger.log(level, data) if color: data = getattr(TerminalColor, color)(data) six.print_(data, flush=True)
def validate(self, parser, options, args): Cmd.validate(self, parser, options, args, load_cluster=True) if len(args) == 0: print_('Missing log level', file=sys.stderr) parser.print_help() exit(1) self.level = args[0]
def run(self): cmds = ["jconsole", "localhost:%s" % self.node.jmx_port] try: subprocess.call(cmds) except OSError: print_("Could not start jconsole. Please make sure jconsole can be found in your $PATH.") exit(1)
def print_help(): print_("""avaliable command: help --- show this help ls --- list friends and groups talk --- talk to friends quit --- quit program """)
def run(self): try: node = Node(self.name, self.cluster, self.options.boostrap, self.thrift, self.storage, self.jmx_port, self.remote_debug_port, self.initial_token, binary_interface=self.binary) self.cluster.add(node, self.options.is_seed, self.options.data_center) except common.ArgumentError as e: print_(str(e), file=sys.stderr) exit(1)
def validate(self, parser, options, args): Cmd.validate(self, parser, options, args, load_cluster=True) try: self.setting = common.parse_settings(args) except common.ArgumentError as e: print_(str(e), file=sys.stderr) exit(1)
def run(self, run_duration, node_state_grid=None, plot_each_transition=False, plotter=None): """ Runs the model forward for a specified period of time. Parameters ---------- run_duration : float Length of time to run node_state_grid : 1D array of ints (x number of nodes) (optional) Node states (if given, replaces model's current node state grid) plot_each_transition : bool (optional) Option to display the grid after each transition plotter : CAPlotter object (optional) Needed if caller wants to plot after every transition """ if node_state_grid is not None: self.set_node_state_grid(node_state_grid) # Continue until we've run out of either time or events while self.current_time < run_duration and self.event_queue: if _DEBUG: six.print_('Current Time = ', self.current_time) # Pick the next transition event from the event queue ev = heappop(self.event_queue) if _DEBUG: six.print_('Event:',ev.time,ev.link,ev.xn_to) self.do_transition(ev, self.current_time, plot_each_transition, plotter) # Update current time self.current_time = ev.time
def validate(self, parser, options, args): Cmd.validate(self, parser, options, args, node_name=True, load_cluster=True, load_node=False) if options.itfs is None and (options.thrift_itf is None or options.storage_itf is None or options.binary_itf is None): print_('Missing thrift and/or storage and/or binary protocol interfaces or jmx port', file=sys.stderr) parser.print_help() exit(1) if options.thrift_itf is None: options.thrift_itf = options.itfs if options.storage_itf is None: options.storage_itf = options.itfs if options.binary_itf is None: options.binary_itf = options.itfs self.thrift = common.parse_interface(options.thrift_itf, 9160) self.storage = common.parse_interface(options.storage_itf, 7000) self.binary = common.parse_interface(options.binary_itf, 9042) if self.binary[0] != self.thrift[0]: print_('Cannot set a binary address different from the thrift one', file=sys.stderr) exit(1) self.jmx_port = options.jmx_port self.remote_debug_port = options.remote_debug_port self.initial_token = options.initial_token
def get_bars(self, order_book_id, fields=None): try: s, e = self._index[order_book_id] except KeyError: six.print_(_(u"No data for {}").format(order_book_id)) return if fields is None: # the first is date fields = self._table.names[1:] if len(fields) == 1: return self._converter.convert(fields[0], self._table.cols[fields[0]][s:e]) # remove datetime if exist in fields self._remove_(fields, 'datetime') dtype = np.dtype([('datetime', np.uint64)] + [(f, self._converter.field_type(f, self._table.cols[f].dtype)) for f in fields]) result = np.empty(shape=(e - s, ), dtype=dtype) for f in fields: result[f] = self._converter.convert(f, self._table.cols[f][s:e]) result['datetime'] = self._table.cols['date'][s:e] result['datetime'] *= 1000000 return result
def build_static(self, *args, **options): """ Builds the static files directory as well as robots.txt and favicon.ico """ logger.debug("Building static directory") if self.verbosity > 1: six.print_("Building static directory") management.call_command("collectstatic", interactive=False, verbosity=0) target_dir = os.path.join(self.build_dir, settings.STATIC_URL[1:]) if os.path.exists(settings.STATIC_ROOT) and settings.STATIC_URL: if getattr(settings, "BAKERY_GZIP", False): self.copytree_and_gzip(settings.STATIC_ROOT, target_dir) # if gzip isn't enabled, just copy the tree straight over else: shutil.copytree(settings.STATIC_ROOT, target_dir) # If they exist in the static directory, copy the robots.txt # and favicon.ico files down to the root so they will work # on the live website. robot_src = os.path.join(target_dir, "robots.txt") if os.path.exists(robot_src): shutil.copy(robot_src, os.path.join(settings.BUILD_DIR, "robots.txt")) favicon_src = os.path.join(target_dir, "favicon.ico") if os.path.exists(favicon_src): shutil.copy(favicon_src, os.path.join(settings.BUILD_DIR, "favicon.ico"))
def test_task_with_distutils_dep(): _sdist.reset() @tasks.task @tasks.needs("paver.tests.test_setuputils.sdist") def sdist(): assert _sdist.called env = _set_environment(sdist=sdist) env.options = options.Bunch(setup=options.Bunch()) install_distutils_tasks() d = _get_distribution() d.cmdclass['sdist'] = _sdist task_obj = env.get_task('sdist') assert task_obj == sdist needs_obj = env.get_task(task_obj.needs[0]) assert isinstance(needs_obj, DistutilsTask) assert needs_obj.command_class == _sdist tasks._process_commands(['sdist', "-f"]) assert sdist.called assert _sdist.called cmd = d.get_command_obj('sdist') print_("Cmd is: %s" % cmd) assert cmd.foo assert _sdist.foo_set
def register(self): """Registers the workflow type and task types with SWF It is necessary to do this each time a new task is added to a workflow. It is safest to run this before each call to :meth:`execute` if you are just launching a workflow from a cron. However, if you are launching many workflows and calling :meth:`execute` many times, you may want to consider calling this method only when necessary because it can contribute to an SWF API throttling issue. """ tasks = get_task_configurations(self.workflow_task) registerables = [] registerables.append(swf.Domain(name=self.domain)) task_dats = set((t['task_family'], t['task_list']) for (t_id, t) in iteritems(tasks)) for task_dat in task_dats: registerables.append(swf.ActivityType(domain=self.domain, version=self.version, name=task_dat[0], task_list=task_dat[1])) wf_name = self.workflow_task.task_family wf_task_list = getattr(self.workflow_task, 'swf_task_list', 'default') registerables.append(swf.WorkflowType(domain=self.domain, version=self.version, name=wf_name, task_list=wf_task_list)) for swf_entity in registerables: try: swf_entity.register() print_(swf_entity.name, 'registered successfully') except (SWFDomainAlreadyExistsError, SWFTypeAlreadyExistsError): print_(swf_entity.__class__.__name__, swf_entity.name, 'already exists')
def _create(self, name, stack_id, username=None, ssh_keys=None, user_scripts=None, node_groups=None, connectors=None, wait=False): """ CLI-only; cluster create command """ if ssh_keys is None: ssh_keys = [DEFAULT_SSH_KEY] try: return self.create(name, stack_id, username, ssh_keys, user_scripts, node_groups, connectors, wait) except error.RequestError as exc: if not (ssh_keys == [DEFAULT_SSH_KEY] and 'Cannot find requested ssh_keys' in str(exc)): raise six.print_('SSH key does not exist; creating...') # Create the SSH key for the user and then attempt to create the # cluster again with open(expand('$HOME/.ssh/id_rsa.pub')) as f: self._client.credentials.create_ssh_key( DEFAULT_SSH_KEY, f.read().strip()) return self.create(name, stack_id, username, ssh_keys, user_scripts, node_groups, connectors, wait)
def findA_M0(): prefix = b"\x00" + b"\xf2" + b"\x00" * (256 - 2 - 16) c = mysrp.Client() import time start = time.time() num_near_misses = 0 for count in thencount(): if count > 300 and count % 500 == 0: now = time.time() print_(count, "tries", now - start) start = now if count > 1000000: raise ValueError("unable to find suitable value in reasonable time") a_str = prefix + binascii.unhexlify("%032x" % count) assert len(a_str) == 2048 / 8, (len(a_str), 2048 / 8) a = mysrp.bytes_to_long(a_str) A = c.one(a) # require that the computed M1 has a leading zero c.two(B, srpSalt, emailUTF8, srpPW) if c._debug_M1_bytes[0:1] != b"\x00": continue print_("found a on count", count) printdec("private a (normally random)", a) printhex("private a (hex)", a_str, groups_per_line=2) return a, A
def processLine(self, line, result, verbose): if all([p.match(line) for p in self.patterns]): if len(result.expectedLines) > 0: # we have matched line in the output and at least one remaining unmatched in a baseline expected = result.expectedLines[0] # running comparison logic for each pattern failedPatterns = [] for p in self.patterns: if not p.compare(expected, line): result.succeeded = False failedPatterns.append(p) # in the case of failure - reporting mismatched lines if len(failedPatterns)>0: result.diagnostics+=("Baseline: {0}\n"+ "Output: {1}\n" ).format(expected, line) if verbose: six.print_("[FAILED]: Testcase " + self.name) six.print_("Baseline: " + expected) # also show all failed patterns for p in failedPatterns: msg = "Failed pattern: " + p.patternText if verbose: print (msg) result.diagnostics+=msg+"\n" # removing this line, since we already matched it (whether successfully or not - doesn't matter) del result.expectedLines[0] else: # we have matched line in the output - but don't have any remaining unmatched in a baseline result.succeeded = False result.diagnostics+=("Unexpected (extra) line in the output which matches the pattern, but doesn't appear in baseline file.\n"+ "Extra line: {0}" ).format(line)
def __init__(self, ncpus="autodetect", interface="0.0.0.0", broadcast="255.255.255.255", port=None, secret=None, timeout=None, restart=False, proto=2, socket_timeout=3600, pid_file=None): pp.Server.__init__(self, ncpus, (), secret, restart, proto, socket_timeout) if pid_file: with open(pid_file, 'w') as pfile: six.print_(os.getpid(), file=pfile) atexit.register(os.remove, pid_file) self.host = interface self.bcast = broadcast if port is not None: self.port = port else: self.port = ppc.randomport() self.timeout = timeout self.ncon = 0 self.last_con_time = time.time() self.ncon_lock = threading.Lock() self.logger.debug("Strarting network server interface=%s port=%i" % (self.host, self.port)) if self.timeout is not None: self.logger.debug("ppserver will exit in %i seconds if no "\ "connections with clients exist" % (self.timeout)) ppc.start_thread("timeout_check", self.check_timeout)
def print_action(func, *args, **kwargs): if hasattr(func, 'display'): func.display(func.__self__, *args, **kwargs) else: result = func(*args, **kwargs) if result is not None: six.print_(result)
def stress(self, stress_options): stress = common.get_stress_bin(self.get_install_dir()) livenodes = [node.network_interfaces['storage'][0] for node in list(self.nodes.values()) if node.is_live()] if len(livenodes) == 0: print_("No live node") return nodes_options = [] if self.cassandra_version() <= '2.1': if '-d' not in stress_options: nodes_options = ['-d', ",".join(livenodes)] args = [stress] + nodes_options + stress_options else: if '-node' not in stress_options: nodes_options = ['-node', ','.join(livenodes)] args = [stress] + stress_options + nodes_options rc = None try: # need to set working directory for env on Windows if common.is_win(): rc = subprocess.call(args, cwd=common.parse_path(stress)) else: rc = subprocess.call(args) except KeyboardInterrupt: pass return rc
def output_profile_result(env): stdout_trap = six.StringIO() env.profile_deco.print_stats(stdout_trap) profile_output = stdout_trap.getvalue() profile_output = profile_output.rstrip() six.print_(profile_output) env.event_bus.publish_event(Event(EVENT.ON_LINE_PROFILER_RESULT, result=profile_output))
def __init__(self, username, password, proxy=None, parser=DEFAULT_PARSER, ignorefiles=None, max_path_part_len=None, gzip_courses=False, wk_filter=None): self.username = username self.password = password self.parser = parser # Split "ignorefiles" argument on commas, strip, remove prefixing dot # if there is one, and filter out empty tokens. self.ignorefiles = [x.strip()[1:] if x[0] == '.' else x.strip() for x in ignorefiles.split(',') if len(x)] self.session = None self.proxy = proxy self.max_path_part_len = max_path_part_len self.gzip_courses = gzip_courses try: self.wk_filter = map( int, wk_filter.split(",")) if wk_filter else None except Exception as e: print_("Invalid week filter, should be a comma separated list of integers", e) exit()
def on_search(args): # TODO: Decode via actual tty encoding try: q = args.q[0].decode("utf-8") except AttributeError: q = args.q[0] pkg_names = set() # First, check for exact case-insensitive name matches for pkg in session.query(Package).filter(collate(Package.name,"NOCASE")==q).all(): pkg_names.add(pkg.name) # Check for substring name matches for pkg in session.query(Package).filter(Package.name.like(u('%{0}%').format(q))).all(): pkg_names.add(pkg.name) # Check for description matches for pkg in session.query(Package).filter(Package.description.like(u('%{0}%').format(q))).all(): pkg_names.add(pkg.name) if len(pkg_names) == 0: print_(u('No matching packages found.')) return # Nice column formatting max_len_name = max( len(name) for name in pkg_names ) for pkg_name in sorted(pkg_names): pkg = session.query(Package).get(pkg_name) print_(u('{name:{max_len_name}} {version:10} {desc}'.format(name=pkg.name, version=pkg.version, desc=pkg.description, max_len_name=max_len_name)))
def print_result(self, result): if self.args.get('format') is None: stylesheet = self.args.get('stylesheet') show_conn_info = bool(stylesheet) elif self.args.get('format') == 'none': stylesheet = None show_conn_info = False elif self.args.get('format') == 'xml': stylesheet = None show_conn_info = True else: stylesheet = self.args.get('stylesheet') if not stylesheet: stylesheet = self.config.get_region_option('vpn-stylesheet') if stylesheet: stylesheet = stylesheet.format(format=self.args['format']) else: self.log.warn('current region has no stylesheet') msg = ('current region has no XSLT stylesheet to format ' 'output; connection info will not be shown (try ' 'specifying one with "--stylesheet" or using ' '"--format xml")') six.print_(msg, file=sys.stderr) show_conn_info = bool(stylesheet) for vpn in result.get('vpnConnectionSet', []): self.print_vpn_connection(vpn, show_conn_info=show_conn_info, stylesheet=stylesheet)
def run(self): try: common.invalidate_cache() except Exception as e: print_(str(e), file=sys.stderr) print_("Error while deleting cache. Please attempt manually.") exit(1)
def run(self): try: profile_options = None if self.options.profile: profile_options = {} if self.options.profile_options: profile_options["options"] = self.options.profile_options if len(self.cluster.nodes) == 0: print_("No node in this cluster yet. Use the populate command before starting.") exit(1) if ( self.cluster.start( no_wait=self.options.no_wait, wait_other_notice=self.options.wait_other_notice, wait_for_binary_proto=self.options.wait_for_binary_proto, verbose=self.options.verbose, jvm_args=self.options.jvm_args, profile_options=profile_options, ) is None ): details = "" if not self.options.verbose: details = " (you can use --verbose for more information)" print_("Error starting nodes, see above for details%s" % details, file=sys.stderr) exit(1) except NodeError as e: print_(str(e), file=sys.stderr) print_("Standard error output is:", file=sys.stderr) for line in e.process.stderr: print_(line.rstrip("\n"), file=sys.stderr) exit(1)
def start(self): """ Start the monitor """ if CURSES_SUPPORTED: curses.wrapper(self.run) else: six.print_("Your system does not have curses installed. " "Cannot use 'watch'")
def n_mult(a,b): if isinstance(a,N_polynomial) and isinstance(b,N_polynomial): total={} for keya in a.terms_: for keyb in b.terms_: m = prodMonomials(keya,keyb) coeff=a.terms_[keya]*b.terms_[keyb] if m in total: newc = coeff + total[m] if newc==0: del total[m] else: total[m]=newc else: total[m]=coeff return N_polynomial(n_ar=total) if isinstance(a,N_constantNum) and isinstance(b,N_polynomial): # print "multiplyBy ", a.a if(a.num_==1): return b out=b.copy() out.scalarMultiply(a.num_) return out if isinstance(a,N_constantNum) and isinstance(b,N_constantNum): return N_constantNum(a.num_*b.num_) print_(a, b) raise NotImplementedError()
def showStats( self ): '''Shows a few stats on standard output. Shouldn't be called before buildGraph(). ''' if self.numInputSentences > 0: six.print_( "Character " + self.charLabel + " has a total of " + str( self.numInputWords ) + " words over " + str( self.numInputSentences ) + " sentences for an average of " + str( self.numInputWords / self.numInputSentences ) + " words/sentence.") else: six.print_( "Character " + self.charLabel + " has a total of " + str( self.numInputWords ) + " words." )
def run_cqlsh(self, cmds=None, show_output=False, cqlsh_options=[]): cdir = self.get_cassandra_dir() cli = common.join_bin(cdir, 'bin', 'cqlsh') env = common.make_cassandra_env(cdir, self.get_path()) host = self.network_interfaces['thrift'][0] port = self.network_interfaces['thrift'][1] args = cqlsh_options + [ host, str(port) ] sys.stdout.flush() if cmds is None: os.execve(cli, [ common.platform_binary('cqlsh') ] + args, env) else: p = subprocess.Popen([ cli ] + args, env=env, stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE) for cmd in cmds.split(';'): p.stdin.write(cmd + ';\n') p.stdin.write("quit;\n") p.wait() for err in p.stderr: print_("(EE) ", err, end='') if show_output: i = 0 for log in p.stdout: # first four lines are not interesting if i >= 4: print_(log, end='') i = i + 1
def on_show(args): for pkg_name in args.package_names: if six.PY2: pkg_name = pkg_name.decode("utf-8") pkg = session.query(Package).get(pkg_name) if pkg: print_(u('{name}\t{version}\t{desc}'.format(name=pkg.name, version=pkg.version, desc=pkg.description)))
def run(self): try: self.cluster.update_log4j(self.log4jpath) except common.ArgumentError as e: print_(str(e), file=sys.stderr) exit(1)
def run_pipeline(print_algo=True, **kwargs): """Runs a full zipline pipeline given configuration keyword arguments. 1. Load data (start and end dates can be provided a strings as well as the source and symobls). 2. Instantiate algorithm (supply either algo_text or algofile kwargs containing initialize() and handle_data() functions). If algofile is supplied, will try to look for algofile_analyze.py and append it. 3. Run algorithm (supply capital_base as float). 4. Return performance dataframe. :Arguments: * print_algo : bool <default=True> Whether to print the algorithm to command line. Will use pygments syntax coloring if pygments is found. """ start = pd.Timestamp(kwargs['start'], tz='UTC') end = pd.Timestamp(kwargs['end'], tz='UTC') symbols = kwargs['symbols'].split(',') if kwargs['source'] == 'yahoo': source = zipline.data.load_bars_from_yahoo(stocks=symbols, start=start, end=end) else: raise NotImplementedError('Source %s not implemented.' % kwargs['source']) algo_text = kwargs.get('algo_text', None) if algo_text is None: # Expect algofile to be set algo_fname = kwargs['algofile'] with open(algo_fname, 'r') as fd: algo_text = fd.read() analyze_fname = os.path.splitext(algo_fname)[0] + '_analyze.py' if os.path.exists(analyze_fname): with open(analyze_fname, 'r') as fd: # Simply append algo_text += fd.read() if print_algo: if PYGMENTS: highlight(algo_text, PythonLexer(), TerminalFormatter(), outfile=sys.stdout) else: print_(algo_text) algo = zipline.TradingAlgorithm(script=algo_text, namespace=kwargs.get('namespace', {}), capital_base=float(kwargs['capital_base'])) perf = algo.run(source) output_fname = kwargs.get('output', None) if output_fname is not None: perf.to_pickle(output_fname) return perf
def clone_development(git_repo, version, verbose=False, alias=False): print_(git_repo, version) target_dir = directory_name(version) assert target_dir if 'github' in version: git_repo_name, git_branch = github_username_and_branch_name(version) elif 'local:' in version: git_repo_name = 'local_{}'.format(git_repo) # add git repo location to distinguish cache location for differing repos git_branch = version.split(':')[-1] # last token on 'local:...' slugs should always be branch name elif alias: git_repo_name = 'alias_{}'.format(version.split('/')[0].split(':')[-1]) git_branch = version.split('/')[-1] else: git_repo_name = 'apache' git_branch = version.split(':', 1)[1] local_git_cache = os.path.join(__get_dir(), '_git_cache_' + git_repo_name) logfile = lastlogfilename() logger = get_logger(logfile) try: # Checkout/fetch a local repository cache to reduce the number of # remote fetches we need to perform: if not os.path.exists(local_git_cache): common.info("Cloning Cassandra...") process = subprocess.Popen( ['git', 'clone', '--mirror', git_repo, local_git_cache], cwd=__get_dir(), stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, _, _ = log_info(process, logger) assert out == 0, "Could not do a git clone" else: common.info("Fetching Cassandra updates...") process = subprocess.Popen( ['git', 'fetch', '-fup', 'origin', '+refs/*:refs/*'], cwd=local_git_cache, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, _, _ = log_info(process, logger) assert out == 0, "Could not update git" # Checkout the version we want from the local cache: if not os.path.exists(target_dir): # development branch doesn't exist. Check it out. common.info("Cloning Cassandra (from local cache)") # git on cygwin appears to be adding `cwd` to the commands which is breaking clone if sys.platform == "cygwin": local_split = local_git_cache.split(os.sep) target_split = target_dir.split(os.sep) process = subprocess.Popen( ['git', 'clone', local_split[-1], target_split[-1]], cwd=__get_dir(), stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, _, _ = log_info(process, logger) assert out == 0, "Could not do a git clone" else: process = subprocess.Popen( ['git', 'clone', local_git_cache, target_dir], cwd=__get_dir(), stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, _, _ = log_info(process, logger) assert out == 0, "Could not do a git clone" # determine if the request is for a branch is_branch = False try: branch_listing = subprocess.check_output(['git', 'branch', '--all'], cwd=target_dir).decode('utf-8') branches = [b.strip() for b in branch_listing.replace('remotes/origin/', '').split()] is_branch = git_branch in branches except subprocess.CalledProcessError as cpe: common.error("Error Running Branch Filter: {}\nAssumming request is not for a branch".format(cpe.output)) # now check out the right version branch_or_sha_tag = 'branch' if is_branch else 'SHA/tag' common.info("Checking out requested {} ({})".format(branch_or_sha_tag, git_branch)) if is_branch: # we use checkout -B with --track so we can specify that we want to track a specific branch # otherwise, you get errors on branch names that are also valid SHAs or SHA shortcuts, like 10360 # we use -B instead of -b so we reset branches that already exist and create a new one otherwise process = subprocess.Popen(['git', 'checkout', '-B', git_branch, '--track', 'origin/{git_branch}'.format(git_branch=git_branch)], cwd=target_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, _, _ = log_info(process, logger) else: process = subprocess.Popen( ['git', 'checkout', git_branch], cwd=target_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, _, _ = log_info(process, logger) if int(out) != 0: raise CCMError('Could not check out git branch {branch}. ' 'Is this a valid branch name? (see {lastlog} or run ' '"ccm showlastlog" for details)'.format( branch=git_branch, lastlog=logfile )) # now compile compile_version(git_branch, target_dir, verbose) else: # branch is already checked out. See if it is behind and recompile if needed. process = subprocess.Popen( ['git', 'fetch', 'origin'], cwd=target_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, _, _ = log_info(process, logger) assert out == 0, "Could not do a git fetch" process = subprocess.Popen(['git', 'status', '-sb'], cwd=target_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) _, status, _ = log_info(process, logger) if str(status).find('[behind') > -1: # If `status` looks like '## cassandra-2.2...origin/cassandra-2.2 [behind 9]\n' common.info("Branch is behind, recompiling") process = subprocess.Popen(['git', 'pull'], cwd=target_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, _, _ = log_info(process, logger) assert out == 0, "Could not do a git pull" process = subprocess.Popen([platform_binary('ant'), 'realclean'], cwd=target_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, _, _ = log_info(process, logger) assert out == 0, "Could not run 'ant realclean'" # now compile compile_version(git_branch, target_dir, verbose) elif re.search('\[.*?(ahead|behind).*?\]', status.decode("utf-8")) is not None: # status looks like '## trunk...origin/trunk [ahead 1, behind 29]\n' # If we have diverged in a way that fast-forward merging cannot solve, raise an exception so the cache is wiped common.error("Could not ascertain branch status, please resolve manually.") raise Exception else: # status looks like '## cassandra-2.2...origin/cassandra-2.2\n' common.debug("Branch up to date, not pulling.") except Exception as e: # wipe out the directory if anything goes wrong. Otherwise we will assume it has been compiled the next time it runs. try: rmdirs(target_dir) common.error("Deleted {} due to error".format(target_dir)) except: print_('Building C* version {version} failed. Attempted to delete {target_dir}' 'but failed. This will need to be manually deleted'.format( version=version, target_dir=target_dir )) finally: raise e
def run(self): try: self.cluster.stress(self.stress_options) except Exception as e: print_(e, file=sys.stderr)
def run(self): l = [ node.network_interfaces['storage'][0] for node in list(self.cluster.nodes.values()) if node.is_live() ] print_(",".join(l))
def run(self): try: if self.options.dse or (not self.options.version and common.isDse( self.options.install_dir)): cluster = DseCluster(self.path, self.name, install_dir=self.options.install_dir, version=self.options.version, dse_username=self.options.dse_username, dse_password=self.options.dse_password, opscenter=self.options.opscenter, verbose=True) else: cluster = Cluster(self.path, self.name, install_dir=self.options.install_dir, version=self.options.version, verbose=True) except OSError as e: cluster_dir = os.path.join(self.path, self.name) import traceback print_('Cannot create cluster: %s\n%s' % (str(e), traceback.format_exc()), file=sys.stderr) exit(1) if self.options.partitioner: cluster.set_partitioner(self.options.partitioner) if cluster.cassandra_version() >= "1.2.5": self.options.binary_protocol = True if self.options.binary_protocol: cluster.set_configuration_options({'start_native_transport': True}) if cluster.cassandra_version() >= "1.2" and self.options.vnodes: cluster.set_configuration_options({'num_tokens': 256}) if not self.options.no_switch: common.switch_cluster(self.path, self.name) print_('Current cluster is now: %s' % self.name) if not (self.options.ipprefix or self.options.ipformat): self.options.ipformat = '127.0.0.%d' if self.options.ssl_path: cluster.enable_ssl(self.options.ssl_path, self.options.require_client_auth) if self.nodes is not None: try: if self.options.debug_log: cluster.set_log_level("DEBUG") if self.options.trace_log: cluster.set_log_level("TRACE") cluster.populate(self.nodes, use_vnodes=self.options.vnodes, ipprefix=self.options.ipprefix, ipformat=self.options.ipformat) if self.options.start_nodes: profile_options = None if self.options.profile: profile_options = {} if self.options.profile_options: profile_options[ 'options'] = self.options.profile_options if cluster.start( verbose=self.options.debug, wait_for_binary_proto=self.options.binary_protocol, jvm_args=self.options.jvm_args, profile_options=profile_options) is None: details = "" if not self.options.debug: details = " (you can use --debug for more information)" print_( "Error starting nodes, see above for details%s" % details, file=sys.stderr) except common.ArgumentError as e: print_(str(e), file=sys.stderr) exit(1)
def run(self): try: self.cluster.set_log_level(self.level, self.options.class_name) except common.ArgumentError as e: print_(str(e), file=sys.stderr) exit(1)
os.mkdir(dirName) for q in six.moves.range(1000): requests = [] for i in six.moves.range(random.randint(1, 2)): tNow = now() requests.append({ 'dirName': dirName, 'bib': 0, 'time': tNow, 'raceSeconds': (tNow - tStart).total_seconds(), 'race_name': u'Client Race Test', }) success, error = PhotoSendRequests(requests, 'photo') if not success: six.print_(error) time.sleep(random.random() * 2) for request in requests: request.update({ 'bib': int(199 * random.random() + 1), 'first_name': choice(first_names), 'last_name': choice(last_names), 'team': choice(teams), }) success, error = PhotoSendRequests(requests, 'rename') if not success: six.print_(error) time.sleep(random.random() * 2) while 1: requests = []
ctx.buy(ctx.ma, q) elif ctx.pos() > 0 and (ctx.open >= ctx.ma > ctx.close or (ctx.open < ctx.ma < ctx.high and ctx.close < ctx.ma)): ctx.sell(ctx.ma, ctx.pos()) def on_exit(self, ctx): pass if __name__ == '__main__': start = timeit.default_timer() ConfigUtil.set(source='cached-tushare', cache_path='E:/_cache_tushare') set_symbols(['002380.SZ-1.Day'], '2016-09-01') profile = add_strategy([Stg1('Stg1')], {'capital': 100000.0}) run() stop = timeit.default_timer() six.print_('using time: %d seconds' % (stop - start)) curve0 = finance.create_equity_curve(profile.all_holdings(0)) curve = finance.create_equity_curve(profile.all_holdings()) AnalyzeFrame(profile) plotting.plot_strategy(profile.data(0), { 1: [profile.technicals(0)] }, profile.deals(0), curve.equity.values, profile.marks(0)) # plotting.plot_curves([curve.networth]) six.print_(finance.summary_stats(curve, 252)) plt.show()
if a in dictdata: a = dictdata[a] else: a = a data2+=a del data return data2 # แก้ไขพิมพ์ภาษาอังกฤษผิดภาษา def texttoeng(data): """ :param str data: Incorrect input language correction (Needs english but input thai) :return: english text """ data = list(data) data2 = "" dictdataeng= {v: k for k, v in six.iteritems(dictdata)} for a in data: if a in dictdataeng: a = dictdataeng[a] else: a = a data2+=a return data2 if __name__ == "__main__": a="l;ylfu8iy[" a=texttothai(a) a=texttothai(a) b="นามรสนอำันี" b=texttoeng(b) six.print_(a) six.print_(b)
def start(self, join_ring=True, no_wait=False, verbose=False, update_pid=True, wait_other_notice=False, replace_token=None, replace_address=None, jvm_args=[], wait_for_binary_proto=False, profile_options=None, use_jna=False): """ Start the node. Options includes: - join_ring: if false, start the node with -Dcassandra.join_ring=False - no_wait: by default, this method returns when the node is started and listening to clients. If no_wait=True, the method returns sooner. - wait_other_notice: if True, this method returns only when all other live node of the cluster have marked this node UP. - replace_token: start the node with the -Dcassandra.replace_token option. - replace_address: start the node with the -Dcassandra.replace_address option. """ if self.is_running(): raise NodeError("%s is already running" % self.name) for itf in list(self.network_interfaces.values()): if itf is not None and replace_address is None: common.check_socket_available(itf) if wait_other_notice: marks = [ (node, node.mark_log()) for node in list(self.cluster.nodes.values()) if node.is_running() ] cdir = self.get_install_dir() launch_bin = common.join_bin(cdir, 'bin', 'dse') # Copy back the dse scripts since profiling may have modified it the previous time shutil.copy(launch_bin, self.get_bin_dir()) launch_bin = common.join_bin(self.get_path(), 'bin', 'dse') # If Windows, change entries in .bat file to split conf from binaries if common.is_win(): self.__clean_bat() if profile_options is not None: config = common.get_config() if not 'yourkit_agent' in config: raise NodeError("Cannot enable profile. You need to set 'yourkit_agent' to the path of your agent in a ~/.ccm/config") cmd = '-agentpath:%s' % config['yourkit_agent'] if 'options' in profile_options: cmd = cmd + '=' + profile_options['options'] print_(cmd) # Yes, it's fragile as shit pattern=r'cassandra_parms="-Dlog4j.configuration=log4j-server.properties -Dlog4j.defaultInitOverride=true' common.replace_in_file(launch_bin, pattern, ' ' + pattern + ' ' + cmd + '"') os.chmod(launch_bin, os.stat(launch_bin).st_mode | stat.S_IEXEC) env = common.make_dse_env(self.get_install_dir(), self.get_path()) if common.is_win(): self._clean_win_jmx(); pidfile = os.path.join(self.get_path(), 'cassandra.pid') args = [launch_bin, 'cassandra'] if self.workload is not None: if 'hadoop' in self.workload: args.append('-t') if 'solr' in self.workload: args.append('-s') if 'spark' in self.workload: args.append('-k') if 'cfs' in self.workload: args.append('-c') args += [ '-p', pidfile, '-Dcassandra.join_ring=%s' % str(join_ring) ] if replace_token is not None: args.append('-Dcassandra.replace_token=%s' % str(replace_token)) if replace_address is not None: args.append('-Dcassandra.replace_address=%s' % str(replace_address)) if use_jna is False: args.append('-Dcassandra.boot_without_jna=true') args = args + jvm_args process = None if common.is_win(): # clean up any old dirty_pid files from prior runs if (os.path.isfile(self.get_path() + "/dirty_pid.tmp")): os.remove(self.get_path() + "/dirty_pid.tmp") process = subprocess.Popen(args, cwd=self.get_bin_dir(), env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE) else: process = subprocess.Popen(args, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # Our modified batch file writes a dirty output with more than just the pid - clean it to get in parity # with *nix operation here. if common.is_win(): self.__clean_win_pid() self._update_pid(process) elif update_pid: if no_wait: time.sleep(2) # waiting 2 seconds nevertheless to check for early errors and for the pid to be set else: for line in process.stdout: if verbose: print_(line.rstrip('\n')) self._update_pid(process) if not self.is_running(): raise NodeError("Error starting node %s" % self.name, process) if wait_other_notice: for node, mark in marks: node.watch_log_for_alive(self, from_mark=mark) if wait_for_binary_proto: self.watch_log_for("Starting listening for CQL clients") # we're probably fine at that point but just wait some tiny bit more because # the msg is logged just before starting the binary protocol server time.sleep(0.2) if self.cluster.hasOpscenter(): self._start_agent() return process
print("Work request #%s added." % req.requestID) # or shorter: # [main.putRequest(req) for req in requests] # ...and wait for the results to arrive in the result queue # by using ThreadPool.wait(). This would block until results for # all work requests have arrived: # main.wait() # instead we can poll for results while doing something else: i = 0 while True: try: time.sleep(0.5) main.poll() print_("Main thread working...", end=' ') print("(active worker threads: %i)" % (threading.activeCount() - 1, )) if i == 10: print("**** Adding 3 more worker threads...") main.createWorkers(3) if i == 20: print("**** Dismissing 2 worker threads...") main.dismissWorkers(2) i += 1 except KeyboardInterrupt: print("**** Interrupted!") break except NoResultsPending: print("**** No pending results.") break
def bell_base_main_hole_outline(ai_c): """ generate the A-outline of the main hole of the bell_base part """ ### constant radian_epsilon = math.pi / 1000 ### intermediate parameters bell_face_width_10 = ai_c['bell_face_width'] / 10.0 wall_thickness = max(ai_c['face_thickness'], ai_c['side_thickness']) ect = ai_c['bell_extra_cut_thickness'] ### sub-outline construction sol = [] sol.append((-3 * bell_face_width_10, -5 * bell_face_width_10 + 1.5 * wall_thickness, ai_c['bell_cnc_router_bit_radius'])) sol.append((-3 * bell_face_width_10, -5 * bell_face_width_10 - ect, -1 * ai_c['bell_cnc_router_bit_radius'])) sol.append((-1 * bell_face_width_10, -5 * bell_face_width_10 - ect, -1 * ai_c['bell_cnc_router_bit_radius'])) sol.append( (-1 * bell_face_width_10, -5 * bell_face_width_10 + wall_thickness, 0)) sol.append( (1 * bell_face_width_10, -5 * bell_face_width_10 + wall_thickness, 0)) sol.append((1 * bell_face_width_10, -5 * bell_face_width_10 - ect, -1 * ai_c['bell_cnc_router_bit_radius'])) sol.append((3 * bell_face_width_10, -5 * bell_face_width_10 - ect, -1 * ai_c['bell_cnc_router_bit_radius'])) sol.append((3 * bell_face_width_10, -5 * bell_face_width_10 + 1.5 * wall_thickness, ai_c['bell_cnc_router_bit_radius'])) if (ai_c['z_hole_radius'] > 0): lAB = 2 * bell_face_width_10 - wall_thickness lAC = ai_c['z_hole_position_length'] lCD = ai_c['z_hole_external_radius'] aBAC = math.pi / 4 lCB = math.sqrt(lAB**2 + lAC**2 - 2 * lAB * lAC * math.cos(aBAC)) # law of cosines in the triangle ABC cos_aACB = (lCB**2 + lAC**2 - lAB**2) / (2 * lCB * lAC) if (abs(cos_aACB) > 1): six.print_( ("ERR359: Error, cos_aACB {:0.3f} is out of the range -1..1". format(cos_aACB))) sys.exit(2) aACB = math.acos(cos_aACB) cos_aBCD = lCD / lCB if (abs(cos_aBCD) > 1): six.print_( ("ERR364: Error, cos_aBCD {:0.3f} is out of the range -1..1". format(cos_aBCD))) sys.exit(2) aBCD = math.acos(cos_aBCD) aACD = aACB + aBCD #print("dbg370: aACB {:0.3f} aBCD {:0.3f} aACD {:0.3f}".format(aACB, aBCD, aACD)) lEC = math.sqrt(2) * wall_thickness + lAC Cx = 5 * bell_face_width_10 - lEC * math.cos(math.pi / 4) # sqrt(2)/2 Cy = -5 * bell_face_width_10 + lEC * math.sin(math.pi / 4) Fx = Cx - ai_c['z_hole_external_radius'] * math.cos(math.pi / 4) Fy = Cy + ai_c['z_hole_external_radius'] * math.sin(math.pi / 4) Dx = Cx + ai_c['z_hole_external_radius'] * math.cos(-math.pi / 4 - aACD) Dy = Cy + ai_c['z_hole_external_radius'] * math.sin(-math.pi / 4 - aACD) Gx = Cx + ai_c['z_hole_external_radius'] * math.cos(-math.pi / 4 + aACD) Gy = Cy + ai_c['z_hole_external_radius'] * math.sin(-math.pi / 4 + aACD) if (aACD > math.pi - radian_epsilon): sol.append((Fx, Fy, ai_c['bell_cnc_router_bit_radius'])) else: sol.append((Dx, Dy, 0)) sol.append((Fx, Fy, Gx, Gy, 0)) #print("dbg351: sol:", sol) ### outline construction r_ol = [] for i in range(4): r_ol.extend(cnc25d_api.outline_rotate(sol, 0.0, 0.0, i * math.pi / 2)) r_ol = cnc25d_api.outline_close(r_ol) ### return return (r_ol)
def print_header(self, iterations="unlimited"): print("Type escape sequence CTRL + C to abort.") six.print_(( "Sending %s, %s-byte ICMP Echos to %s, timeout is %s milliseconds:" % (iterations, self.packet_size, self.destination, self.timeout)))
def run(self): for node in self.cluster.nodelist(): errors = node.grep_log_for_errors() for mylist in errors: for line in mylist: print_(line)
def show(js): six.print_(json.dumps(js, sort_keys=True, indent=4, separators=(',', ': ')))
def run(self): stdout, stderr = self.cluster.sctool(self.sctool_options) print_(stderr) print_(stdout)
def bell_face_outline(ai_c): """ generate the external-outline (type-a) of the bell_face part """ ### precision radian_epsilon = math.pi / 1000 ### leg slope inclination angle lAB = ai_c['bell_face_width'] / 2.0 - ai_c['leg_spare_width'] lBC = ai_c['leg_length'] lCD = ai_c['axle_external_radius'] lAC = math.sqrt(lAB**2 + lBC**2) cos_aBAC = float(lAB) / lAC if (abs(cos_aBAC) > 1): six.print_( ("ERR063: Error, cos_aBAC {:0.3f} is out of the range -1..1". format(cos_aBAC))) six.print_(("dbg064: lAC {:0.3f} lAB {:0.3f}".format(lAC, lAB))) sys.exit(2) aBAC = math.acos(cos_aBAC) #lAD = math.sqrt(lAC**2-lCD**2) aCAD = math.asin(float(lCD) / lAC) leg_inclination_angle = aBAC + aCAD # aBAD leg_ext_axle_angle = math.pi / 2 - leg_inclination_angle #print("dbg072: leg_inclination_angle {:0.3f} leg_ext_axle_angle {:0.3f}".format(leg_inclination_angle, leg_ext_axle_angle)) #print("dbg073: aBAC {:0.3f} aCAD {:0.3f} lAC {:0.3f}".format(aBAC, aCAD, lAC)) ### smoothing leg if (ai_c['leg_spare_width'] > 0): # coordiante of A Ax = -1 * ai_c['bell_face_width'] / 2.0 + ai_c['leg_spare_width'] Ay = ai_c['base_thickness'] + ai_c['bell_face_height'] # coordiante of C Dx = -1 * ai_c['axle_external_radius'] * math.cos(leg_ext_axle_angle) Dy = ai_c['base_thickness'] + ai_c['bell_face_height'] + ai_c[ 'leg_length'] + ai_c['axle_external_radius'] * math.sin( leg_ext_axle_angle) # coordiante of E Ex = -1 * ai_c['bell_face_width'] / 2.0 Ey = ai_c['base_thickness'] + ai_c['bell_face_height'] # equation of the line AC (AClx, ACly, ACk, lAC, xAC) = small_geometry.line_equation( (Ax, Ay), (Dx, Dy), "line_AC") # coordinate of F: the point at the distance leg_smoothing_radius of AC an A (FX, FY, ACkF) = small_geometry.line_distance_point( (Ax, Ay), (Dx, Dy), ai_c['leg_smoothing_radius'], "point_F") # coordinate of G: the intersection of the circle of center E and radius leg_smoothing_radius and the line parallet to AC passing through F (Gx, Gy, line_circle_intersection_status ) = small_geometry.line_circle_intersection( (AClx, ACly, ACkF), (Ex, Ey), ai_c['leg_smoothing_radius'], (Dx, Dy), math.pi / 2, "point_G") # coordinate of H: projection of G on the line (AC) (Hx, Hy) = small_geometry.line_point_projection((AClx, ACly, ACk), (Gx, Gy), "point_H") # angle (Gx, GH) axGH = math.atan2(Hy - Gy, Hx - Gx) if (abs(axGH + leg_ext_axle_angle) > radian_epsilon): # check axGH six.print_(( "ERR097: Error, axGH {:0.3f} is not equal to -1*leg_ext_axle_angle {:0.3f}" .format(axGH, leg_ext_axle_angle))) sys.exit(2) # angle (Gx, GE) axGE = math.atan2(Ey - Gy, Ex - Gx) # angle (Gx, GI) axGI = (axGH + axGE) / 2.0 # coordinate of I Ix = Gx + math.cos(axGI) * ai_c['leg_smoothing_radius'] Iy = Gy + math.sin(axGI) * ai_c['leg_smoothing_radius'] ### intermediate parameters axle_center_y = ai_c['base_thickness'] + ai_c['bell_face_height'] + ai_c[ 'leg_length'] bell_face_height_5 = ai_c['bell_face_height'] / 5.0 bell_face_width_10 = ai_c['bell_face_width'] / 10.0 bell_face_width_2 = ai_c['bell_face_width'] / 2.0 ect = ai_c['bell_extra_cut_thickness'] st = ai_c['side_thickness'] bt = ai_c['base_thickness'] ### bell_face_outline r_ol = [] r_ol.append( (bell_face_width_2, ai_c['base_thickness'] + ai_c['bell_face_height'], 0)) # top-right, CCW #r_ol.append((bell_face_width_2-ai_c['leg_spare_width'], ai_c['base_thickness']+ai_c['bell_face_height'], 0)) # leg if (ai_c['leg_spare_width'] > 0): r_ol.append((-1 * Ix, Iy, -1 * Hx, Hy, 0)) r_ol.append((ai_c['axle_external_radius'] * math.cos(leg_ext_axle_angle), axle_center_y + ai_c['axle_external_radius'] * math.sin(leg_ext_axle_angle), 0)) # axle r_ol.append( (0, axle_center_y + ai_c['axle_external_radius'], -1 * ai_c['axle_external_radius'] * math.cos(leg_ext_axle_angle), axle_center_y + ai_c['axle_external_radius'] * math.sin(leg_ext_axle_angle), 0)) #r_ol.append((-1*bell_face_width_2+ai_c['leg_spare_width'], ai_c['base_thickness']+ai_c['bell_face_height'], 0)) # leg if (ai_c['leg_spare_width'] > 0): r_ol.append((Hx, Hy, 0)) r_ol.append((Ix, Iy, -1 * bell_face_width_2, ai_c['base_thickness'] + ai_c['bell_face_height'], 0)) else: r_ol.append((-1 * bell_face_width_2, ai_c['base_thickness'] + ai_c['bell_face_height'], 0)) # left-side r_ol.append((-1 * bell_face_width_2, ai_c['base_thickness'] + 4 * bell_face_height_5 + ect, 0)) r_ol.append((-1 * bell_face_width_2 + st + ect, ai_c['base_thickness'] + 4 * bell_face_height_5 + ect, -1 * ai_c['bell_cnc_router_bit_radius'])) r_ol.append((-1 * bell_face_width_2 + st + ect, ai_c['base_thickness'] + 3 * bell_face_height_5 - ect, -1 * ai_c['bell_cnc_router_bit_radius'])) r_ol.append((-1 * bell_face_width_2, ai_c['base_thickness'] + 3 * bell_face_height_5 - ect, 0)) r_ol.append((-1 * bell_face_width_2, ai_c['base_thickness'] + 2 * bell_face_height_5 + ect, 0)) r_ol.append((-1 * bell_face_width_2 + st + ect, ai_c['base_thickness'] + 2 * bell_face_height_5 + ect, -1 * ai_c['bell_cnc_router_bit_radius'])) r_ol.append((-1 * bell_face_width_2 + st + ect, ai_c['base_thickness'] + 1 * bell_face_height_5 - ect, -1 * ai_c['bell_cnc_router_bit_radius'])) r_ol.append((-1 * bell_face_width_2, ai_c['base_thickness'] + 1 * bell_face_height_5 - ect, 0)) r_ol.append( (-1 * bell_face_width_2, ai_c['base_thickness'] + ect, 0)) # bottom r_ol.append((-3 * bell_face_width_10 + ect, ai_c['base_thickness'] + ect, -1 * ai_c['bell_cnc_router_bit_radius'])) r_ol.append((-3 * bell_face_width_10 + ect, 0, 0)) r_ol.append((-1 * bell_face_width_10 - ect, 0, 0)) r_ol.append((-1 * bell_face_width_10 - ect, ai_c['base_thickness'] + ect, -1 * ai_c['bell_cnc_router_bit_radius'])) r_ol.append((1 * bell_face_width_10 + ect, ai_c['base_thickness'] + ect, -1 * ai_c['bell_cnc_router_bit_radius'])) r_ol.append((1 * bell_face_width_10 + ect, 0, 0)) r_ol.append((3 * bell_face_width_10 - ect, 0, 0)) r_ol.append((3 * bell_face_width_10 - ect, ai_c['base_thickness'] + ect, -1 * ai_c['bell_cnc_router_bit_radius'])) r_ol.append( (bell_face_width_2, ai_c['base_thickness'] + ect, 0)) # right-side r_ol.append((bell_face_width_2, ai_c['base_thickness'] + 1 * bell_face_height_5 - ect, 0)) r_ol.append((bell_face_width_2 - (st + ect), ai_c['base_thickness'] + 1 * bell_face_height_5 - ect, -1 * ai_c['bell_cnc_router_bit_radius'])) r_ol.append((bell_face_width_2 - (st + ect), ai_c['base_thickness'] + 2 * bell_face_height_5 + ect, -1 * ai_c['bell_cnc_router_bit_radius'])) r_ol.append((bell_face_width_2, ai_c['base_thickness'] + 2 * bell_face_height_5 + ect, 0)) r_ol.append((bell_face_width_2, ai_c['base_thickness'] + 3 * bell_face_height_5 - ect, 0)) r_ol.append((bell_face_width_2 - (st + ect), ai_c['base_thickness'] + 3 * bell_face_height_5 - ect, -1 * ai_c['bell_cnc_router_bit_radius'])) r_ol.append((bell_face_width_2 - (st + ect), ai_c['base_thickness'] + 4 * bell_face_height_5 + ect, -1 * ai_c['bell_cnc_router_bit_radius'])) r_ol.append((bell_face_width_2, ai_c['base_thickness'] + 4 * bell_face_height_5 + ect, 0)) r_ol.append((r_ol[0][0], r_ol[0][1], 0)) # close return (r_ol)
def writeToFile(s, fname): six.print_('creating', fname, '...') with io.open(os.path.join(pypiDir, fname), 'w') as f: f.write(s)
def validate(self, parser, options, args): Cmd.validate(self, parser, options, args, cluster_name=True) if not os.path.exists(os.path.join(self.path, self.name, 'cluster.conf')): print_("%s does not appear to be a valid cluster (use ccm list to view valid clusters)" % self.name, file=sys.stderr) sys.exit(1)
def main(args=None): if not args: args = sys.argv[1:] outputFilename = None embedResources = False generateGetText = False assignVariables = True generatePython = False try: opts, args = getopt.gnu_getopt( args, "hpgevo:", "help python gettext embed novar output=".split()) except getopt.GetoptError as exc: print("\nError : %s\n" % str(exc)) print(__doc__) sys.exit(1) # If there is no input file argument, show help and exit if not args: print(__doc__) print("No xrc input file was specified.") sys.exit(1) # Parse options and arguments for opt, val in opts: if opt in ["-h", "--help"]: print(__doc__) sys.exit(1) if opt in ["-p", "--python"]: generatePython = True if opt in ["-o", "--output"]: outputFilename = val if opt in ["-e", "--embed"]: embedResources = True if opt in ["-v", "--novar"]: assignVariables = False if opt in ["-g", "--gettext"]: generateGetText = True # check for and expand any wildcards in the list of input files inputFiles = [] for arg in args: inputFiles += glob.glob(arg) comp = XmlResourceCompiler() try: if generatePython: if not outputFilename: outputFilename = os.path.splitext(args[0])[0] + "_xrc.py" comp.MakePythonModule(inputFiles, outputFilename, embedResources, generateGetText, assignVariables) elif generateGetText: if not outputFilename: outputFilename = '-' comp.MakeGetTextOutput(inputFiles, outputFilename) else: print(__doc__) print("One or both of -p, -g must be specified.") sys.exit(1) except IOError as exc: print_("%s." % str(exc), file=sys.stderr) else: if outputFilename != "-": print_("Resources written to %s." % outputFilename, file=sys.stderr)
def main(): if os.path.exists(iterm2Pth): print_('Fixing iterm2 settings') scrubLines(iterm2Pth, 'NSWindow Frame iTerm Window', n=2)
def main(): p = argparse.ArgumentParser( description='Chainer implementation of waifu2x') p.add_argument('--version', action='version', version='0.1.0') p.add_argument('--gpu', '-g', type=int, default=-1) p.add_argument('--input', '-i', default='images/small.png') p.add_argument('--output', '-o', type=str, required=True) p.add_argument('--quality', '-q', type=int, default=None) p.add_argument('--model_dir', '-d', default=None) p.add_argument('--scale_ratio', '-s', type=float, default=2.0) p.add_argument('--tta', '-t', action='store_true') p.add_argument('--batch_size', '-b', type=int, default=16) p.add_argument('--block_size', '-l', type=int, default=128) p.add_argument('--extension', '-e', default='png', choices=['png', 'webp']) p.add_argument('--arch', '-a', default='VGG7', choices=[ 'VGG7', '0', 'UpConv7', '1', 'ResNet10', '2', 'UpResNet10', '3' ]) p.add_argument('--method', '-m', default='scale', choices=['noise', 'scale', 'noise_scale']) p.add_argument('--noise_level', '-n', type=int, default=1, choices=[0, 1, 2, 3]) p.add_argument('--color', '-c', default='rgb', choices=['y', 'rgb']) p.add_argument('--tta_level', '-T', type=int, default=8, choices=[2, 4, 8]) g = p.add_mutually_exclusive_group() g.add_argument('--width', '-W', type=int, default=0) g.add_argument('--height', '-H', type=int, default=0) g.add_argument('--shorter_side', '-S', type=int, default=0) g.add_argument('--longer_side', '-L', type=int, default=0) args = p.parse_args() if args.arch in srcnn.table: args.arch = srcnn.table[args.arch] models = load_models(args) input_exts = ['.png', '.jpg', '.jpeg', '.bmp', '.tif', '.tiff', '.webp'] output_exts = ['.png', '.webp'] outext = '.' + args.extension outname = None outdir = args.output if os.path.isdir(args.input): filelist = utils.load_filelist(args.input) else: tmpname, tmpext = os.path.splitext(os.path.basename(args.output)) if tmpext in output_exts: outext = tmpext outname = tmpname outdir = os.path.dirname(args.output) outdir = './' if outdir == '' else outdir elif tmpext != '': raise ValueError('Format {} is not supported'.format(tmpext)) filelist = [args.input] if not os.path.exists(outdir): os.makedirs(outdir) for path in filelist: tmpname, tmpext = os.path.splitext(os.path.basename(path)) if outname is None or len(filelist) > 1: outname = tmpname outpath = os.path.join(outdir, '{}{}'.format(outname, outext)) if tmpext.lower() in input_exts: src = Image.open(path) w, h = src.size[:2] if args.width != 0: args.scale_ratio = args.width / w elif args.height != 0: args.scale_ratio = args.height / h elif args.shorter_side != 0: if w < h: args.scale_ratio = args.shorter_side / w else: args.scale_ratio = args.shorter_side / h elif args.longer_side != 0: if w > h: args.scale_ratio = args.longer_side / w else: args.scale_ratio = args.longer_side / h dst = src.copy() start = time.time() outname += '_(tta{})'.format(args.tta_level) if args.tta else '_' if 'noise_scale' in models: outname += '(noise{}_scale{:.1f}x)'.format( args.noise_level, args.scale_ratio) dst = upscale_image(args, dst, models['noise_scale'], models['alpha']) else: if 'noise' in models: outname += '(noise{})'.format(args.noise_level) dst = denoise_image(args, dst, models['noise']) if 'scale' in models: outname += '(scale{:.1f}x)'.format(args.scale_ratio) dst = upscale_image(args, dst, models['scale']) print('Elapsed time: {:.6f} sec'.format(time.time() - start)) outname += '({}_{}){}'.format(args.arch, args.color, outext) #if os.path.exists(outpath): # outpath = os.path.join(outdir, outname) outpath = args.output lossless = args.quality is None quality = 100 if lossless else args.quality icc_profile = src.info.get('icc_profile') icc_profile = "" if icc_profile is None else icc_profile dst.convert(src.mode).save(outpath, quality=quality, lossless=lossless, icc_profile=icc_profile) six.print_('Saved as \'{}\''.format(outpath))
lineOut.append(' ') else: lineOut.append(c) lines.append(''.join(lineOut)) return '\n'.join(lines) + '\n' def writeToFile(s, fname): six.print_('creating', fname, '...') with io.open(os.path.join(pypiDir, fname), 'w') as f: f.write(s) #------------------------------------------------------ # Create a release area for pypi six.print_('Clearing previous contents...') try: subprocess.call(['rm', '-rf', pypiDir]) except: try: shutil.rmtree(pypiDir, ignore_errors=True) except: pass os.mkdir(pypiDir) #-------------------------------------------------------- readme = ''' ====== pyllrp ======
def version(**kwargs): """ Output Version Info """ from rqalpha import version_info six.print_("Current Version: ", version_info)
def MakePythonModule(self, inputFiles, outputFilename, embedResources=False, generateGetText=False, assignVariables=True): self.blocks = {} self.outputFilename = outputFilename outputFile = self._OpenOutputFile(outputFilename) self.assignVariables = assignVariables classes = [] subclasses = [] resources = [] gettextStrings = [] # process all the inputFiles, collecting the output data for inFile in inputFiles: resourceDocument = minidom.parse(inFile) subclasses.append(self.GenerateSubclasses(resourceDocument)) classes.append(self.GenerateClasses(resourceDocument)) if embedResources: res = self.GenerateInitResourcesEmbedded( inFile, resourceDocument) else: res = self.GenerateInitResourcesFile(inFile, resourceDocument) resources.append(res) if generateGetText: gettextStrings += self.FindStringsInNode( resourceDocument.firstChild) # now write it all out print_(self.templates.FILE_HEADER, file=outputFile) # Note: Technically it is not legal to have anything other # than ascii for class and variable names, but since the user # can create the XML with non-ascii names we'll go ahead and # allow for it here, and then let Python complain about it # later when they try to run the program. if subclasses: subclasses = self.ReplaceBlocks(u"\n".join(subclasses)) print_(subclasses, file=outputFile) if classes: classes = self.ReplaceBlocks(u"\n".join(classes)) print_(classes, file=outputFile) print_(self.templates.INIT_RESOURE_HEADER, file=outputFile) if embedResources: print_(self.templates.PREPARE_MEMFS, file=outputFile) resources = u"\n".join(resources) print_(resources, file=outputFile) if generateGetText: # gettextStrings is a list of unicode strings as returned by ConvertText conversions = [u' _("%s")' % s for s in gettextStrings] conversion_block = u"\n".join(conversions) conversion_func = self.templates.GETTEXT_DUMMY_FUNC % conversion_block print_(conversion_func, file=outputFile)
def test_mixed_unicode_and_nonascii_str(self): six.print_(self.printed_nonascii_str) six.print_(self.printed_unicode) six.print_(self.printed_nonascii_str, file=sys.stderr) six.print_(self.printed_unicode, file=sys.stderr) raise {}["oops"]
def install(params): """ Install third-party Mod """ try: from pip._internal import main as pip_main from pip._internal.commands.install import InstallCommand except ImportError: from pip import main as pip_main from pip.commands.install import InstallCommand params = [param for param in params] ##### modified here ##### a = 'test_1' b = 'test_2' options, mod_list = InstallCommand(a, b).parse_args(params) mod_list = [mod_name for mod_name in mod_list if mod_name != "."] params = ["install"] + params for mod_name in mod_list: mod_name_index = params.index(mod_name) if mod_name.startswith("rqalpha_mod_sys_"): six.print_('System Mod can not be installed or uninstalled') return if "rqalpha_mod_" in mod_name: lib_name = mod_name else: lib_name = "rqalpha_mod_" + mod_name params[mod_name_index] = lib_name # Install Mod installed_result = pip_main.main(params) # Export config from rqalpha.utils.config import load_yaml, user_mod_conf_path user_conf = load_yaml(user_mod_conf_path()) if os.path.exists(user_mod_conf_path()) else {'mod': {}} if installed_result == 0: # 如果为0,则说明安装成功 if len(mod_list) == 0: """ 主要是方便 `pip install -e .` 这种方式 本地调试 Mod 使用,需要满足以下条件: 1. `rqalpha mod install -e .` 命令是在对应 自定义 Mod 的根目录下 2. 该 Mod 必须包含 `setup.py` 文件(否则也不能正常的 `pip install -e .` 来安装) 3. 该 Mod 包名必须按照 RQAlpha 的规范来命名,具体规则如下 * 必须以 `rqalpha-mod-` 来开头,比如 `rqalpha-mod-xxx-yyy` * 对应import的库名必须要 `rqalpha_mod_` 来开头,并且需要和包名后半部分一致,但是 `-` 需要替换为 `_`, 比如 `rqalpha_mod_xxx_yyy` """ mod_name = _detect_package_name_from_dir() mod_name = mod_name.replace("-", "_").replace("rqalpha_mod_", "") mod_list.append(mod_name) for mod_name in mod_list: if "rqalpha_mod_" in mod_name: mod_name = mod_name.replace("rqalpha_mod_", "") if "==" in mod_name: mod_name = mod_name.split('==')[0] user_conf['mod'][mod_name] = {} user_conf['mod'][mod_name]['enabled'] = False dump_config(user_mod_conf_path(), user_conf) return installed_result
def test_err(self): six.print_("goodbye", file=sys.stderr)
def init(target_directory): """Initialize a new Great Expectations project. This guided input walks the user through setting up a project. It scaffolds directories, sets up notebooks, creates a project file, and appends to a `.gitignore` file. """ six.print_( colored(figlet_format("Great Expectations", font="big"), color="cyan")) cli_message(greeting_1) if not click.confirm(msg_prompt_lets_begin, default=True): cli_message( "OK - run great_expectations init again when ready. Exiting...") exit(0) try: context = DataContext.create(target_directory) except DataContextError as err: logger.critical(err.message) sys.exit(-1) base_dir = context.root_directory scaffold_directories_and_notebooks(base_dir) cli_message("\nDone.", ) data_source_name = add_datasource(context) cli_message(""" ========== Profiling ========== Would you like to profile '{0:s}' to create candidate expectations and documentation? Please note: Profiling is still a beta feature in Great Expectations. The current profiler will evaluate the entire data source (without sampling), which may be very time consuming. As a rule of thumb, we recommend starting with data smaller than 100MB. To learn more about profiling, visit <blue>https://docs.greatexpectations.io/en/latest/guides/profiling.html\ ?utm_source=cli&utm_medium=init&utm_campaign={1:s}</blue>. """.format(data_source_name, __version__.replace(".", "_"))) if click.confirm("Proceed?", default=True): profiling_results = profile_datasource(context, data_source_name) cli_message(""" ========== Data Documentation ========== To generate documentation from the data you just profiled, the profiling results should be moved from great_expectations/uncommitted (ignored by git) to great_expectations/fixtures. Before committing, please make sure that this data does not contain sensitive information! To learn more: <blue>https://docs.greatexpectations.io/en/latest/guides/data_documentation.html\ ?utm_source=cli&utm_medium=init&utm_campaign={0:s}</blue> """.format(__version__.replace(".", "_"))) if click.confirm( "Move the profiled data and build HTML documentation?", default=True): cli_message("\nMoving files...") for profiling_result in profiling_results: data_asset_name = profiling_result[1]['meta'][ 'data_asset_name'] expectation_suite_name = profiling_result[1]['meta'][ 'expectation_suite_name'] run_id = profiling_result[1]['meta']['run_id'] context.move_validation_to_fixtures(data_asset_name, expectation_suite_name, run_id) cli_message("\nDone.") cli_message("\nBuilding documentation...") build_documentation(context) else: cli_message("Okay, skipping HTML documentation for now.`.") else: cli_message("Okay, skipping profiling for now. You can always do this " "later by running `great_expectations profile`.") cli_message(msg_go_to_notebook)