idx
int64
0
252k
question
stringlengths
48
5.28k
target
stringlengths
5
1.23k
241,200
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
241,201
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
241,202
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
241,203
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
241,204
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
241,205
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
241,206
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
241,207
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
241,208
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
241,209
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
241,210
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
241,211
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
241,212
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 .
241,213
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 .
241,214
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 .
241,215
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
241,216
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 .
241,217
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
241,218
def atPage ( self , page , pseudopage , declarations ) : return self . ruleset ( [ self . selector ( '*' ) ] , declarations )
This is overriden by xhtml2pdf . context . pisaCSSBuilder
241,219
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
241,220
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
241,221
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
241,222
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
241,223
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 .
241,224
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
241,225
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 .
241,226
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 .
241,227
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
241,228
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 .
241,229
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 .
241,230
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 .
241,231
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 .
241,232
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 .
241,233
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 .
241,234
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 .
241,235
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 .
241,236
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 .
241,237
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 .
241,238
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
241,239
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 .
241,240
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 .
241,241
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
241,242
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 .
241,243
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 .
241,244
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 .
241,245
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 .
241,246
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 .
241,247
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
241,248
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 .
241,249
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 .
241,250
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
241,251
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 .
241,252
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 .
241,253
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
241,254
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 .
241,255
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 .
241,256
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 .
241,257
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 .
241,258
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 .
241,259
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 .
241,260
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 .
241,261
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
241,262
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 .
241,263
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 .
241,264
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 .
241,265
def build_report ( self , msg = '' ) : shutit_global . shutit_global_object . yield_to_draw ( ) s = '\n' s += '################################################################################\n' s += '# COMMAND HISTORY BEGIN ' + shutit_global . shutit_global_object . build_id + '\n' s += self . get_commands ( ) s += '#...
Resposible for constructing a report to be output as part of the build . Returns report as a string .
241,266
def match_string ( self , string_to_match , regexp ) : shutit_global . shutit_global_object . yield_to_draw ( ) if not isinstance ( string_to_match , str ) : return None lines = string_to_match . split ( '\r\n' ) new_lines = [ ] for line in lines : new_lines = new_lines + line . split ( '\r' ) for line in lines : new_l...
Get regular expression from the first of the lines passed in in string that matched . Handles first group of regexp as a return value .
241,267
def is_to_be_built_or_is_installed ( self , shutit_module_obj ) : shutit_global . shutit_global_object . yield_to_draw ( ) cfg = self . cfg if cfg [ shutit_module_obj . module_id ] [ 'shutit.core.module.build' ] : return True return self . is_installed ( shutit_module_obj )
Returns true if this module is configured to be built or if it is already installed .
241,268
def is_installed ( self , shutit_module_obj ) : shutit_global . shutit_global_object . yield_to_draw ( ) if shutit_module_obj . module_id in self . get_current_shutit_pexpect_session_environment ( ) . modules_installed : return True if shutit_module_obj . module_id in self . get_current_shutit_pexpect_session_environme...
Returns true if this module is installed . Uses cache where possible .
241,269
def allowed_image ( self , module_id ) : shutit_global . shutit_global_object . yield_to_draw ( ) self . log ( "In allowed_image: " + module_id , level = logging . DEBUG ) cfg = self . cfg if self . build [ 'ignoreimage' ] : self . log ( "ignoreimage == true, returning true" + module_id , level = logging . DEBUG ) retu...
Given a module id determine whether the image is allowed to be built .
241,270
def print_modules ( self ) : shutit_global . shutit_global_object . yield_to_draw ( ) cfg = self . cfg module_string = '' module_string += 'Modules: \n' module_string += ' Run order Build Remove Module ID\n' for module_id in self . module_ids ( ) : module_string += ' ' + str ( self . shutit_map [ module_...
Returns a string table representing the modules in the ShutIt module map .
241,271
def load_shutit_modules ( self ) : shutit_global . shutit_global_object . yield_to_draw ( ) if self . loglevel <= logging . DEBUG : self . log ( 'ShutIt module paths now: ' , level = logging . DEBUG ) self . log ( self . host [ 'shutit_module_path' ] , level = logging . DEBUG ) for shutit_module_path in self . host [ '...
Responsible for loading the shutit modules based on the configured module paths .
241,272
def get_command ( self , command ) : shutit_global . shutit_global_object . yield_to_draw ( ) if command in ( 'md5sum' , 'sed' , 'head' ) : if self . get_current_shutit_pexpect_session_environment ( ) . distro == 'osx' : return 'g' + command return command
Helper function for osx - return gnu utils rather than default for eg head and md5sum where possible and needed .
241,273
def get_send_command ( self , send ) : shutit_global . shutit_global_object . yield_to_draw ( ) if send is None : return send cmd_arr = send . split ( ) if cmd_arr and cmd_arr [ 0 ] in ( 'md5sum' , 'sed' , 'head' ) : newcmd = self . get_command ( cmd_arr [ 0 ] ) send = send . replace ( cmd_arr [ 0 ] , newcmd ) return s...
Internal helper function to get command that s really sent
241,274
def load_configs ( self ) : shutit_global . shutit_global_object . yield_to_draw ( ) configs = [ ( 'defaults' , StringIO ( default_cnf ) ) , os . path . expanduser ( '~/.shutit/config' ) , os . path . join ( self . host [ 'shutit_path' ] , 'config' ) , 'configs/build.cnf' ] for config_file_name in self . build [ 'extra...
Responsible for loading config files into ShutIt . Recurses down from configured shutit module paths .
241,275
def config_collection ( self ) : shutit_global . shutit_global_object . yield_to_draw ( ) self . log ( 'In config_collection' , level = logging . DEBUG ) cfg = self . cfg for module_id in self . module_ids ( ) : self . get_config ( module_id , 'shutit.core.module.build' , None , boolean = True , forcenone = True ) self...
Collect core config from config files for all seen modules .
241,276
def print_config ( self , cfg , hide_password = True , history = False , module_id = None ) : shutit_global . shutit_global_object . yield_to_draw ( ) cp = self . config_parser s = '' keys1 = list ( cfg . keys ( ) ) if keys1 : keys1 . sort ( ) for k in keys1 : if module_id is not None and k != module_id : continue if i...
Returns a string representing the config of this ShutIt run .
241,277
def process_args ( self , args ) : shutit_global . shutit_global_object . yield_to_draw ( ) assert isinstance ( args , ShutItInit ) , shutit_util . print_debug ( ) if args . action == 'version' : shutit_global . shutit_global_object . shutit_print ( 'ShutIt version: ' + shutit . shutit_version ) shutit_global . shutit_...
Process the args we have . args is always a ShutItInit object .
241,278
def check_deps ( self ) : shutit_global . shutit_global_object . yield_to_draw ( ) cfg = self . cfg self . log ( 'PHASE: dependencies' , level = logging . DEBUG ) self . pause_point ( '\nNow checking for dependencies between modules' , print_input = False , level = 3 ) to_build = [ self . shutit_map [ module_id ] for m...
Dependency checking phase is performed in this method .
241,279
def check_conflicts ( self ) : shutit_global . shutit_global_object . yield_to_draw ( ) cfg = self . cfg self . log ( 'PHASE: conflicts' , level = logging . DEBUG ) errs = [ ] self . pause_point ( '\nNow checking for conflicts between modules' , print_input = False , level = 3 ) for module_id in self . module_ids ( ) :...
Checks for any conflicts between modules configured to be built .
241,280
def do_remove ( self , loglevel = logging . DEBUG ) : shutit_global . shutit_global_object . yield_to_draw ( ) cfg = self . cfg self . log ( 'PHASE: remove' , level = loglevel ) self . pause_point ( '\nNow removing any modules that need removing' , print_input = False , level = 3 ) for module_id in self . module_ids ( ...
Remove modules by calling remove method on those configured for removal .
241,281
def do_build ( self ) : shutit_global . shutit_global_object . yield_to_draw ( ) cfg = self . cfg self . log ( 'PHASE: build, repository work' , level = logging . DEBUG ) module_id_list = self . module_ids ( ) if self . build [ 'deps_only' ] : module_id_list_build_only = filter ( lambda x : cfg [ x ] [ 'shutit.core.mod...
Runs build phase building any modules that we ve determined need building .
241,282
def stop_all ( self , run_order = - 1 ) : shutit_global . shutit_global_object . yield_to_draw ( ) for module_id in self . module_ids ( rev = True ) : shutit_module_obj = self . shutit_map [ module_id ] if run_order == - 1 or shutit_module_obj . run_order <= run_order : if self . is_installed ( shutit_module_obj ) : if...
Runs stop method on all modules less than the passed - in run_order . Used when target is exporting itself mid - build so we clean up state before committing run files etc .
241,283
def start_all ( self , run_order = - 1 ) : shutit_global . shutit_global_object . yield_to_draw ( ) for module_id in self . module_ids ( ) : shutit_module_obj = self . shutit_map [ module_id ] if run_order == - 1 or shutit_module_obj . run_order <= run_order : if self . is_installed ( shutit_module_obj ) : if not shuti...
Runs start method on all modules less than the passed - in run_order . Used when target is exporting itself mid - build so we can export a clean target and still depended - on modules running if necessary .
241,284
def init_shutit_map ( self ) : shutit_global . shutit_global_object . yield_to_draw ( ) modules = self . shutit_modules if len ( [ mod for mod in modules if mod . run_order > 0 ] ) < 1 : self . log ( modules , level = logging . DEBUG ) path = ':' . join ( self . host [ 'shutit_module_path' ] ) self . log ( '\nIf you ar...
Initializes the module map of shutit based on the modules we have gathered .
241,285
def conn_target ( self ) : shutit_global . shutit_global_object . yield_to_draw ( ) conn_module = None for mod in self . conn_modules : if mod . module_id == self . build [ 'conn_module' ] : conn_module = mod break if conn_module is None : self . fail ( 'Couldn\'t find conn_module ' + self . build [ 'conn_module' ] ) c...
Connect to the target .
241,286
def finalize_target ( self ) : shutit_global . shutit_global_object . yield_to_draw ( ) self . pause_point ( '\nFinalizing the target module (' + self . shutit_main_dir + '/shutit_setup.py)' , print_input = False , level = 3 ) for mod in self . conn_modules : if mod . module_id == self . build [ 'conn_module' ] : conn_...
Finalize the target using the core finalize method .
241,287
def resolve_dependencies ( self , to_build , depender ) : shutit_global . shutit_global_object . yield_to_draw ( ) self . log ( 'In resolve_dependencies' , level = logging . DEBUG ) cfg = self . cfg for dependee_id in depender . depends_on : dependee = self . shutit_map . get ( dependee_id ) if ( dependee and dependee ...
Add any required dependencies .
241,288
def check_dependee_exists ( self , depender , dependee , dependee_id ) : shutit_global . shutit_global_object . yield_to_draw ( ) if dependee is None : return 'module: \n\n' + dependee_id + '\n\nnot found in paths: ' + str ( self . host [ 'shutit_module_path' ] ) + ' but needed for ' + depender . module_id + '\nCheck y...
Checks whether a depended - on module is available .
241,289
def check_dependee_build ( self , depender , dependee , dependee_id ) : shutit_global . shutit_global_object . yield_to_draw ( ) cfg = self . cfg if not ( cfg [ dependee . module_id ] [ 'shutit.core.module.build' ] or self . is_to_be_built_or_is_installed ( dependee ) ) : return 'depender module id:\n\n[' + depender . ...
Checks whether a depended on module is configured to be built .
241,290
def destroy ( self ) : if self . session_type == 'bash' : self . logout ( ) elif self . session_type == 'vagrant' : self . logout ( )
Finish up a session .
241,291
def shutit_method_scope ( func ) : def wrapper ( self , shutit ) : ret = func ( self , shutit ) return ret return wrapper
Notifies the ShutIt object whenever we call a shutit module method . This allows setting values for the scope of a function .
241,292
def managing_thread_main_simple ( ) : import shutit_global last_msg = '' while True : printed_anything = False if shutit_global . shutit_global_object . log_trace_when_idle and time . time ( ) - shutit_global . shutit_global_object . last_log_time > 10 : this_msg = '' this_header = '' for thread_id , stack in sys . _cu...
Simpler thread to track whether main thread has been quiet for long enough that a thread dump should be printed .
241,293
def map_package ( shutit_pexpect_session , package , install_type ) : if package in PACKAGE_MAP . keys ( ) : for itype in PACKAGE_MAP [ package ] . keys ( ) : if itype == install_type : ret = PACKAGE_MAP [ package ] [ install_type ] if isinstance ( ret , str ) : return ret if callable ( ret ) : ret ( shutit_pexpect_ses...
If package mapping exists then return it else return package .
241,294
def is_file_secure ( file_name ) : if not os . path . isfile ( file_name ) : return True file_mode = os . stat ( file_name ) . st_mode if file_mode & ( stat . S_IRGRP | stat . S_IWGRP | stat . S_IXGRP | stat . S_IROTH | stat . S_IWOTH | stat . S_IXOTH ) : return False return True
Returns false if file is considered insecure true if secure . If file doesn t exist it s considered secure!
241,295
def random_id ( size = 8 , chars = string . ascii_letters + string . digits ) : return '' . join ( random . choice ( chars ) for _ in range ( size ) )
Generates a random string of given size from the given chars .
241,296
def random_word ( size = 6 ) : words = shutit_assets . get_words ( ) . splitlines ( ) word = '' while len ( word ) != size or "'" in word : word = words [ int ( random . random ( ) * ( len ( words ) - 1 ) ) ] return word . lower ( )
Returns a random word in lower case .
241,297
def ctrl_c_signal_handler ( _ , frame ) : global ctrl_c_calls ctrl_c_calls += 1 if ctrl_c_calls > 10 : shutit_global . shutit_global_object . handle_exit ( exit_code = 1 ) shutit_frame = get_shutit_frame ( frame ) if in_ctrlc : msg = 'CTRL-C hit twice, quitting' if shutit_frame : shutit_global . shutit_global_object . ...
CTRL - c signal handler - enters a pause point if it can .
241,298
def get_input ( msg , default = '' , valid = None , boolean = False , ispass = False , color = None ) : log_trace_when_idle_original_value = shutit_global . shutit_global_object . log_trace_when_idle shutit_global . shutit_global_object . log_trace_when_idle = False if boolean and valid is None : valid = ( 'yes' , 'y' ...
Gets input from the user and returns the answer .
241,299
def build ( self , shutit ) : target_child = self . start_container ( shutit , 'target_child' ) self . setup_host_child ( shutit ) self . setup_target_child ( shutit , target_child ) shutit . send ( 'chmod -R 777 ' + shutit_global . shutit_global_object . shutit_state_dir + ' && mkdir -p ' + shutit_global . shutit_glob...
Sets up the target ready for building .