idx int64 0 63k | question stringlengths 61 4.03k | target stringlengths 6 1.23k |
|---|---|---|
52,300 | def Robbins ( L , G , rhol , rhog , mul , H = 1.0 , Fpd = 24.0 ) : r L = L * 737.33812 G = G * 737.33812 rhol = rhol * 0.062427961 rhog = rhog * 0.062427961 mul = mul * 1000.0 C3 = 7.4E-8 C4 = 2.7E-5 Fpd_root_term = ( .05 * Fpd ) ** 0.5 Lf = L * ( 62.4 / rhol ) * Fpd_root_term * mul ** 0.1 Gf = G * ( 0.075 / rhog ) ** ... | r Calculates pressure drop across a packed column using the Robbins equation . |
52,301 | def dP_packed_bed ( dp , voidage , vs , rho , mu , L = 1 , Dt = None , sphericity = None , Method = None , AvailableMethods = False ) : r def list_methods ( ) : methods = [ ] if all ( ( dp , voidage , vs , rho , mu , L ) ) : for key , values in packed_beds_correlations . items ( ) : if Dt or not values [ 1 ] : methods ... | r This function handles choosing which pressure drop in a packed bed correlation is used . Automatically select which correlation to use if none is provided . Returns None if insufficient information is provided . |
52,302 | def Friedel ( m , x , rhol , rhog , mul , mug , sigma , D , roughness = 0 , L = 1 ) : r v_lo = m / rhol / ( pi / 4 * D ** 2 ) Re_lo = Reynolds ( V = v_lo , rho = rhol , mu = mul , D = D ) fd_lo = friction_factor ( Re = Re_lo , eD = roughness / D ) dP_lo = fd_lo * L / D * ( 0.5 * rhol * v_lo ** 2 ) v_go = m / rhog / ( p... | r Calculates two - phase pressure drop with the Friedel correlation . |
52,303 | def airmass ( func , angle , H_max = 86400.0 , R_planet = 6.371229E6 , RI = 1.000276 ) : r delta0 = RI - 1.0 rho0 = func ( 0.0 ) angle_term = cos ( radians ( angle ) ) def to_int ( Z ) : rho = func ( Z ) t1 = ( 1.0 + 2.0 * delta0 * ( 1.0 - rho / rho0 ) ) t2 = ( angle_term / ( 1.0 + Z / R_planet ) ) ** 2 t3 = ( 1.0 - t1... | r Calculates mass of air per square meter in the atmosphere using a provided atmospheric model . The lowest air mass is calculated straight up ; as the angle is lowered to nearer and nearer the horizon the air mass increases and can approach 40x or more the minimum airmass . |
52,304 | def _get_ind_from_H ( H ) : r if H <= 0 : return 0 for ind , Hi in enumerate ( H_std ) : if Hi >= H : return ind - 1 return 7 | r Method defined in the US Standard Atmosphere 1976 for determining the index of the layer a specified elevation is above . Levels are 0 11E3 20E3 32E3 47E3 51E3 71E3 84852 meters respectively . |
52,305 | def gauge_from_t ( t , SI = True , schedule = 'BWG' ) : r tol = 0.1 if SI : t_inch = round ( t / inch , 9 ) else : t_inch = t try : sch_integers , sch_inch , sch_SI , decreasing = wire_schedules [ schedule ] except : raise ValueError ( 'Wire gauge schedule not found' ) sch_max , sch_min = sch_inch [ 0 ] , sch_inch [ - ... | r Looks up the gauge of a given wire thickness of given schedule . Values are all non - linear and tabulated internally . |
52,306 | def t_from_gauge ( gauge , SI = True , schedule = 'BWG' ) : r try : sch_integers , sch_inch , sch_SI , decreasing = wire_schedules [ schedule ] except : raise ValueError ( "Wire gauge schedule not found; supported gauges are \'BWG', 'AWG', 'SWG', 'MWG', 'BSWG', and 'SSWG'." ) try : i = sch_integers . index ( gauge ) ex... | r Looks up the thickness of a given wire gauge of given schedule . Values are all non - linear and tabulated internally . |
52,307 | def API520_F2 ( k , P1 , P2 ) : r r = P2 / P1 return ( k / ( k - 1 ) * r ** ( 2. / k ) * ( ( 1 - r ** ( ( k - 1. ) / k ) ) / ( 1. - r ) ) ) ** 0.5 | r Calculates coefficient F2 for subcritical flow for use in API 520 subcritical flow relief valve sizing . |
52,308 | def API520_SH ( T1 , P1 ) : r if P1 > 20780325.0 : raise Exception ( 'For P above 20679 kPag, use the critical flow model' ) if T1 > 922.15 : raise Exception ( 'Superheat cannot be above 649 degrees Celcius' ) if T1 < 422.15 : return 1. return float ( bisplev ( T1 , P1 , API520_KSH_tck ) ) | r Calculates correction due to steam superheat for steam flow for use in API 520 relief valve sizing . 2D interpolation among a table with 28 pressures and 10 temperatures is performed . |
52,309 | def API520_W ( Pset , Pback ) : r gauge_backpressure = ( Pback - atm ) / ( Pset - atm ) * 100.0 if gauge_backpressure < 15.0 : return 1.0 return interp ( gauge_backpressure , Kw_x , Kw_y ) | r Calculates capacity correction due to backpressure on balanced spring - loaded PRVs in liquid service . For pilot operated valves this is always 1 . Applicable up to 50% of the percent gauge backpressure For use in API 520 relief valve sizing . 1D interpolation among a table with 53 backpressures is performed . |
52,310 | def API520_B ( Pset , Pback , overpressure = 0.1 ) : r gauge_backpressure = ( Pback - atm ) / ( Pset - atm ) * 100 if overpressure not in [ 0.1 , 0.16 , 0.21 ] : raise Exception ( 'Only overpressure of 10%, 16%, or 21% are permitted' ) if ( overpressure == 0.1 and gauge_backpressure < 30 ) or ( overpressure == 0.16 and... | r Calculates capacity correction due to backpressure on balanced spring - loaded PRVs in vapor service . For pilot operated valves this is always 1 . Applicable up to 50% of the percent gauge backpressure For use in API 520 relief valve sizing . 1D interpolation among a table with 53 backpressures is performed . |
52,311 | def API520_A_g ( m , T , Z , MW , k , P1 , P2 = 101325 , Kd = 0.975 , Kb = 1 , Kc = 1 ) : r P1 , P2 = P1 / 1000. , P2 / 1000. m = m * 3600. if is_critical_flow ( P1 , P2 , k ) : C = API520_C ( k ) A = m / ( C * Kd * Kb * Kc * P1 ) * ( T * Z / MW ) ** 0.5 else : F2 = API520_F2 ( k , P1 , P2 ) A = 17.9 * m / ( F2 * Kd * ... | r Calculates required relief valve area for an API 520 valve passing a gas or a vapor at either critical or sub - critical flow . |
52,312 | def API520_A_steam ( m , T , P1 , Kd = 0.975 , Kb = 1 , Kc = 1 ) : r KN = API520_N ( P1 ) KSH = API520_SH ( T , P1 ) P1 = P1 / 1000. m = m * 3600. A = 190.5 * m / ( P1 * Kd * Kb * Kc * KN * KSH ) return A * 0.001 ** 2 | r Calculates required relief valve area for an API 520 valve passing a steam at either saturation or superheat but not partially condensed . |
52,313 | def getFile ( self , name , relative = None ) : if self . pathCallback is not None : return getFile ( self . _getFileDeprecated ( name , relative ) ) return getFile ( name , relative or self . pathDirectory ) | Returns a file name or None |
52,314 | def getFontName ( self , names , default = "helvetica" ) : if type ( names ) is not ListType : if type ( names ) not in six . string_types : names = str ( names ) names = names . strip ( ) . split ( "," ) for name in names : if type ( name ) not in six . string_types : name = str ( name ) font = self . fontList . get (... | Name of a font |
52,315 | def pisaPreLoop ( node , context , collect = False ) : data = u"" if node . nodeType == Node . TEXT_NODE and collect : data = node . data elif node . nodeType == Node . ELEMENT_NODE : name = node . tagName . lower ( ) if name in ( "style" , "link" ) : attr = pisaGetAttributes ( context , name , node . attributes ) medi... | Collect all CSS definitions |
52,316 | def pisaParser ( src , context , default_css = "" , xhtml = False , encoding = None , xml_output = None ) : global CSSAttrCache CSSAttrCache = { } if xhtml : parser = html5lib . XHTMLParser ( tree = treebuilders . getTreeBuilder ( "dom" ) ) else : parser = html5lib . HTMLParser ( tree = treebuilders . getTreeBuilder ( ... | - Parse HTML and get miniDOM - Extract CSS informations add default CSS parse CSS - Handle the document DOM itself and build reportlab story - Return Context object |
52,317 | def doLayout ( self , width ) : self . width = width font_sizes = [ 0 ] + [ frag . get ( "fontSize" , 0 ) for frag in self ] self . fontSize = max ( font_sizes ) self . height = self . lineHeight = max ( frag * self . LINEHEIGHT for frag in font_sizes ) y = ( self . lineHeight - self . fontSize ) for frag in self : fra... | Align words in previous line . |
52,318 | def splitIntoLines ( self , maxWidth , maxHeight , splitted = False ) : self . lines = [ ] self . height = 0 self . maxWidth = self . width = maxWidth self . maxHeight = maxHeight boxStack = [ ] style = self . style x = 0 if not splitted : x = style [ "textIndent" ] lenText = len ( self ) pos = 0 while pos < lenText : ... | Split text into lines and calculate X positions . If we need more space in height than available we return the rest of the text |
52,319 | def dumpLines ( self ) : for i , line in enumerate ( self . lines ) : logger . debug ( "Line %d:" , i ) logger . debug ( line . dumpFragments ( ) ) | For debugging dump all line and their content |
52,320 | def wrap ( self , availWidth , availHeight ) : self . avWidth = availWidth self . avHeight = availHeight logger . debug ( "*** wrap (%f, %f)" , availWidth , availHeight ) if not self . text : logger . debug ( "*** wrap (%f, %f) needed" , 0 , 0 ) return 0 , 0 width = availWidth self . splitIndex = self . text . splitInt... | Determine the rectangle this paragraph really needs . |
52,321 | def split ( self , availWidth , availHeight ) : logger . debug ( "*** split (%f, %f)" , availWidth , availHeight ) splitted = [ ] if self . splitIndex : text1 = self . text [ : self . splitIndex ] text2 = self . text [ self . splitIndex : ] p1 = Paragraph ( Text ( text1 ) , self . style , debug = self . debug ) p2 = Pa... | Split ourselves in two paragraphs . |
52,322 | def draw ( self ) : logger . debug ( "*** draw" ) if not self . text : return canvas = self . canv style = self . style canvas . saveState ( ) if self . debug : bw = 0.5 bc = Color ( 1 , 1 , 0 ) bg = Color ( 0.9 , 0.9 , 0.9 ) canvas . setStrokeColor ( bc ) canvas . setLineWidth ( bw ) canvas . setFillColor ( bg ) canva... | Render the content of the paragraph . |
52,323 | def showLogging ( debug = False ) : try : log_level = logging . WARN log_format = LOG_FORMAT_DEBUG if debug : log_level = logging . DEBUG logging . basicConfig ( level = log_level , format = log_format ) except : logging . basicConfig ( ) | Shortcut for enabling log dump |
52,324 | def parseFile ( self , srcFile , closeFile = False ) : try : result = self . parse ( srcFile . read ( ) ) finally : if closeFile : srcFile . close ( ) return result | Parses CSS file - like objects using the current cssBuilder . Use for external stylesheets . |
52,325 | def parse ( self , src ) : self . cssBuilder . beginStylesheet ( ) try : src = cssSpecial . cleanupCSS ( src ) try : src , stylesheet = self . _parseStylesheet ( src ) except self . ParseError as err : err . setFullCSSSource ( src ) raise finally : self . cssBuilder . endStylesheet ( ) return stylesheet | Parses CSS string source using the current cssBuilder . Use for embedded stylesheets . |
52,326 | def parseInline ( self , src ) : self . cssBuilder . beginInline ( ) try : try : src , properties = self . _parseDeclarationGroup ( src . strip ( ) , braces = False ) except self . ParseError as err : err . setFullCSSSource ( src , inline = True ) raise result = self . cssBuilder . inline ( properties ) finally : self ... | Parses CSS inline source string using the current cssBuilder . Use to parse a tag s sytle - like attribute . |
52,327 | def parseAttributes ( self , attributes = None , ** kwAttributes ) : attributes = attributes if attributes is not None else { } if attributes : kwAttributes . update ( attributes ) self . cssBuilder . beginInline ( ) try : properties = [ ] try : for propertyName , src in six . iteritems ( kwAttributes ) : src , propert... | Parses CSS attribute source strings and return as an inline stylesheet . Use to parse a tag s highly CSS - based attributes like font . |
52,328 | def parseSingleAttr ( self , attrValue ) : results = self . parseAttributes ( temp = attrValue ) if 'temp' in results [ 1 ] : return results [ 1 ] [ 'temp' ] else : return results [ 0 ] [ 'temp' ] | Parse a single CSS attribute source string and returns the built CSS expression . Use to parse a tag s highly CSS - based attributes like font . |
52,329 | def _parseAtFrame ( self , src ) : src = src [ len ( '@frame ' ) : ] . lstrip ( ) box , src = self . _getIdent ( src ) src , properties = self . _parseDeclarationGroup ( src . lstrip ( ) ) result = [ self . cssBuilder . atFrame ( box , properties ) ] return src . lstrip ( ) , result | XXX Proprietary for PDF |
52,330 | def ErrorMsg ( ) : import traceback limit = None _type , value , tb = sys . exc_info ( ) _list = traceback . format_tb ( tb , limit ) + traceback . format_exception_only ( _type , value ) return "Traceback (innermost last):\n" + "%-20s %s" % ( " " . join ( _list [ : - 1 ] ) , _list [ - 1 ] ) | Helper to get a nice traceback as string |
52,331 | def transform_attrs ( obj , keys , container , func , extras = None ) : cpextras = extras for reportlab , css in keys : extras = cpextras if extras is None : extras = [ ] elif not isinstance ( extras , list ) : extras = [ extras ] if css in container : extras . insert ( 0 , container [ css ] ) setattr ( obj , reportlab... | Allows to apply one function to set of keys cheching if key is in container also trasform ccs key to report lab keys . |
52,332 | def copy_attrs ( obj1 , obj2 , attrs ) : for attr in attrs : value = getattr ( obj2 , attr ) if hasattr ( obj2 , attr ) else None if value is None and isinstance ( obj2 , dict ) and attr in obj2 : value = obj2 [ attr ] setattr ( obj1 , attr , value ) | Allows copy a list of attributes from object2 to object1 . Useful for copy ccs attributes to fragment |
52,333 | def set_value ( obj , attrs , value , _copy = False ) : for attr in attrs : if _copy : value = copy ( value ) setattr ( obj , attr , value ) | Allows set the same value to a list of attributes |
52,334 | def getColor ( value , default = None ) : if isinstance ( value , Color ) : return value value = str ( value ) . strip ( ) . lower ( ) if value == "transparent" or value == "none" : return default if value in COLOR_BY_NAME : return COLOR_BY_NAME [ value ] if value . startswith ( "#" ) and len ( value ) == 4 : value = "... | Convert to color value . This returns a Color object instance from a text bit . |
52,335 | def getCoords ( x , y , w , h , pagesize ) : ax , ay = pagesize if x < 0 : x = ax + x if y < 0 : y = ay + y if w is not None and h is not None : if w <= 0 : w = ( ax - x + w ) if h <= 0 : h = ( ay - y + h ) return x , ( ay - y - h ) , w , h return x , ( ay - y ) | As a stupid programmer I like to use the upper left corner of the document as the 0 0 coords therefore we need to do some fancy calculations |
52,336 | def getFrameDimensions ( data , page_width , page_height ) : box = data . get ( "-pdf-frame-box" , [ ] ) if len ( box ) == 4 : return [ getSize ( x ) for x in box ] top = getSize ( data . get ( "top" , 0 ) ) left = getSize ( data . get ( "left" , 0 ) ) bottom = getSize ( data . get ( "bottom" , 0 ) ) right = getSize ( ... | Calculate dimensions of a frame |
52,337 | def getPos ( position , pagesize ) : position = str ( position ) . split ( ) if len ( position ) != 2 : raise Exception ( "position not defined right way" ) x , y = [ getSize ( pos ) for pos in position ] return getCoords ( x , y , None , None , pagesize ) | Pair of coordinates |
52,338 | def makeTempFile ( self ) : if self . strategy == 0 : try : new_delegate = self . STRATEGIES [ 1 ] ( ) new_delegate . write ( self . getvalue ( ) ) self . _delegate = new_delegate self . strategy = 1 log . warn ( "Created temporary file %s" , self . name ) except : self . capacity = - 1 | Switch to next startegy . If an error occured stay with the first strategy |
52,339 | def getvalue ( self ) : if self . strategy == 0 : return self . _delegate . getvalue ( ) self . _delegate . flush ( ) self . _delegate . seek ( 0 ) value = self . _delegate . read ( ) if not isinstance ( value , six . binary_type ) : value = value . encode ( 'utf-8' ) return value | Get value of file . Work around for second strategy . Always returns bytes |
52,340 | def write ( self , value ) : if self . capacity > 0 and self . strategy == 0 : len_value = len ( value ) if len_value >= self . capacity : needs_new_strategy = True else : self . seek ( 0 , 2 ) needs_new_strategy = ( self . tell ( ) + len_value ) >= self . capacity if needs_new_strategy : self . makeTempFile ( ) if not... | If capacity ! = - 1 and length of file > capacity it is time to switch |
52,341 | def setMimeTypeByName ( self , name ) : " Guess the mime type " mimetype = mimetypes . guess_type ( name ) [ 0 ] if mimetype is not None : self . mimetype = mimetypes . guess_type ( name ) [ 0 ] . split ( ";" ) [ 0 ] | Guess the mime type |
52,342 | def _sameFrag ( f , g ) : if ( hasattr ( f , 'cbDefn' ) or hasattr ( g , 'cbDefn' ) or hasattr ( f , 'lineBreak' ) or hasattr ( g , 'lineBreak' ) ) : return 0 for a in ( 'fontName' , 'fontSize' , 'textColor' , 'backColor' , 'rise' , 'underline' , 'strike' , 'link' ) : if getattr ( f , a , None ) != getattr ( g , a , No... | returns 1 if two ParaFrags map out the same |
52,343 | def _drawBullet ( canvas , offset , cur_y , bulletText , style ) : tx2 = canvas . beginText ( style . bulletIndent , cur_y + getattr ( style , "bulletOffsetY" , 0 ) ) tx2 . setFont ( style . bulletFontName , style . bulletFontSize ) tx2 . setFillColor ( hasattr ( style , 'bulletColor' ) and style . bulletColor or style... | draw a bullet text could be a simple string or a frag list |
52,344 | def splitLines0 ( frags , widths ) : lineNum = 0 maxW = widths [ lineNum ] i = - 1 l = len ( frags ) lim = start = 0 text = frags [ 0 ] while 1 : while i < l : while start < lim and text [ start ] == ' ' : start += 1 if start == lim : i += 1 if i == l : break start = 0 f = frags [ i ] text = f . text lim = len ( text )... | given a list of ParaFrags we return a list of ParaLines |
52,345 | def cjkFragSplit ( frags , maxWidths , calcBounds , encoding = 'utf8' ) : from reportlab . rl_config import _FUZZ U = [ ] for f in frags : text = f . text if not isinstance ( text , unicode ) : text = text . decode ( encoding ) if text : U . extend ( [ cjkU ( t , f , encoding ) for t in text ] ) else : U . append ( cjk... | This attempts to be wordSplit for frags using the dumb algorithm |
52,346 | def minWidth ( self ) : frags = self . frags nFrags = len ( frags ) if not nFrags : return 0 if nFrags == 1 : f = frags [ 0 ] fS = f . fontSize fN = f . fontName words = hasattr ( f , 'text' ) and split ( f . text , ' ' ) or f . words func = lambda w , fS = fS , fN = fN : stringWidth ( w , fN , fS ) else : words = _get... | Attempt to determine a minimum sensible width |
52,347 | def breakLinesCJK ( self , width ) : if self . debug : print ( id ( self ) , "breakLinesCJK" ) if not isinstance ( width , ( list , tuple ) ) : maxWidths = [ width ] else : maxWidths = width style = self . style _handleBulletWidth ( self . bulletText , style , maxWidths ) if len ( self . frags ) > 1 : autoLeading = get... | Initially the dumbest possible wrapping algorithm . Cannot handle font variations . |
52,348 | def getPlainText ( self , identify = None ) : frags = getattr ( self , 'frags' , None ) if frags : plains = [ ] for frag in frags : if hasattr ( frag , 'text' ) : plains . append ( frag . text ) return '' . join ( plains ) elif identify : text = getattr ( self , 'text' , None ) if text is None : text = repr ( self ) re... | Convenience function for templates which want access to the raw text without XML tags . |
52,349 | def getActualLineWidths0 ( self ) : assert hasattr ( self , 'width' ) , "Cannot call this method before wrap()" if self . blPara . kind : func = lambda frag , w = self . width : w - frag . extraSpace else : func = lambda frag , w = self . width : w - frag [ 0 ] return map ( func , self . blPara . lines ) | Convenience function ; tells you how wide each line actually is . For justified styles this will be the same as the wrap width ; for others it might be useful for seeing if paragraphs will fit in spaces . |
52,350 | def link_callback ( uri , rel ) : sUrl = settings . STATIC_URL sRoot = settings . STATIC_ROOT mUrl = settings . MEDIA_URL mRoot = settings . MEDIA_ROOT if uri . startswith ( mUrl ) : path = os . path . join ( mRoot , uri . replace ( mUrl , "" ) ) elif uri . startswith ( sUrl ) : path = os . path . join ( sRoot , uri . ... | Convert HTML URIs to absolute system paths so xhtml2pdf can access those resources |
52,351 | def start ( ) : setupdir = dirname ( dirname ( __file__ ) ) curdir = os . getcwd ( ) if len ( sys . argv ) > 1 : configfile = sys . argv [ 1 ] elif exists ( join ( setupdir , "setup.py" ) ) : configfile = join ( setupdir , "dev.cfg" ) elif exists ( join ( curdir , "prod.cfg" ) ) : configfile = join ( curdir , "prod.cfg... | Start the CherryPy application server . |
52,352 | def mergeStyles ( self , styles ) : " XXX Bugfix for use in PISA " for k , v in six . iteritems ( styles ) : if k in self and self [ k ] : self [ k ] = copy . copy ( self [ k ] ) self [ k ] . update ( v ) else : self [ k ] = v | XXX Bugfix for use in PISA |
52,353 | def atPage ( self , page , pseudopage , declarations ) : return self . ruleset ( [ self . selector ( '*' ) ] , declarations ) | This is overriden by xhtml2pdf . context . pisaCSSBuilder |
52,354 | def handle_nextPageTemplate ( self , pt ) : has_left_template = self . _has_template_for_name ( pt + '_left' ) has_right_template = self . _has_template_for_name ( pt + '_right' ) if has_left_template and has_right_template : pt = [ pt + '_left' , pt + '_right' ] if isinstance ( pt , str ) : if hasattr ( self , '_nextP... | if pt has also templates for even and odd page convert it to list |
52,355 | def getRGBData ( self ) : "Return byte array of RGB data as string" if self . _data is None : self . _dataA = None if sys . platform [ 0 : 4 ] == 'java' : import jarray from java . awt . image import PixelGrabber width , height = self . getSize ( ) buffer = jarray . zeros ( width * height , 'i' ) pg = PixelGrabber ( se... | Return byte array of RGB data as string |
52,356 | def wrap ( self , availWidth , availHeight ) : " This can be called more than once! Do not overwrite important data like drawWidth " availHeight = self . setMaxHeight ( availHeight ) width = min ( self . drawWidth , availWidth ) wfactor = float ( width ) / self . drawWidth height = min ( self . drawHeight , availHeight... | This can be called more than once! Do not overwrite important data like drawWidth |
52,357 | def _normWidth ( self , w , maxw ) : if type ( w ) == type ( "" ) : w = ( ( maxw / 100.0 ) * float ( w [ : - 1 ] ) ) elif ( w is None ) or ( w == "*" ) : w = maxw return min ( w , maxw ) | Helper for calculating percentages |
52,358 | def wrap ( self , availWidth , availHeight ) : widths = ( availWidth - self . rightColumnWidth , self . rightColumnWidth ) if len ( self . _lastEntries ) == 0 : _tempEntries = [ ( 0 , 'Placeholder for table of contents' , 0 ) ] else : _tempEntries = self . _lastEntries lastMargin = 0 tableData = [ ] tableStyle = [ ( 'V... | All table properties should be known by now . |
52,359 | def _spawn_child ( self , command , args = None , timeout = shutit_global . shutit_global_object . default_timeout , maxread = 2000 , searchwindowsize = None , env = None , ignore_sighup = False , echo = True , preexec_fn = None , encoding = None , codec_errors = 'strict' , dimensions = None , delaybeforesend = shutit_... | spawn a child and manage the delaybefore send setting to 0 |
52,360 | def sendline ( self , sendspec ) : assert not sendspec . started , shutit_util . print_debug ( ) shutit = self . shutit shutit . log ( 'Sending in pexpect session (' + str ( id ( self ) ) + '): ' + str ( sendspec . send ) , level = logging . DEBUG ) if sendspec . expect : shutit . log ( 'Expecting: ' + str ( sendspec .... | Sends line handling background and newline directives . |
52,361 | def wait ( self , cadence = 2 , sendspec = None ) : shutit = self . shutit shutit . log ( 'In wait.' , level = logging . DEBUG ) if sendspec : cadence = sendspec . wait_cadence shutit . log ( 'Login stack is:\n' + str ( self . login_stack ) , level = logging . DEBUG ) while True : res , res_str , background_object = se... | Does not return until all background commands are completed . |
52,362 | def expect ( self , expect , searchwindowsize = None , maxread = None , timeout = None , iteration_n = 1 ) : if isinstance ( expect , str ) : expect = [ expect ] if searchwindowsize != None : old_searchwindowsize = self . pexpect_child . searchwindowsize self . pexpect_child . searchwindowsize = searchwindowsize if max... | Handle child expects with EOF and TIMEOUT handled |
52,363 | def replace_container ( self , new_target_image_name , go_home = None ) : shutit = self . shutit shutit . log ( 'Replacing container with ' + new_target_image_name + ', please wait...' , level = logging . DEBUG ) shutit . log ( shutit . print_session_state ( ) , level = logging . DEBUG ) conn_module = None for mod in s... | Replaces a container . Assumes we are in Docker context . |
52,364 | def whoami ( self , note = None , loglevel = logging . DEBUG ) : shutit = self . shutit shutit . handle_note ( note ) res = self . send_and_get_output ( ' command whoami' , echo = False , loglevel = loglevel ) . strip ( ) if res == '' : res = self . send_and_get_output ( ' command id -u -n' , echo = False , loglevel = ... | Returns the current user by executing whoami . |
52,365 | def check_last_exit_values ( self , send , check_exit = True , expect = None , exit_values = None , retry = 0 , retbool = False ) : shutit = self . shutit expect = expect or self . default_expect if not self . check_exit or not check_exit : shutit . log ( 'check_exit configured off, returning' , level = logging . DEBUG... | Internal function to check the exit value of the shell . Do not use . |
52,366 | def get_file_perms ( self , filename , note = None , loglevel = logging . DEBUG ) : shutit = self . shutit shutit . handle_note ( note ) cmd = ' command stat -c %a ' + filename self . send ( ShutItSendSpec ( self , send = ' ' + cmd , check_exit = False , echo = False , loglevel = loglevel , ignore_background = True ) )... | Returns the permissions of the file on the target as an octal string triplet . |
52,367 | def is_user_id_available ( self , user_id , note = None , loglevel = logging . DEBUG ) : shutit = self . shutit shutit . handle_note ( note ) self . send ( ShutItSendSpec ( self , send = ' command cut -d: -f3 /etc/paswd | grep -w ^' + user_id + '$ | wc -l' , expect = self . default_expect , echo = False , loglevel = lo... | Determine whether the specified user_id available . |
52,368 | def lsb_release ( self , loglevel = logging . DEBUG ) : shutit = self . shutit d = { } self . send ( ShutItSendSpec ( self , send = ' command lsb_release -a' , check_exit = False , echo = False , loglevel = loglevel , ignore_background = True ) ) res = shutit . match_string ( self . pexpect_child . before , r'^Distribu... | Get distro information from lsb_release . |
52,369 | def user_exists ( self , user , note = None , loglevel = logging . DEBUG ) : shutit = self . shutit shutit . handle_note ( note ) exists = False if user == '' : return exists ret = self . send ( ShutItSendSpec ( self , send = ' command id %s && echo E""XIST || echo N""XIST' % user , expect = [ 'NXIST' , 'EXIST' ] , ech... | Returns true if the specified username exists . |
52,370 | def quick_send ( self , send , echo = None , loglevel = logging . INFO ) : shutit = self . shutit shutit . log ( 'Quick send: ' + send , level = loglevel ) res = self . sendline ( ShutItSendSpec ( self , send = send , check_exit = False , echo = echo , fail_on_empty_before = False , record_command = False , ignore_back... | Quick and dirty send that ignores background tasks . Intended for internal use . |
52,371 | def _create_command_file ( self , expect , send ) : shutit = self . shutit random_id = shutit_util . random_id ( ) fname = shutit_global . shutit_global_object . shutit_state_dir + '/tmp_' + random_id working_str = send assert not self . sendline ( ShutItSendSpec ( self , send = ' truncate -s 0 ' + fname , ignore_backg... | Internal function . Do not use . |
52,372 | def check_dependee_order ( depender , dependee , dependee_id ) : shutit_global . shutit_global_object . yield_to_draw ( ) if dependee . run_order > depender . run_order : return 'depender module id:\n\n' + depender . module_id + '\n\n(run order: ' + str ( depender . run_order ) + ') ' + 'depends on dependee module_id:\... | Checks whether run orders are in the appropriate order . |
52,373 | def make_dep_graph ( depender ) : shutit_global . shutit_global_object . yield_to_draw ( ) digraph = '' for dependee_id in depender . depends_on : digraph = ( digraph + '"' + depender . module_id + '"->"' + dependee_id + '";\n' ) return digraph | Returns a digraph string fragment based on the passed - in module |
52,374 | def get_config_set ( self , section , option ) : values = set ( ) for cp , filename , fp in self . layers : filename = filename fp = fp if cp . has_option ( section , option ) : values . add ( cp . get ( section , option ) ) return values | Returns a set with each value per config file in it . |
52,375 | def reload ( self ) : oldlayers = self . layers self . layers = [ ] for cp , filename , fp in oldlayers : cp = cp if fp is None : self . read ( filename ) else : self . readfp ( fp , filename ) | Re - reads all layers again . In theory this should overwrite all the old values with any newer ones . It assumes we never delete a config item before reload . |
52,376 | def get_shutit_pexpect_session_environment ( self , environment_id ) : if not isinstance ( environment_id , str ) : self . fail ( 'Wrong argument type in get_shutit_pexpect_session_environment' ) for env in shutit_global . shutit_global_object . shutit_pexpect_session_environments : if env . environment_id == environme... | Returns the first shutit_pexpect_session object related to the given environment - id |
52,377 | def get_current_shutit_pexpect_session_environment ( self , note = None ) : self . handle_note ( note ) current_session = self . get_current_shutit_pexpect_session ( ) if current_session is not None : res = current_session . current_environment else : res = None self . handle_note_after ( note ) return res | Returns the current environment from the currently - set default pexpect child . |
52,378 | def get_current_shutit_pexpect_session ( self , note = None ) : self . handle_note ( note ) res = self . current_shutit_pexpect_session self . handle_note_after ( note ) return res | Returns the currently - set default pexpect child . |
52,379 | def get_shutit_pexpect_sessions ( self , note = None ) : self . handle_note ( note ) sessions = [ ] for key in self . shutit_pexpect_sessions : sessions . append ( shutit_object . shutit_pexpect_sessions [ key ] ) self . handle_note_after ( note ) return sessions | Returns all the shutit_pexpect_session keys for this object . |
52,380 | def set_default_shutit_pexpect_session ( self , shutit_pexpect_session ) : assert isinstance ( shutit_pexpect_session , ShutItPexpectSession ) , shutit_util . print_debug ( ) self . current_shutit_pexpect_session = shutit_pexpect_session return True | Sets the default pexpect child . |
52,381 | def fail ( self , msg , shutit_pexpect_child = None , throw_exception = False ) : shutit_global . shutit_global_object . yield_to_draw ( ) if shutit_pexpect_child is not None : shutit_pexpect_session = self . get_shutit_pexpect_session_from_child ( shutit_pexpect_child ) shutit_util . print_debug ( sys . exc_info ( ) )... | Handles a failure pausing if a pexpect child object is passed in . |
52,382 | def get_current_environment ( self , note = None ) : shutit_global . shutit_global_object . yield_to_draw ( ) self . handle_note ( note ) res = self . get_current_shutit_pexpect_session_environment ( ) . environment_id self . handle_note_after ( note ) return res | Returns the current environment id from the current shutit_pexpect_session |
52,383 | def handle_note ( self , note , command = '' , training_input = '' ) : shutit_global . shutit_global_object . yield_to_draw ( ) if self . build [ 'walkthrough' ] and note != None and note != '' : assert isinstance ( note , str ) , shutit_util . print_debug ( ) wait = self . build [ 'walkthrough_wait' ] wrap = '\n' + 80... | Handle notes and walkthrough option . |
52,384 | def expect_allow_interrupt ( self , shutit_pexpect_child , expect , timeout , iteration_s = 1 ) : shutit_global . shutit_global_object . yield_to_draw ( ) shutit_pexpect_session = self . get_shutit_pexpect_session_from_child ( shutit_pexpect_child ) accum_timeout = 0 if isinstance ( expect , str ) : expect = [ expect ]... | This function allows you to interrupt the run at more or less any point by breaking up the timeout into interactive chunks . |
52,385 | def send_host_file ( self , path , hostfilepath , expect = None , shutit_pexpect_child = None , note = None , user = None , group = None , loglevel = logging . INFO ) : shutit_global . shutit_global_object . yield_to_draw ( ) shutit_pexpect_child = shutit_pexpect_child or self . get_current_shutit_pexpect_session ( ) .... | Send file from host machine to given path |
52,386 | def send_host_dir ( self , path , hostfilepath , expect = None , shutit_pexpect_child = None , note = None , user = None , group = None , loglevel = logging . DEBUG ) : shutit_global . shutit_global_object . yield_to_draw ( ) shutit_pexpect_child = shutit_pexpect_child or self . get_current_shutit_pexpect_session ( ) .... | Send directory and all contents recursively from host machine to given path . It will automatically make directories on the target . |
52,387 | def delete_text ( self , text , fname , pattern = None , expect = None , shutit_pexpect_child = None , note = None , before = False , force = False , line_oriented = True , loglevel = logging . DEBUG ) : shutit_global . shutit_global_object . yield_to_draw ( ) return self . change_text ( text , fname , pattern , expect... | Delete a chunk of text from a file . See insert_text . |
52,388 | def get_file ( self , target_path , host_path , note = None , loglevel = logging . DEBUG ) : shutit_global . shutit_global_object . yield_to_draw ( ) self . handle_note ( note ) if self . build [ 'delivery' ] != 'docker' : return False shutit_pexpect_child = self . get_shutit_pexpect_session_from_id ( 'host_child' ) . ... | Copy a file from the target machine to the host machine |
52,389 | def prompt_cfg ( self , msg , sec , name , ispass = False ) : shutit_global . shutit_global_object . yield_to_draw ( ) cfgstr = '[%s]/%s' % ( sec , name ) config_parser = self . config_parser usercfg = os . path . join ( self . host [ 'shutit_path' ] , 'config' ) self . log ( '\nPROMPTING FOR CONFIG: %s' % ( cfgstr , )... | Prompt for a config value optionally saving it to the user - level cfg . Only runs if we are in an interactive mode . |
52,390 | def step_through ( self , msg = '' , shutit_pexpect_child = None , level = 1 , print_input = True , value = True ) : shutit_global . shutit_global_object . yield_to_draw ( ) shutit_pexpect_child = shutit_pexpect_child or self . get_current_shutit_pexpect_session ( ) . pexpect_child shutit_pexpect_session = self . get_s... | Implements a step - through function using pause_point . |
52,391 | def interact ( self , msg = 'SHUTIT PAUSE POINT' , shutit_pexpect_child = None , print_input = True , level = 1 , resize = True , color = '32' , default_msg = None , wait = - 1 ) : shutit_global . shutit_global_object . yield_to_draw ( ) self . pause_point ( msg = msg , shutit_pexpect_child = shutit_pexpect_child , pri... | Same as pause_point but sets up the terminal ready for unmediated interaction . |
52,392 | def pause_point ( self , msg = 'SHUTIT PAUSE POINT' , shutit_pexpect_child = None , print_input = True , level = 1 , resize = True , color = '32' , default_msg = None , interact = False , wait = - 1 ) : shutit_global . shutit_global_object . yield_to_draw ( ) if ( not shutit_global . shutit_global_object . determine_in... | Inserts a pause in the build session which allows the user to try things out before continuing . Ignored if we are not in an interactive mode or the interactive level is less than the passed - in one . Designed to help debug the build or drop to on failure so the situation can be debugged . |
52,393 | def login ( self , command = 'su -' , user = None , password = None , prompt_prefix = None , expect = None , timeout = shutit_global . shutit_global_object . default_timeout , escape = False , echo = None , note = None , go_home = True , fail_on_fail = True , is_ssh = True , check_sudo = True , loglevel = logging . DEB... | Logs user in on default child . |
52,394 | def logout_all ( self , command = 'exit' , note = None , echo = None , timeout = shutit_global . shutit_global_object . default_timeout , nonewline = False , loglevel = logging . DEBUG ) : shutit_global . shutit_global_object . yield_to_draw ( ) for key in self . shutit_pexpect_sessions : shutit_pexpect_session = self ... | Logs the user out of all pexpect sessions within this ShutIt object . |
52,395 | def push_repository ( self , repository , docker_executable = 'docker' , shutit_pexpect_child = None , expect = None , note = None , loglevel = logging . INFO ) : shutit_global . shutit_global_object . yield_to_draw ( ) self . handle_note ( note ) shutit_pexpect_child = shutit_pexpect_child or self . get_shutit_pexpect... | Pushes the repository . |
52,396 | def get_emailer ( self , cfg_section ) : shutit_global . shutit_global_object . yield_to_draw ( ) import emailer return emailer . Emailer ( cfg_section , self ) | Sends an email using the mailer |
52,397 | def get_shutit_pexpect_session_id ( self , shutit_pexpect_child ) : shutit_global . shutit_global_object . yield_to_draw ( ) if not isinstance ( shutit_pexpect_child , pexpect . pty_spawn . spawn ) : self . fail ( 'Wrong type in get_shutit_pexpect_session_id' , throw_exception = True ) for key in self . shutit_pexpect_... | Given a pexpect child object return the shutit_pexpect_session_id object . |
52,398 | def get_shutit_pexpect_session_from_id ( self , shutit_pexpect_id ) : shutit_global . shutit_global_object . yield_to_draw ( ) for key in self . shutit_pexpect_sessions : if self . shutit_pexpect_sessions [ key ] . pexpect_session_id == shutit_pexpect_id : return self . shutit_pexpect_sessions [ key ] return self . fai... | Get the pexpect session from the given identifier . |
52,399 | def get_commands ( self ) : shutit_global . shutit_global_object . yield_to_draw ( ) s = '' for c in self . build [ 'shutit_command_history' ] : if isinstance ( c , str ) : if c and c [ 0 ] != ' ' : s += c + '\n' return s | Gets command that have been run and have not been redacted . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.