signature
stringlengths
8
3.44k
body
stringlengths
0
1.41M
docstring
stringlengths
1
122k
id
stringlengths
5
17
@asyncio.coroutine<EOL><INDENT>def connect(self):<DEDENT>
if time.time() < self._login_cooldown:<EOL><INDENT>raise FailedToConnect("<STR_LIT>")<EOL><DEDENT>resp = yield from self.session.post("<STR_LIT>", headers = {<EOL>"<STR_LIT:Content-Type>": "<STR_LIT:application/json>",<EOL>"<STR_LIT>": self.appid,<EOL>"<STR_LIT>": "<STR_LIT>" + self.token<EOL>}, data=json.dumps({"<STR_LIT>": True}))<EOL>data = yield from resp.json()<EOL>if "<STR_LIT>" in data:<EOL><INDENT>self.key = data.get("<STR_LIT>")<EOL>self.sessionid = data.get("<STR_LIT>")<EOL>self.uncertain_spaceid = data.get("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>raise FailedToConnect<EOL><DEDENT>
|coro| Connect to ubisoft, automatically called when needed
f10342:c5:m3
@asyncio.coroutine<EOL><INDENT>def get_players(self, name=None, platform=None, uid=None):<DEDENT>
if name is None and uid is None:<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if name is not None and uid is not None:<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if platform is None:<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if "<STR_LIT>" not in self.cache: self.cache[platform] = {}<EOL>if name:<EOL><INDENT>cache_key = "<STR_LIT>" % name<EOL><DEDENT>else:<EOL><INDENT>cache_key = "<STR_LIT>" % uid<EOL><DEDENT>if cache_key in self.cache[platform]:<EOL><INDENT>if self.cachetime > <NUM_LIT:0> and self.cache[platform][cache_key][<NUM_LIT:0>] < time.time():<EOL><INDENT>del self.cache[platform][cache_key]<EOL><DEDENT>else:<EOL><INDENT>return self.cache[platform][cache_key][<NUM_LIT:1>]<EOL><DEDENT><DEDENT>if name:<EOL><INDENT>data = yield from self.get("<STR_LIT>" % (parse.quote(name), parse.quote(platform)))<EOL><DEDENT>else:<EOL><INDENT>data = yield from self.get("<STR_LIT>" % (uid, parse.quote(platform)))<EOL><DEDENT>if "<STR_LIT>" in data:<EOL><INDENT>results = [Player(self, x) for x in data["<STR_LIT>"] if x.get("<STR_LIT>", "<STR_LIT>") == platform]<EOL>if len(results) == <NUM_LIT:0>: raise InvalidRequest("<STR_LIT>")<EOL>if self.cachetime != <NUM_LIT:0>:<EOL><INDENT>self.cache[platform][cache_key] = [time.time() + self.cachetime, results]<EOL><DEDENT>return results<EOL><DEDENT>else:<EOL><INDENT>raise InvalidRequest("<STR_LIT>" % str(data))<EOL><DEDENT>
|coro| get a list of players matching the term on that platform, exactly one of uid and name must be given, platform must be given, this list almost always has only 1 element, so it's easier to use get_player Parameters ---------- name : str the name of the player you're searching for platform : str the name of the platform you're searching on (See :class:`Platforms`) uid : str the uid of the player you're searching for Returns ------- list[:class:`Player`] list of found players
f10342:c5:m5
@asyncio.coroutine<EOL><INDENT>def get_player(self, name=None, platform=None, uid=None):<DEDENT>
results = yield from self.get_players(name=name, platform=platform, uid=uid)<EOL>return results[<NUM_LIT:0>]<EOL>
|coro| Calls get_players and returns the first element, exactly one of uid and name must be given, platform must be given Parameters ---------- name : str the name of the player you're searching for platform : str the name of the platform you're searching on (See :class:`Platforms`) uid : str the uid of the player you're searching for Returns ------- :class:`Player` player found
f10342:c5:m6
@asyncio.coroutine<EOL><INDENT>def get_operator_definitions(self):<DEDENT>
if self._op_definitions is not None:<EOL><INDENT>return self._op_definitions<EOL><DEDENT>resp = yield from self.session.get("<STR_LIT>")<EOL>data = yield from resp.json()<EOL>self._op_definitions = data<EOL>return data<EOL>
|coro| Retrieves a list of information about operators - their badge, unique statistic, etc. Returns ------- dict operators
f10342:c5:m7
@asyncio.coroutine<EOL><INDENT>def get_operator_index(self, name):<DEDENT>
opdefs = yield from self.get_operator_definitions()<EOL>name = name.lower()<EOL>if name not in opdefs:<EOL><INDENT>return None<EOL><DEDENT>return opdefs[name]["<STR_LIT:index>"]<EOL>
|coro| Gets the operators index from the operator definitions dict Returns ------- str the operator index
f10342:c5:m8
@asyncio.coroutine<EOL><INDENT>def get_operator_statistic(self, name):<DEDENT>
opdefs = yield from self.get_operator_definitions()<EOL>name = name.lower()<EOL>if name not in opdefs:<EOL><INDENT>return None<EOL><DEDENT>if "<STR_LIT>" not in opdefs[name] or "<STR_LIT>" not in opdefs[name]["<STR_LIT>"]:<EOL><INDENT>return None<EOL><DEDENT>return opdefs[name]["<STR_LIT>"]["<STR_LIT>"]["<STR_LIT>"]<EOL>
|coro| Gets the operator unique statistic from the operator definitions dict Returns ------- str the name of the operator unique statistic
f10342:c5:m9
@asyncio.coroutine<EOL><INDENT>def get_operator_badge(self, name):<DEDENT>
opdefs = yield from self.get_operator_definitions()<EOL>name = name.lower()<EOL>if name not in opdefs:<EOL><INDENT>return None<EOL><DEDENT>badge = opdefs[name]["<STR_LIT>"]<EOL>if not badge.startswith("<STR_LIT:http>"):<EOL><INDENT>badge = "<STR_LIT>" + badge<EOL><DEDENT>return badge<EOL>
|coro| Gets the operator badge URL Returns ------- str the operators badge URL
f10342:c5:m10
@asyncio.coroutine<EOL><INDENT>def get_definitions(self):<DEDENT>
if self._definitions is not None:<EOL><INDENT>return self._definitions<EOL><DEDENT>resp = yield from self.session.get("<STR_LIT>")<EOL>data = yield from resp.json()<EOL>self._definitions = data<EOL>return data<EOL>
|coro| Retrieves the list of api definitions, downloading it from Ubisoft if it hasn't been fetched all ready Primarily for internal use, but could contain useful information. Returns ------- dict definitions
f10342:c5:m11
@asyncio.coroutine<EOL><INDENT>def get_object_index(self, key):<DEDENT>
defns = yield from self.get_definitions()<EOL>for x in defns:<EOL><INDENT>if key in x and "<STR_LIT>" in defns[x]:<EOL><INDENT>return defns[x]["<STR_LIT>"]<EOL><DEDENT><DEDENT>return None<EOL>
|coro| Mainly for internal use with get_operator, returns the "location" index for the key in the definitions Returns ------- str the object's location index
f10342:c5:m12
def get_icon_url(self):
return self.RANK_ICONS[self.rank_id]<EOL>
Get URL for this rank's icon Returns ------- :class:`str` the URL for the rank icon
f10342:c6:m3
def get_charm_url(self):
if self.rank_id <= <NUM_LIT:4>: return self.RANK_CHARMS[<NUM_LIT:0>]<EOL>if self.rank_id <= <NUM_LIT:8>: return self.RANK_CHARMS[<NUM_LIT:1>]<EOL>if self.rank_id <= <NUM_LIT:12>: return self.RANK_CHARMS[<NUM_LIT:2>]<EOL>if self.rank_id <= <NUM_LIT:16>: return self.RANK_CHARMS[<NUM_LIT:3>]<EOL>if self.rank_id <= <NUM_LIT>: return self.RANK_CHARMS[<NUM_LIT:4>]<EOL>return self.RANK_CHARMS[<NUM_LIT:5>]<EOL>
Get charm URL for the bracket this rank is in Returns ------- :class:`str` the URL for the charm
f10342:c6:m4
def get_bracket(self):
return Rank.bracket_from_rank(self.rank_id)<EOL>
Get rank bracket Returns ------- :class:`int` the id for the rank bracket this rank is in
f10342:c6:m5
@asyncio.coroutine<EOL><INDENT>def load_level(self):<DEDENT>
data = yield from self.auth.get("<STR_LIT>" % (self.spaceid, self.platform_url, self.id))<EOL>if "<STR_LIT>" in data and len(data["<STR_LIT>"]) > <NUM_LIT:0>:<EOL><INDENT>self.xp = data["<STR_LIT>"][<NUM_LIT:0>].get("<STR_LIT>", <NUM_LIT:0>)<EOL>self.level = data["<STR_LIT>"][<NUM_LIT:0>].get("<STR_LIT>", <NUM_LIT:0>)<EOL><DEDENT>else:<EOL><INDENT>raise InvalidRequest("<STR_LIT>" % str(data))<EOL><DEDENT>
|coro| Load the players XP and level
f10342:c11:m3
@asyncio.coroutine<EOL><INDENT>def check_level(self):<DEDENT>
if not hasattr(self, "<STR_LIT>"):<EOL><INDENT>yield from self.load_level()<EOL><DEDENT>
|coro| Check the players XP and level, only loading it if it hasn't been loaded yet
f10342:c11:m4
@asyncio.coroutine<EOL><INDENT>def load_rank(self, region, season=-<NUM_LIT:1>):<DEDENT>
data = yield from self.auth.get("<STR_LIT>" % (self.spaceid, self.platform_url, self.id, region, season))<EOL>if "<STR_LIT>" in data and self.id in data["<STR_LIT>"]:<EOL><INDENT>regionkey = "<STR_LIT>" % (region, season)<EOL>self.ranks[regionkey] = Rank(data["<STR_LIT>"][self.id])<EOL>return self.ranks[regionkey]<EOL><DEDENT>else:<EOL><INDENT>raise InvalidRequest("<STR_LIT>" % str(data))<EOL><DEDENT>
|coro| Loads the players rank for this region and season Parameters ---------- region : str the name of the region you want to get the rank for season : Optional[int] the season you want to get the rank for (defaults to -1, latest season) Returns ------- :class:`Rank` the players rank for this region and season
f10342:c11:m5
@asyncio.coroutine<EOL><INDENT>def get_rank(self, region, season=-<NUM_LIT:1>):<DEDENT>
cache_key = "<STR_LIT>" % (region, season)<EOL>if cache_key in self.ranks:<EOL><INDENT>return self.ranks[cache_key]<EOL><DEDENT>result = yield from self.load_rank(region, season)<EOL>return result<EOL>
|coro| Checks the players rank for this region, only loading it if it hasn't already been found Parameters ---------- region : str the name of the region you want to get the rank for season : Optional[int] the season you want to get the rank for (defaults to -1, latest season) Returns ------- :class:`Rank` the players rank for this region and season
f10342:c11:m6
@asyncio.coroutine<EOL><INDENT>def load_all_operators(self):<DEDENT>
statistics = "<STR_LIT>"<EOL>for operator in OperatorStatisticNames:<EOL><INDENT>operator_key = yield from self.auth.get_operator_statistic(operator)<EOL>if operator_key:<EOL><INDENT>statistics += "<STR_LIT:U+002C>" + operator_key<EOL><DEDENT><DEDENT>data = yield from self.auth.get("<STR_LIT>" % (self.spaceid, self.platform_url, self.id, statistics))<EOL>if "<STR_LIT>" not in data or not self.id in data["<STR_LIT>"]:<EOL><INDENT>raise InvalidRequest("<STR_LIT>" % str(data))<EOL><DEDENT>data = data["<STR_LIT>"][self.id]<EOL>for operator in OperatorStatisticNames:<EOL><INDENT>location = yield from self.auth.get_operator_index(operator.lower())<EOL>op_data = {x.split("<STR_LIT::>")[<NUM_LIT:0>].split("<STR_LIT:_>")[<NUM_LIT:1>]: data[x] for x in data if x is not None and location in x}<EOL>operator_key = yield from self.auth.get_operator_statistic(operator)<EOL>if operator_key:<EOL><INDENT>op_data["<STR_LIT>"] = operator_key.split("<STR_LIT:_>")[<NUM_LIT:1>]<EOL><DEDENT>self.operators[operator.lower()] = Operator(operator.lower(), op_data)<EOL><DEDENT>return self.operators<EOL>
|coro| Loads the player stats for all operators Returns ------- dict[:class:`Operator`] the dictionary of all operators found
f10342:c11:m7
@asyncio.coroutine<EOL><INDENT>def get_all_operators(self):<DEDENT>
if len(self.operators) >= len(OperatorStatisticNames):<EOL><INDENT>return self.operators<EOL><DEDENT>result = yield from self.load_all_operators()<EOL>return result<EOL>
|coro| Checks the player stats for all operators, loading them all again if any aren't found This is significantly more efficient than calling get_operator for every operator name. Returns ------- dict[:class:`Operator`] the dictionary of all operators found
f10342:c11:m8
@asyncio.coroutine<EOL><INDENT>def load_operator(self, operator):<DEDENT>
location = yield from self.auth.get_operator_index(operator)<EOL>if location is None:<EOL><INDENT>raise ValueError("<STR_LIT>" % operator)<EOL><DEDENT>operator_key = yield from self.auth.get_operator_statistic(operator)<EOL>if operator_key is not None:<EOL><INDENT>operator_key = "<STR_LIT:U+002C>" + operator_key<EOL><DEDENT>else:<EOL><INDENT>operator_key = "<STR_LIT>"<EOL><DEDENT>data = yield from self.auth.get("<STR_LIT>" % (self.spaceid, self.platform_url, self.id, operator_key))<EOL>if not "<STR_LIT>" in data or not self.id in data["<STR_LIT>"]:<EOL><INDENT>raise InvalidRequest("<STR_LIT>" % str(data))<EOL><DEDENT>data = data["<STR_LIT>"][self.id]<EOL>data = {x.split("<STR_LIT::>")[<NUM_LIT:0>].split("<STR_LIT:_>")[<NUM_LIT:1>]: data[x] for x in data if x is not None and location in x}<EOL>if operator_key:<EOL><INDENT>data["<STR_LIT>"] = operator_key.split("<STR_LIT:_>")[<NUM_LIT:1>]<EOL><DEDENT>oper = Operator(operator, data)<EOL>self.operators[operator] = oper<EOL>return oper<EOL>
|coro| Loads the players stats for the operator Parameters ---------- operator : str the name of the operator Returns ------- :class:`Operator` the operator object found
f10342:c11:m9
@asyncio.coroutine<EOL><INDENT>def get_operator(self, operator):<DEDENT>
if operator in self.operators:<EOL><INDENT>return self.operators[operator]<EOL><DEDENT>result = yield from self.load_operator(operator)<EOL>return result<EOL>
|coro| Checks the players stats for this operator, only loading them if they haven't already been found Parameters ---------- operator : str the name of the operator Returns ------- :class:`Operator` the operator object found
f10342:c11:m10
@asyncio.coroutine<EOL><INDENT>def load_weapons(self):<DEDENT>
data = yield from self.auth.get("<STR_LIT>" % (self.spaceid, self.platform_url, self.id))<EOL>if not "<STR_LIT>" in data or not self.id in data["<STR_LIT>"]:<EOL><INDENT>raise InvalidRequest("<STR_LIT>" % str(data))<EOL><DEDENT>data = data["<STR_LIT>"][self.id]<EOL>self.weapons = [Weapon(i) for i in range(<NUM_LIT:7>)]<EOL>for x in data:<EOL><INDENT>spl = x.split("<STR_LIT::>")<EOL>category = spl[<NUM_LIT:0>].split("<STR_LIT:_>")[<NUM_LIT:1>]<EOL>try:<EOL><INDENT>weapontype = int(spl[<NUM_LIT:1>]) - <NUM_LIT:1><EOL>weapon = self.weapons[weapontype]<EOL>if category == "<STR_LIT>": weapon.kills = data[x]<EOL>elif category == "<STR_LIT>": weapon.headshots = data[x]<EOL>elif category == "<STR_LIT>": weapon.shots = data[x]<EOL>elif category == "<STR_LIT>": weapon.hits = data[x]<EOL><DEDENT>except (ValueError, TypeError, IndexError):<EOL><INDENT>pass<EOL><DEDENT><DEDENT>return self.weapons<EOL>
|coro| Load the players weapon stats Returns ------- list[:class:`Weapon`] list of all the weapon objects found
f10342:c11:m11
@asyncio.coroutine<EOL><INDENT>def check_weapons(self):<DEDENT>
if len(self.weapons) == <NUM_LIT:0>:<EOL><INDENT>yield from self.load_weapons()<EOL><DEDENT>return self.weapons<EOL>
|coro| Check the players weapon stats, only loading them if they haven't already been found Returns ------- list[:class:`Weapon`] list of all the weapon objects found
f10342:c11:m12
@asyncio.coroutine<EOL><INDENT>def load_gamemodes(self):<DEDENT>
stats = yield from self._fetch_statistics("<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>")<EOL>self.gamemodes = {x: Gamemode(x) for x in GamemodeNames}<EOL>for name in self.gamemodes:<EOL><INDENT>statname, gamemode = name + "<STR_LIT>", self.gamemodes[name]<EOL>gamemode.best_score = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>gamemode.lost = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>gamemode.won = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>gamemode.played = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>if name == "<STR_LIT>":<EOL><INDENT>gamemode.areas_secured = stats.get("<STR_LIT>", <NUM_LIT:0>)<EOL>gamemode.areas_defended = stats.get("<STR_LIT>", <NUM_LIT:0>)<EOL>gamemode.areas_contested = stats.get("<STR_LIT>", <NUM_LIT:0>)<EOL><DEDENT>elif name == "<STR_LIT>":<EOL><INDENT>gamemode.hostages_rescued = stats.get("<STR_LIT>", <NUM_LIT:0>)<EOL>gamemode.hostages_defended = stats.get("<STR_LIT>", <NUM_LIT:0>)<EOL><DEDENT><DEDENT>return self.gamemodes<EOL>
|coro| Loads the players gamemode stats Returns ------- dict dict of all the gamemodes found (gamemode_name: :class:`Gamemode`)
f10342:c11:m13
@asyncio.coroutine<EOL><INDENT>def check_gamemodes(self):<DEDENT>
if len(self.gamemodes) == <NUM_LIT:0>:<EOL><INDENT>yield from self.load_gamemodes()<EOL><DEDENT>return self.gamemodes<EOL>
|coro| Checks the players gamemode stats, only loading them if they haven't already been found Returns ------- dict dict of all the gamemodes found (gamemode_name: :class:`Gamemode`)
f10342:c11:m14
@asyncio.coroutine<EOL><INDENT>def load_general(self):<DEDENT>
stats = yield from self._fetch_statistics("<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>", "<STR_LIT>")<EOL>statname = "<STR_LIT>"<EOL>self.deaths = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.penetration_kills = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.matches_won = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.bullets_hit = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.melee_kills = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.bullets_fired = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.matches_played = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.kill_assists = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.time_played = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.revives = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.kills = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.headshots = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.matches_lost = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.dbno_assists = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.suicides = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.barricades_deployed = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.reinforcements_deployed = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.total_xp = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.rappel_breaches = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.distance_travelled = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.revives_denied = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.dbnos = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.gadgets_destroyed = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.blind_kills = stats.get(statname + "<STR_LIT>")<EOL>
|coro| Loads the players general stats
f10342:c11:m15
@asyncio.coroutine<EOL><INDENT>def check_general(self):<DEDENT>
if not hasattr(self, "<STR_LIT>"):<EOL><INDENT>yield from self.load_general()<EOL><DEDENT>
|coro| Checks the players general stats, only loading them if they haven't already been found
f10342:c11:m16
@asyncio.coroutine<EOL><INDENT>def load_queues(self):<DEDENT>
stats = yield from self._fetch_statistics("<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>", "<STR_LIT>")<EOL>self.ranked = GameQueue("<STR_LIT>")<EOL>self.casual = GameQueue("<STR_LIT>")<EOL>for gq in (self.ranked, self.casual):<EOL><INDENT>statname = gq.name + "<STR_LIT>"<EOL>gq.won = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>gq.lost = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>gq.time_played = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>gq.played = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>gq.kills = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>gq.deaths = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL><DEDENT>
|coro| Loads the players game queues
f10342:c11:m17
@asyncio.coroutine<EOL><INDENT>def check_queues(self):<DEDENT>
if self.casual is None:<EOL><INDENT>yield from self.load_queues()<EOL><DEDENT>
|coro| Checks the players game queues, only loading them if they haven't already been found
f10342:c11:m18
@asyncio.coroutine<EOL><INDENT>def load_terrohunt(self):<DEDENT>
stats = yield from self._fetch_statistics("<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>")<EOL>self.terrorist_hunt = GameQueue("<STR_LIT>")<EOL>statname = "<STR_LIT>"<EOL>self.terrorist_hunt.deaths = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.terrorist_hunt.penetration_kills = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.terrorist_hunt.matches_won = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.terrorist_hunt.bullets_hit = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.terrorist_hunt.melee_kills = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.terrorist_hunt.bullets_fired = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.terrorist_hunt.matches_played = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.terrorist_hunt.kill_assists = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.terrorist_hunt.time_played = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.terrorist_hunt.revives = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.terrorist_hunt.kills = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.terrorist_hunt.headshots = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.terrorist_hunt.matches_lost = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.terrorist_hunt.dbno_assists = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.terrorist_hunt.suicides = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.terrorist_hunt.barricades_deployed = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.terrorist_hunt.reinforcements_deployed = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.terrorist_hunt.total_xp = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.terrorist_hunt.rappel_breaches = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.terrorist_hunt.distance_travelled = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.terrorist_hunt.revives_denied = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.terrorist_hunt.dbnos = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.terrorist_hunt.gadgets_destroyed = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.terrorist_hunt.areas_secured = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.terrorist_hunt.areas_defended = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.terrorist_hunt.areas_contested = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.terrorist_hunt.hostages_rescued = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.terrorist_hunt.hostages_defended = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>self.terrorist_hunt.blind_kills = stats.get(statname + "<STR_LIT>", <NUM_LIT:0>)<EOL>return self.terrorist_hunt<EOL>
|coro| Loads the player's general stats for terrorist hunt
f10342:c11:m19
@asyncio.coroutine<EOL><INDENT>def check_terrohunt(self):<DEDENT>
if self.terrorist_hunt is None:<EOL><INDENT>yield from self.load_terrohunt()<EOL><DEDENT>return self.terrorist_hunt<EOL>
|coro| Checks the players general stats for terrorist hunt, only loading them if they haven't been loaded already
f10342:c11:m20
def create_skeleton(shutit):
skel_path = shutit.cfg['<STR_LIT>']['<STR_LIT:path>']<EOL>skel_module_name = shutit.cfg['<STR_LIT>']['<STR_LIT>']<EOL>skel_domain = shutit.cfg['<STR_LIT>']['<STR_LIT>']<EOL>skel_domain_hash = shutit.cfg['<STR_LIT>']['<STR_LIT>']<EOL>skel_depends = shutit.cfg['<STR_LIT>']['<STR_LIT>']<EOL>skel_shutitfiles = shutit.cfg['<STR_LIT>']['<STR_LIT>']<EOL>skel_delivery = shutit.cfg['<STR_LIT>']['<STR_LIT>']<EOL>skel_pattern = shutit.cfg['<STR_LIT>']['<STR_LIT>']<EOL>skel_vagrant_num_machines = shutit.cfg['<STR_LIT>']['<STR_LIT>']<EOL>skel_vagrant_machine_prefix = shutit.cfg['<STR_LIT>']['<STR_LIT>']<EOL>skel_vagrant_ssh_access = shutit.cfg['<STR_LIT>']['<STR_LIT>']<EOL>skel_vagrant_docker = shutit.cfg['<STR_LIT>']['<STR_LIT>']<EOL>skel_vagrant_snapshot = shutit.cfg['<STR_LIT>']['<STR_LIT>']<EOL>skel_vagrant_upload = shutit.cfg['<STR_LIT>']['<STR_LIT>']<EOL>skel_vagrant_image_name = shutit.cfg['<STR_LIT>']['<STR_LIT>']<EOL>if not skel_path or skel_path[<NUM_LIT:0>] != '<STR_LIT:/>':<EOL><INDENT>shutit.fail('<STR_LIT>') <EOL><DEDENT>if os.path.exists(skel_path):<EOL><INDENT>shutit.fail(skel_path + '<STR_LIT>') <EOL><DEDENT>if not skel_module_name:<EOL><INDENT>shutit.fail('<STR_LIT>') <EOL><DEDENT>if not re.match('<STR_LIT>', skel_module_name):<EOL><INDENT>shutit.fail('<STR_LIT>' + skel_module_name) <EOL><DEDENT>if not skel_domain:<EOL><INDENT>shutit.fail('<STR_LIT>') <EOL><DEDENT>os.makedirs(skel_path)<EOL>os.chdir(skel_path)<EOL>if shutit.cfg['<STR_LIT>']['<STR_LIT>'] == '<STR_LIT>':<EOL><INDENT>from shutit_patterns import bash<EOL>bash.setup_bash_pattern(shutit,<EOL>skel_path=skel_path,<EOL>skel_delivery=skel_delivery,<EOL>skel_domain=skel_domain,<EOL>skel_module_name=skel_module_name,<EOL>skel_shutitfiles=skel_shutitfiles,<EOL>skel_domain_hash=skel_domain_hash,<EOL>skel_depends=skel_depends)<EOL><DEDENT>elif shutit.cfg['<STR_LIT>']['<STR_LIT>'] == '<STR_LIT>':<EOL><INDENT>from shutit_patterns import docker<EOL>docker.setup_docker_pattern(shutit,<EOL>skel_path=skel_path,<EOL>skel_delivery=skel_delivery,<EOL>skel_domain=skel_domain,<EOL>skel_module_name=skel_module_name,<EOL>skel_shutitfiles=skel_shutitfiles,<EOL>skel_domain_hash=skel_domain_hash,<EOL>skel_depends=skel_depends)<EOL><DEDENT>elif shutit.cfg['<STR_LIT>']['<STR_LIT>'] == '<STR_LIT>': <EOL><INDENT>from shutit_patterns import vagrant<EOL>vagrant.setup_vagrant_pattern(shutit,<EOL>skel_path=skel_path,<EOL>skel_delivery=skel_delivery,<EOL>skel_domain=skel_domain,<EOL>skel_module_name=skel_module_name,<EOL>skel_shutitfiles=skel_shutitfiles,<EOL>skel_domain_hash=skel_domain_hash,<EOL>skel_depends=skel_depends,<EOL>skel_vagrant_num_machines=skel_vagrant_num_machines,<EOL>skel_vagrant_machine_prefix=skel_vagrant_machine_prefix,<EOL>skel_vagrant_ssh_access=skel_vagrant_ssh_access,<EOL>skel_vagrant_docker=skel_vagrant_docker,<EOL>skel_vagrant_snapshot=skel_vagrant_snapshot,<EOL>skel_vagrant_upload=skel_vagrant_upload,<EOL>skel_vagrant_image_name=skel_vagrant_image_name)<EOL><DEDENT>elif shutit.cfg['<STR_LIT>']['<STR_LIT>'] == '<STR_LIT>':<EOL><INDENT>shutitfile.setup_shutitfile_pattern(shutit,<EOL>skel_path=skel_path,<EOL>skel_delivery=skel_delivery,<EOL>skel_pattern=skel_pattern,<EOL>skel_domain=skel_domain,<EOL>skel_module_name=skel_module_name,<EOL>skel_vagrant_num_machines=skel_vagrant_num_machines,<EOL>skel_vagrant_machine_prefix=skel_vagrant_machine_prefix,<EOL>skel_vagrant_ssh_access=skel_vagrant_ssh_access,<EOL>skel_vagrant_docker=skel_vagrant_docker)<EOL><DEDENT>elif shutit.cfg['<STR_LIT>']['<STR_LIT>'] == '<STR_LIT>': <EOL><INDENT>shutit.fail('<STR_LIT>')<EOL><DEDENT>
Creates module based on a pattern supplied as a git repo.
f10345:m0
def shutit_method_scope(func):
def wrapper(self, shutit):<EOL><INDENT>"""<STR_LIT>"""<EOL>ret = func(self, shutit)<EOL>return ret<EOL><DEDENT>return wrapper<EOL>
Notifies the ShutIt object whenever we call a shutit module method. This allows setting values for the 'scope' of a function.
f10346:m0
def __new__(mcs, name, bases, local):
<EOL>if name != '<STR_LIT>':<EOL><INDENT>sim = mcs.ShutItModule<EOL>assert sim is not None, shutit_util.print_debug()<EOL>for fname, method in iteritems(local):<EOL><INDENT>if not hasattr(sim, fname):<EOL><INDENT>continue<EOL><DEDENT>if not callable(method):<EOL><INDENT>continue<EOL><DEDENT>sim_method = getattr(sim, fname)<EOL>if sim_method is method: <EOL><INDENT>continue<EOL><DEDENT>args = inspect.getargspec(sim_method)[<NUM_LIT:0>]<EOL>if args != ['<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>continue<EOL><DEDENT>local[fname] = shutit_method_scope(method)<EOL><DEDENT><DEDENT>cls = super(ShutItMeta, mcs).__new__(mcs, name, bases, local)<EOL>if name == '<STR_LIT>':<EOL><INDENT>mcs.ShutItModule = cls<EOL><DEDENT>return cls<EOL>
Checks this is a ShutItModule, and wraps any ShutItModule methods that have been overridden in the subclass.
f10346:c3:m0
def __init__(self, module_id, run_order, description='<STR_LIT>', maintainer='<STR_LIT>', depends=None, conflicts=None, delivery_methods=None):
<EOL>self.module_id = module_id<EOL>if not isinstance(module_id, str): <EOL><INDENT>err = str(module_id) + '<STR_LIT>'<EOL>shutit_global.shutit_global_object.shutit_print(err)<EOL>raise ShutItModuleError(err)<EOL><DEDENT>if isinstance(run_order, (float, int, str)):<EOL><INDENT>run_order = decimal.Decimal(run_order)<EOL><DEDENT>if not isinstance(run_order, decimal.Decimal): <EOL><INDENT>err = module_id + '<STR_LIT>'<EOL>shutit_global.shutit_global_object.shutit_print(err)<EOL>raise ShutItModuleError(err)<EOL><DEDENT>self.run_order = run_order<EOL>self.depends_on = []<EOL>if depends is not None:<EOL><INDENT>self.depends_on = [dep for dep in depends]<EOL><DEDENT>self.conflicts_with = []<EOL>if conflicts is not None:<EOL><INDENT>self.conflicts_with = [conflict for conflict in conflicts]<EOL><DEDENT>self.description = description<EOL>self.maintainer = maintainer<EOL>if not delivery_methods:<EOL><INDENT>delivery_methods = ['<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>']<EOL><DEDENT>if isinstance(delivery_methods, str):<EOL><INDENT>delivery_methods = [delivery_methods]<EOL><DEDENT>self.ok_delivery_methods = delivery_methods<EOL>
Constructor. Sets up module_id, run_order, deps and conflicts. Also checks types for safety.
f10346:c4:m0
def get_config(self, shutit):
return True<EOL>
Gets all config items necessary for this module to be built
f10346:c4:m1
def check_ready(self, shutit):
return True<EOL>
Checks whether we are ready to build this module. This is called before the build, to ensure modules have their requirements in place before we commence the build. Checking whether the build will happen at all (and therefore whether the check should take place) will be determined by the framework. Should return True if it's ready to run, else False.
f10346:c4:m2
def remove(self, shutit):
return False<EOL>
Remove the module, which should ensure the module has been deleted from the system. Returns True if all removed without any errors, else False.
f10346:c4:m3
def start(self, shutit):
return True<EOL>
Run when module should be installed (is_installed() or configured to build is true) Run after repository work. Returns True if all started ok.
f10346:c4:m4
def stop(self, shutit):
return True<EOL>
Runs when module should be stopped. Runs before repo work, and before finalize is called. Returns True if all stopped ok.
f10346:c4:m5
def is_installed(self, shutit):
return shutit.is_shutit_installed(self.module_id)<EOL>
Determines whether the module has been built in this target host already. Returns True if it is certain it's there, else False. Required.
f10346:c4:m6
@abstractmethod<EOL><INDENT>def build(self, shutit):<DEDENT>
pass<EOL>
Runs the build part of the module, which should ensure the module has been set up. If is_installed determines that the module is already there, this is not run. Returns True if it has succeeded in building, else False. Required.
f10346:c4:m7
def finalize(self, shutit):
return True<EOL>
Finalize the module, ie do things that need doing after final module has been run and before we exit, eg updatedb.
f10346:c4:m9
def do_finalize():
def _finalize(shutit):<EOL><INDENT>shutit.stop_all()<EOL>shutit.log('<STR_LIT>' + str(shutit), level=logging.DEBUG)<EOL>for module_id in shutit.module_ids(rev=True):<EOL><INDENT>if shutit.is_installed(shutit.shutit_map[module_id]):<EOL><INDENT>shutit.login(prompt_prefix=module_id,command=shutit_global.shutit_global_object.bash_startup_command,echo=False)<EOL>if not shutit.shutit_map[module_id].finalize(shutit):<EOL><INDENT>shutit.fail(module_id + '<STR_LIT>', shutit_pexpect_child=shutit.get_shutit_pexpect_session_from_id('<STR_LIT>').pexpect_child) <EOL><DEDENT>shutit.logout(echo=False)<EOL><DEDENT><DEDENT>for fshutit in shutit_global.shutit_global_object.shutit_objects:<EOL><INDENT>_finalize(fshutit)<EOL><DEDENT><DEDENT>
Runs finalize phase; run after all builds are complete and all modules have been stopped.
f10347:m2
def check_dependee_order(depender, dependee, dependee_id):
<EOL>shutit_global.shutit_global_object.yield_to_draw()<EOL>if dependee.run_order > depender.run_order:<EOL><INDENT>return '<STR_LIT>' + depender.module_id + '<STR_LIT>' + str(depender.run_order) + '<STR_LIT>' + '<STR_LIT>' + dependee_id + '<STR_LIT>' + str(dependee.run_order) + '<STR_LIT>' + '<STR_LIT>'<EOL><DEDENT>return '<STR_LIT>'<EOL>
Checks whether run orders are in the appropriate order.
f10347:m3
def make_dep_graph(depender):
shutit_global.shutit_global_object.yield_to_draw()<EOL>digraph = '<STR_LIT>'<EOL>for dependee_id in depender.depends_on:<EOL><INDENT>digraph = (digraph + '<STR_LIT:">' + depender.module_id + '<STR_LIT>' + dependee_id + '<STR_LIT>')<EOL><DEDENT>return digraph<EOL>
Returns a digraph string fragment based on the passed-in module
f10347:m4
def get_config_set(self, section, option):
values = set()<EOL>for cp, filename, fp in self.layers:<EOL><INDENT>filename = filename <EOL>fp = fp <EOL>if cp.has_option(section, option):<EOL><INDENT>values.add(cp.get(section, option))<EOL><DEDENT><DEDENT>return values<EOL>
Returns a set with each value per config file in it.
f10347:c0:m4
def reload(self):
oldlayers = self.layers<EOL>self.layers = []<EOL>for cp, filename, fp in oldlayers:<EOL><INDENT>cp = cp <EOL>if fp is None:<EOL><INDENT>self.read(filename)<EOL><DEDENT>else:<EOL><INDENT>self.readfp(fp, filename)<EOL><DEDENT><DEDENT>
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.
f10347:c0:m5
def __init__(self,<EOL>session_type,<EOL>standalone):
self.standalone = standalone<EOL>self.build = {}<EOL>self.build['<STR_LIT>'] = '<STR_LIT>'<EOL>self.build['<STR_LIT>'] = False<EOL>self.build['<STR_LIT>'] = '<STR_LIT>'<EOL>self.build['<STR_LIT>'] = []<EOL>self.build['<STR_LIT>'] = False <EOL>self.build['<STR_LIT>'] = -<NUM_LIT:1> <EOL>self.build['<STR_LIT>'] = None<EOL>self.build['<STR_LIT>'] = False<EOL>self.build['<STR_LIT>'] = False<EOL>self.build['<STR_LIT>'] = False<EOL>self.build['<STR_LIT>'] = False<EOL>self.build['<STR_LIT>'] = None<EOL>self.build['<STR_LIT>'] = None<EOL>self.build['<STR_LIT>'] = None<EOL>self.build['<STR_LIT>'] = False<EOL>self.host = {}<EOL>self.host['<STR_LIT>'] = sys.path[<NUM_LIT:0>]<EOL>self.host['<STR_LIT>'] = os.getcwd()<EOL>self.build['<STR_LIT>'] = None<EOL>self.build['<STR_LIT>'] = None<EOL>self.repository = {}<EOL>self.expect_prompts = {}<EOL>self.list_configs = {}<EOL>self.target = {}<EOL>self.action = {}<EOL>self.shutit_pexpect_sessions = {}<EOL>self.shutit_map = {}<EOL>self.shutit_file_map = {}<EOL>self.list_modules = {} <EOL>self.current_shutit_pexpect_session = None<EOL>self.config_parser = None<EOL>self.shutit_modules = set()<EOL>self.conn_modules = set()<EOL>self.shutit_main_dir = os.path.abspath(os.path.dirname(__file__))<EOL>self.shutit_global_object = shutit_global.shutit_global_object<EOL>self.cfg = {} <EOL>self.shutitfile = {}<EOL>self.cfg['<STR_LIT>'] = self.shutitfile <EOL>self.cfg['<STR_LIT>'] = {} <EOL>self.session_type = session_type<EOL>self.uuid_str = str(uuid.uuid4())<EOL>self.loglevel = None<EOL>self.logfile = None<EOL>self.last_log_time = time.time()<EOL>self.logging_setup_done = False<EOL>self.nocolor = False<EOL>self.vagrant_machines = None<EOL>
Constructor. Sets up: - shutit_modules - representation of loaded shutit modules - shutit_main_dir - directory in which shutit is located - cfg - dictionary of configuration of build - shutit_map - maps module_ids to module objects standalone - Whether this is a shutit object created dynamically (True) within a python script, or as part of a shutit invocation (False). If it's created dynamically, then this can make a difference to how the configuration is collected.
f10347:c2:m0
def get_shutit_pexpect_session_environment(self, environment_id):
if not isinstance(environment_id, str):<EOL><INDENT>self.fail('<STR_LIT>') <EOL><DEDENT>for env in shutit_global.shutit_global_object.shutit_pexpect_session_environments:<EOL><INDENT>if env.environment_id == environment_id:<EOL><INDENT>return env<EOL><DEDENT><DEDENT>return None<EOL>
Returns the first shutit_pexpect_session object related to the given environment-id
f10347:c2:m3
def get_current_shutit_pexpect_session_environment(self, note=None):
self.handle_note(note)<EOL>current_session = self.get_current_shutit_pexpect_session()<EOL>if current_session is not None:<EOL><INDENT>res = current_session.current_environment<EOL><DEDENT>else:<EOL><INDENT>res = None<EOL><DEDENT>self.handle_note_after(note)<EOL>return res<EOL>
Returns the current environment from the currently-set default pexpect child.
f10347:c2:m4
def get_current_shutit_pexpect_session(self, note=None):
self.handle_note(note)<EOL>res = self.current_shutit_pexpect_session<EOL>self.handle_note_after(note)<EOL>return res<EOL>
Returns the currently-set default pexpect child. @return: default shutit pexpect child object
f10347:c2:m5
def get_shutit_pexpect_sessions(self, note=None):
self.handle_note(note)<EOL>sessions = []<EOL>for key in self.shutit_pexpect_sessions:<EOL><INDENT>sessions.append(shutit_object.shutit_pexpect_sessions[key])<EOL><DEDENT>self.handle_note_after(note)<EOL>return sessions<EOL>
Returns all the shutit_pexpect_session keys for this object. @return: list of all shutit_pexpect_session keys (pexpect_session_ids)
f10347:c2:m6
def get_default_shutit_pexpect_session_expect(self):
return self.current_shutit_pexpect_session.default_expect<EOL>
Returns the currently-set default pexpect string (usually a prompt). @return: default pexpect string
f10347:c2:m7
def get_default_shutit_pexpect_session_check_exit(self):
return self.current_shutit_pexpect_session.check_exit<EOL>
Returns default value of check_exit. See send method. @rtype: boolean @return: Default check_exit value
f10347:c2:m8
def set_default_shutit_pexpect_session(self, shutit_pexpect_session):
assert isinstance(shutit_pexpect_session, ShutItPexpectSession), shutit_util.print_debug()<EOL>self.current_shutit_pexpect_session = shutit_pexpect_session<EOL>return True<EOL>
Sets the default pexpect child. @param shutit_pexpect_session: pexpect child to set as default
f10347:c2:m9
def set_default_shutit_pexpect_session_expect(self, expect=None):
if expect is None:<EOL><INDENT>self.current_shutit_pexpect_session.default_expect = self.expect_prompts['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>self.current_shutit_pexpect_session.default_expect = expect<EOL><DEDENT>return True<EOL>
Sets the default pexpect string (usually a prompt). Defaults to the configured root prompt if no argument is passed. @param expect: String to expect in the output @type expect: string
f10347:c2:m10
def fail(self, msg, shutit_pexpect_child=None, throw_exception=False):
shutit_global.shutit_global_object.yield_to_draw()<EOL>if shutit_pexpect_child is not None:<EOL><INDENT>shutit_pexpect_session = self.get_shutit_pexpect_session_from_child(shutit_pexpect_child)<EOL>shutit_util.print_debug(sys.exc_info())<EOL>shutit_pexpect_session.pause_point('<STR_LIT>' + msg, color='<STR_LIT>')<EOL><DEDENT>if throw_exception:<EOL><INDENT>sys.stderr.write('<STR_LIT>' + msg + '<STR_LIT:\n>')<EOL>sys.stderr.write('<STR_LIT:\n>')<EOL>shutit_util.print_debug(sys.exc_info())<EOL>raise ShutItFailException(msg)<EOL><DEDENT>else:<EOL><INDENT>shutit_global.shutit_global_object.handle_exit(exit_code=<NUM_LIT:1>,msg=msg)<EOL><DEDENT>shutit_global.shutit_global_object.yield_to_draw()<EOL>
Handles a failure, pausing if a pexpect child object is passed in. @param shutit_pexpect_child: pexpect child to work on @param throw_exception: Whether to throw an exception. @type throw_exception: boolean
f10347:c2:m11
def get_current_environment(self, note=None):
shutit_global.shutit_global_object.yield_to_draw()<EOL>self.handle_note(note)<EOL>res = self.get_current_shutit_pexpect_session_environment().environment_id<EOL>self.handle_note_after(note)<EOL>return res<EOL>
Returns the current environment id from the current shutit_pexpect_session
f10347:c2:m12
def multisend(self,<EOL>send,<EOL>send_dict,<EOL>expect=None,<EOL>shutit_pexpect_child=None,<EOL>timeout=shutit_global.shutit_global_object.default_timeout,<EOL>check_exit=None,<EOL>fail_on_empty_before=True,<EOL>record_command=True,<EOL>exit_values=None,<EOL>escape=False,<EOL>echo=None,<EOL>note=None,<EOL>secret=False,<EOL>nonewline=False,<EOL>loglevel=logging.DEBUG):
shutit_global.shutit_global_object.yield_to_draw()<EOL>assert isinstance(send_dict, dict), shutit_util.print_debug()<EOL>shutit_pexpect_child = shutit_pexpect_child or self.get_current_shutit_pexpect_session().pexpect_child<EOL>expect = expect or self.get_current_shutit_pexpect_session().default_expect<EOL>shutit_pexpect_session = self.get_shutit_pexpect_session_from_child(shutit_pexpect_child)<EOL>return shutit_pexpect_session.multisend(ShutItSendSpec(shutit_pexpect_session,<EOL>send=send,<EOL>send_dict=send_dict,<EOL>expect=expect,<EOL>timeout=timeout,<EOL>check_exit=check_exit,<EOL>fail_on_empty_before=fail_on_empty_before,<EOL>record_command=record_command,<EOL>exit_values=exit_values,<EOL>escape=escape,<EOL>echo=echo,<EOL>note=note,<EOL>loglevel=loglevel,<EOL>secret=secret,<EOL>nonewline=nonewline))<EOL>
Multisend. Same as send, except it takes multiple sends and expects in a dict that are processed while waiting for the end "expect" argument supplied. @param send_dict: see shutit_sendspec @param expect: String or list of strings of final expected output that returns from this function. See send() @param send: See send() @param shutit_pexpect_child: See send() @param timeout: See send() @param check_exit: See send() @param fail_on_empty_before: See send() @param record_command: See send() @param exit_values: See send() @param echo: See send() @param note: See send()
f10347:c2:m13
def send_and_require(self,<EOL>send,<EOL>regexps,<EOL>not_there=False,<EOL>shutit_pexpect_child=None,<EOL>echo=None,<EOL>note=None,<EOL>loglevel=logging.INFO):
shutit_global.shutit_global_object.yield_to_draw()<EOL>shutit_pexpect_child = shutit_pexpect_child or self.get_current_shutit_pexpect_session().pexpect_child<EOL>shutit_pexpect_session = self.get_shutit_pexpect_session_from_child(shutit_pexpect_child)<EOL>return shutit_pexpect_session.send_and_require(send,<EOL>regexps,<EOL>not_there=not_there,<EOL>echo=echo,<EOL>note=note,<EOL>loglevel=loglevel)<EOL>
Send string and require the item in the output. See send_until
f10347:c2:m14
def send_until(self,<EOL>send,<EOL>regexps,<EOL>not_there=False,<EOL>shutit_pexpect_child=None,<EOL>cadence=<NUM_LIT:5>,<EOL>retries=<NUM_LIT:100>,<EOL>echo=None,<EOL>note=None,<EOL>debug_command=None,<EOL>pause_point_on_fail=True,<EOL>nonewline=False,<EOL>loglevel=logging.INFO):
shutit_global.shutit_global_object.yield_to_draw()<EOL>shutit_pexpect_child = shutit_pexpect_child or self.get_current_shutit_pexpect_session().pexpect_child<EOL>shutit_pexpect_session = self.get_shutit_pexpect_session_from_child(shutit_pexpect_child)<EOL>return shutit_pexpect_session.send_until(send,<EOL>regexps,<EOL>not_there=not_there,<EOL>cadence=cadence,<EOL>retries=retries,<EOL>echo=echo,<EOL>note=note,<EOL>loglevel=loglevel,<EOL>debug_command=debug_command,<EOL>nonewline=nonewline,<EOL>pause_point_on_fail=pause_point_on_fail)<EOL>
Send string on a regular cadence until a string is either seen, or the timeout is triggered. @param send: See send() @param regexps: List of regexps to wait for. @param not_there: If True, wait until this a regexp is not seen in the output. If False wait until a regexp is seen in the output (default) @param shutit_pexpect_child: See send() @param echo: See send() @param note: See send()
f10347:c2:m15
def challenge(self,<EOL>task_desc,<EOL>expect=None,<EOL>hints=None,<EOL>congratulations='<STR_LIT:OK>',<EOL>failed='<STR_LIT>',<EOL>expect_type='<STR_LIT>',<EOL>challenge_type='<STR_LIT>',<EOL>shutit_pexpect_child=None,<EOL>timeout=None,<EOL>check_exit=None,<EOL>fail_on_empty_before=True,<EOL>record_command=True,<EOL>exit_values=None,<EOL>echo=True,<EOL>escape=False,<EOL>pause=<NUM_LIT:1>,<EOL>loglevel=logging.DEBUG,<EOL>follow_on_context=None,<EOL>num_stages=None):
shutit_global.shutit_global_object.yield_to_draw()<EOL>shutit_pexpect_child = shutit_pexpect_child or self.get_current_shutit_pexpect_session().pexpect_child<EOL>shutit_pexpect_session = self.get_shutit_pexpect_session_from_child(shutit_pexpect_child)<EOL>return shutit_pexpect_session.challenge(self,<EOL>task_desc=task_desc,<EOL>expect=expect,<EOL>hints=hints,<EOL>congratulations=congratulations,<EOL>failed=failed,<EOL>expect_type=expect_type,<EOL>challenge_type=challenge_type,<EOL>timeout=timeout,<EOL>check_exit=check_exit,<EOL>fail_on_empty_before=fail_on_empty_before,<EOL>record_command=record_command,<EOL>exit_values=exit_values,<EOL>echo=echo,<EOL>escape=escape,<EOL>pause=pause,<EOL>loglevel=loglevel,<EOL>follow_on_context=follow_on_context,<EOL>num_stages=num_stages)<EOL>
Set the user a task to complete, success being determined by matching the output. Either pass in regexp(s) desired from the output as a string or a list, or an md5sum of the output wanted. @param follow_on_context On success, move to this context. A dict of information about that context. context = the type of context, eg docker, bash ok_container_name = if passed, send user to this container reset_container_name = if resetting, send user to this container @param challenge_type Behaviour of challenge made to user command = check for output of single command golf = user gets a pause point, and when leaving, command follow_on_context['check_command'] is run to check the output
f10347:c2:m16
def send(self,<EOL>send,<EOL>expect=None,<EOL>shutit_pexpect_child=None,<EOL>timeout=None,<EOL>check_exit=None,<EOL>fail_on_empty_before=True,<EOL>record_command=True,<EOL>exit_values=None,<EOL>echo=None,<EOL>escape=False,<EOL>retry=<NUM_LIT:3>,<EOL>note=None,<EOL>assume_gnu=True,<EOL>follow_on_commands=None,<EOL>searchwindowsize=None,<EOL>maxread=None,<EOL>delaybeforesend=None,<EOL>secret=False,<EOL>nonewline=False,<EOL>background=False,<EOL>wait=True,<EOL>block_other_commands=True,<EOL>loglevel=logging.INFO):
shutit_global.shutit_global_object.yield_to_draw()<EOL>shutit_pexpect_child = shutit_pexpect_child or self.get_current_shutit_pexpect_session().pexpect_child<EOL>shutit_pexpect_session = self.get_shutit_pexpect_session_from_child(shutit_pexpect_child)<EOL>ignore_background = not wait<EOL>return shutit_pexpect_session.send(ShutItSendSpec(shutit_pexpect_session,<EOL>send,<EOL>expect=expect,<EOL>timeout=timeout,<EOL>check_exit=check_exit,<EOL>fail_on_empty_before=fail_on_empty_before,<EOL>record_command=record_command,<EOL>exit_values=exit_values,<EOL>echo=echo,<EOL>escape=escape,<EOL>retry=retry,<EOL>note=note,<EOL>assume_gnu=assume_gnu,<EOL>loglevel=loglevel,<EOL>follow_on_commands=follow_on_commands,<EOL>searchwindowsize=searchwindowsize,<EOL>maxread=maxread,<EOL>delaybeforesend=delaybeforesend,<EOL>secret=secret,<EOL>nonewline=nonewline,<EOL>run_in_background=background,<EOL>ignore_background=ignore_background,<EOL>block_other_commands=block_other_commands))<EOL>
Send string as a shell command, and wait until the expected output is seen (either a string or any from a list of strings) before returning. The expected string will default to the currently-set default expected string (see get_default_shutit_pexpect_session_expect) Returns the pexpect return value (ie which expected string in the list matched) @param send: See shutit.ShutItSendSpec @param expect: See shutit.ShutItSendSpec @param shutit_pexpect_child: See shutit.ShutItSendSpec @param timeout: See shutit.ShutItSendSpec @param check_exit: See shutit.ShutItSendSpec @param fail_on_empty_before:See shutit.ShutItSendSpec @param record_command:See shutit.ShutItSendSpec @param exit_values:See shutit.ShutItSendSpec @param echo: See shutit.ShutItSendSpec @param escape: See shutit.ShutItSendSpec @param retry: See shutit.ShutItSendSpec @param note: See shutit.ShutItSendSpec @param assume_gnu: See shutit.ShutItSendSpec @param wait: See shutit.ShutItSendSpec @param block_other_commands: See shutit.ShutItSendSpec.block_other_commands @return: The pexpect return value (ie which expected string in the list matched) @rtype: string
f10347:c2:m17
def send_and_return_status(self,<EOL>send,<EOL>expect=None,<EOL>shutit_pexpect_child=None,<EOL>timeout=None,<EOL>fail_on_empty_before=True,<EOL>record_command=True,<EOL>exit_values=None,<EOL>echo=None,<EOL>escape=False,<EOL>retry=<NUM_LIT:3>,<EOL>note=None,<EOL>assume_gnu=True,<EOL>follow_on_commands=None,<EOL>loglevel=logging.INFO):
shutit_global.shutit_global_object.yield_to_draw()<EOL>shutit_pexpect_child = shutit_pexpect_child or self.get_current_shutit_pexpect_session().pexpect_child<EOL>shutit_pexpect_session = self.get_shutit_pexpect_session_from_child(shutit_pexpect_child)<EOL>shutit_pexpect_session.send(ShutItSendSpec(shutit_pexpect_session,<EOL>send=send,<EOL>expect=expect,<EOL>timeout=timeout,<EOL>check_exit=False,<EOL>fail_on_empty_before=fail_on_empty_before,<EOL>record_command=record_command,<EOL>exit_values=exit_values,<EOL>echo=echo,<EOL>escape=escape,<EOL>retry=retry,<EOL>note=note,<EOL>assume_gnu=assume_gnu,<EOL>loglevel=loglevel,<EOL>follow_on_commands=follow_on_commands))<EOL>return shutit_pexpect_session.check_last_exit_values(send,<EOL>check_exit=True,<EOL>expect=expect,<EOL>exit_values=exit_values,<EOL>retry=retry,<EOL>retbool=True)<EOL>
Returns true if a good exit code was received (usually 0)
f10347:c2:m18
def handle_note(self, note, command='<STR_LIT>', training_input='<STR_LIT>'):
shutit_global.shutit_global_object.yield_to_draw()<EOL>if self.build['<STR_LIT>'] and note != None and note != '<STR_LIT>':<EOL><INDENT>assert isinstance(note, str), shutit_util.print_debug()<EOL>wait = self.build['<STR_LIT>']<EOL>wrap = '<STR_LIT:\n>' + <NUM_LIT>*'<STR_LIT:=>' + '<STR_LIT:\n>'<EOL>message = wrap + note + wrap<EOL>if command != '<STR_LIT>':<EOL><INDENT>message += '<STR_LIT>' + command + wrap<EOL><DEDENT>if wait >= <NUM_LIT:0>:<EOL><INDENT>self.pause_point(message, color=<NUM_LIT>, wait=wait)<EOL><DEDENT>else:<EOL><INDENT>if training_input != '<STR_LIT>' and self.build['<STR_LIT>']:<EOL><INDENT>if len(training_input.split('<STR_LIT:\n>')) == <NUM_LIT:1>:<EOL><INDENT>shutit_global.shutit_global_object.shutit_print(shutit_util.colorise('<STR_LIT>',message))<EOL>while shutit_util.util_raw_input(prompt=shutit_util.colorise('<STR_LIT>','<STR_LIT>')) not in (training_input,'<STR_LIT:s>'):<EOL><INDENT>shutit_global.shutit_global_object.shutit_print('<STR_LIT>')<EOL><DEDENT>shutit_global.shutit_global_object.shutit_print(shutit_util.colorise('<STR_LIT>','<STR_LIT>'))<EOL><DEDENT>else:<EOL><INDENT>self.pause_point(message + '<STR_LIT>', color=<NUM_LIT>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>self.pause_point(message + '<STR_LIT>', color=<NUM_LIT>)<EOL><DEDENT><DEDENT><DEDENT>return True<EOL>
Handle notes and walkthrough option. @param note: See send()
f10347:c2:m19
def expect_allow_interrupt(self,<EOL>shutit_pexpect_child,<EOL>expect,<EOL>timeout,<EOL>iteration_s=<NUM_LIT:1>):
shutit_global.shutit_global_object.yield_to_draw()<EOL>shutit_pexpect_session = self.get_shutit_pexpect_session_from_child(shutit_pexpect_child)<EOL>accum_timeout = <NUM_LIT:0><EOL>if isinstance(expect, str):<EOL><INDENT>expect = [expect]<EOL><DEDENT>if timeout < <NUM_LIT:1>:<EOL><INDENT>timeout = <NUM_LIT:1><EOL><DEDENT>if iteration_s > timeout:<EOL><INDENT>iteration_s = timeout - <NUM_LIT:1><EOL><DEDENT>if iteration_s < <NUM_LIT:1>:<EOL><INDENT>iteration_s = <NUM_LIT:1><EOL><DEDENT>timed_out = True<EOL>iteration_n = <NUM_LIT:0><EOL>while accum_timeout < timeout:<EOL><INDENT>iteration_n+=<NUM_LIT:1><EOL>res = shutit_pexpect_session.expect(expect, timeout=iteration_s, iteration_n=iteration_n)<EOL>if res == len(expect):<EOL><INDENT>if self.build['<STR_LIT>']:<EOL><INDENT>timed_out = False<EOL>self.build['<STR_LIT>'] = False<EOL>break<EOL><DEDENT>accum_timeout += iteration_s<EOL><DEDENT>else:<EOL><INDENT>return res<EOL><DEDENT><DEDENT>if timed_out and not shutit_global.shutit_global_object.determine_interactive():<EOL><INDENT>self.log('<STR_LIT>', level=logging.DEBUG)<EOL>self.fail('<STR_LIT>') <EOL><DEDENT>else:<EOL><INDENT>if shutit_global.shutit_global_object.determine_interactive():<EOL><INDENT>shutit_pexpect_child.send('<STR_LIT>')<EOL>res = shutit_pexpect_session.expect(expect,timeout=<NUM_LIT:1>)<EOL>if res == len(expect):<EOL><INDENT>shutit_pexpect_child.send('<STR_LIT>')<EOL>res = shutit_pexpect_session.expect(expect,timeout=<NUM_LIT:1>)<EOL>if res == len(expect):<EOL><INDENT>self.fail('<STR_LIT>') <EOL><DEDENT><DEDENT>shutit_pexpect_session.pause_point('<STR_LIT>')<EOL>return res<EOL><DEDENT>else:<EOL><INDENT>if timed_out:<EOL><INDENT>self.fail('<STR_LIT>') <EOL><DEDENT>else:<EOL><INDENT>self.fail('<STR_LIT>') <EOL><DEDENT><DEDENT><DEDENT>self.fail('<STR_LIT>') <EOL>return True<EOL>
This function allows you to interrupt the run at more or less any point by breaking up the timeout into interactive chunks.
f10347:c2:m21
def run_script(self,<EOL>script,<EOL>shutit_pexpect_child=None,<EOL>in_shell=True,<EOL>echo=None,<EOL>note=None,<EOL>loglevel=logging.DEBUG):
shutit_global.shutit_global_object.yield_to_draw()<EOL>shutit_pexpect_child = shutit_pexpect_child or self.get_current_shutit_pexpect_session().pexpect_child<EOL>shutit_pexpect_session = self.get_shutit_pexpect_session_from_child(shutit_pexpect_child)<EOL>return shutit_pexpect_session.run_script(script,<EOL>in_shell=in_shell,<EOL>echo=echo,<EOL>note=note,<EOL>loglevel=loglevel)<EOL>
Run the passed-in string as a script on the target's command line. @param script: String representing the script. It will be de-indented and stripped before being run. @param shutit_pexpect_child: See send() @param in_shell: Indicate whether we are in a shell or not. (Default: True) @param note: See send() @type script: string @type in_shell: boolean
f10347:c2:m22
def send_file(self,<EOL>path,<EOL>contents,<EOL>shutit_pexpect_child=None,<EOL>truncate=False,<EOL>note=None,<EOL>user=None,<EOL>echo=False,<EOL>group=None,<EOL>loglevel=logging.INFO,<EOL>encoding=None):
shutit_global.shutit_global_object.yield_to_draw()<EOL>shutit_pexpect_child = shutit_pexpect_child or self.get_current_shutit_pexpect_session().pexpect_child<EOL>shutit_pexpect_session = self.get_shutit_pexpect_session_from_child(shutit_pexpect_child)<EOL>return shutit_pexpect_session.send_file(path,<EOL>contents,<EOL>truncate=truncate,<EOL>note=note,<EOL>echo=echo,<EOL>user=user,<EOL>group=group,<EOL>loglevel=loglevel,<EOL>encoding=encoding)<EOL>
Sends the passed-in string as a file to the passed-in path on the target. @param path: Target location of file on target. @param contents: Contents of file as a string. @param shutit_pexpect_child: See send() @param note: See send() @param user: Set ownership to this user (defaults to whoami) @param group: Set group to this user (defaults to first group in groups) @type path: string @type contents: string
f10347:c2:m23
def chdir(self,<EOL>path,<EOL>shutit_pexpect_child=None,<EOL>timeout=shutit_global.shutit_global_object.default_timeout,<EOL>note=None,<EOL>loglevel=logging.DEBUG):
shutit_global.shutit_global_object.yield_to_draw()<EOL>shutit_pexpect_child = shutit_pexpect_child or self.get_current_shutit_pexpect_session().pexpect_child<EOL>shutit_pexpect_session = self.get_shutit_pexpect_session_from_child(shutit_pexpect_child)<EOL>return shutit_pexpect_session.chdir(path,timeout=timeout,note=note,loglevel=loglevel)<EOL>
How to change directory will depend on whether we are in delivery mode bash or docker. @param path: Path to send file to. @param shutit_pexpect_child: See send() @param timeout: Timeout on response @param note: See send()
f10347:c2:m24
def send_host_file(self,<EOL>path,<EOL>hostfilepath,<EOL>expect=None,<EOL>shutit_pexpect_child=None,<EOL>note=None,<EOL>user=None,<EOL>group=None,<EOL>loglevel=logging.INFO):
shutit_global.shutit_global_object.yield_to_draw()<EOL>shutit_pexpect_child = shutit_pexpect_child or self.get_current_shutit_pexpect_session().pexpect_child<EOL>expect = expect or self.get_current_shutit_pexpect_session().default_expect<EOL>shutit_pexpect_session = self.get_shutit_pexpect_session_from_child(shutit_pexpect_child)<EOL>self.handle_note(note, '<STR_LIT>' + hostfilepath + '<STR_LIT>' + path)<EOL>self.log('<STR_LIT>' + hostfilepath + '<STR_LIT>' + path, level=loglevel)<EOL>if user is None:<EOL><INDENT>user = shutit_pexpect_session.whoami()<EOL><DEDENT>if group is None:<EOL><INDENT>group = self.whoarewe()<EOL><DEDENT>if os.path.isfile(hostfilepath):<EOL><INDENT>shutit_pexpect_session.send_file(path,<EOL>codecs.open(hostfilepath,mode='<STR_LIT:rb>',encoding='<STR_LIT>').read(),<EOL>user=user,<EOL>group=group,<EOL>loglevel=loglevel,<EOL>encoding='<STR_LIT>')<EOL><DEDENT>elif os.path.isdir(hostfilepath):<EOL><INDENT>self.send_host_dir(path,<EOL>hostfilepath,<EOL>user=user,<EOL>group=group,<EOL>loglevel=loglevel)<EOL><DEDENT>else:<EOL><INDENT>self.fail('<STR_LIT>' + hostfilepath + '<STR_LIT>' + os.getcwd(), shutit_pexpect_child=shutit_pexpect_child, throw_exception=False) <EOL><DEDENT>self.handle_note_after(note=note)<EOL>return True<EOL>
Send file from host machine to given path @param path: Path to send file to. @param hostfilepath: Path to file from host to send to target. @param expect: See send() @param shutit_pexpect_child: See send() @param note: See send() @param user: Set ownership to this user (defaults to whoami) @param group: Set group to this user (defaults to first group in groups) @type path: string @type hostfilepath: string
f10347:c2:m25
def send_host_dir(self,<EOL>path,<EOL>hostfilepath,<EOL>expect=None,<EOL>shutit_pexpect_child=None,<EOL>note=None,<EOL>user=None,<EOL>group=None,<EOL>loglevel=logging.DEBUG):
shutit_global.shutit_global_object.yield_to_draw()<EOL>shutit_pexpect_child = shutit_pexpect_child or self.get_current_shutit_pexpect_session().pexpect_child<EOL>expect = expect or self.get_current_shutit_pexpect_session().default_expect<EOL>shutit_pexpect_session = self.get_shutit_pexpect_session_from_child(shutit_pexpect_child)<EOL>self.handle_note(note, '<STR_LIT>' + hostfilepath + '<STR_LIT>' + path)<EOL>self.log('<STR_LIT>' + hostfilepath + '<STR_LIT>' + path, level=logging.INFO)<EOL>shutit_pexpect_session.send(ShutItSendSpec(shutit_pexpect_session,<EOL>send='<STR_LIT>' + path,<EOL>echo=False,<EOL>loglevel=loglevel))<EOL>if user is None:<EOL><INDENT>user = shutit_pexpect_session.whoami()<EOL><DEDENT>if group is None:<EOL><INDENT>group = self.whoarewe()<EOL><DEDENT>if shutit_pexpect_session.command_available('<STR_LIT>'):<EOL><INDENT>gzipfname = '<STR_LIT>'<EOL>with tarfile.open(gzipfname, '<STR_LIT>') as tar:<EOL><INDENT>tar.add(hostfilepath, arcname=os.path.basename(hostfilepath))<EOL><DEDENT>shutit_pexpect_session.send_file(gzipfname,<EOL>codecs.open(gzipfname,mode='<STR_LIT:rb>',encoding='<STR_LIT>').read(),<EOL>user=user,<EOL>group=group,<EOL>loglevel=loglevel,<EOL>encoding='<STR_LIT>')<EOL>shutit_pexpect_session.send(ShutItSendSpec(shutit_pexpect_session,<EOL>send='<STR_LIT>' + path + '<STR_LIT>' + path + '<STR_LIT>' + gzipfname))<EOL><DEDENT>else:<EOL><INDENT>for root, subfolders, files in os.walk(hostfilepath):<EOL><INDENT>subfolders.sort()<EOL>files.sort()<EOL>for subfolder in subfolders:<EOL><INDENT>shutit_pexpect_session.send(ShutItSendSpec(shutit_pexpect_session,<EOL>send='<STR_LIT>' + path + '<STR_LIT:/>' + subfolder,<EOL>echo=False,<EOL>loglevel=loglevel))<EOL>self.log('<STR_LIT>' + hostfilepath + '<STR_LIT:/>' + subfolder, level=logging.DEBUG)<EOL>self.send_host_dir(path + '<STR_LIT:/>' + subfolder,<EOL>hostfilepath + '<STR_LIT:/>' + subfolder,<EOL>expect=expect,<EOL>shutit_pexpect_child=shutit_pexpect_child,<EOL>loglevel=loglevel)<EOL><DEDENT>for fname in files:<EOL><INDENT>hostfullfname = os.path.join(root, fname)<EOL>targetfname = os.path.join(path, fname)<EOL>self.log('<STR_LIT>' + hostfullfname + '<STR_LIT>' + '<STR_LIT>' + targetfname, level=logging.DEBUG)<EOL>shutit_pexpect_session.send_file(targetfname,<EOL>codecs.open(hostfullfname,mode='<STR_LIT:rb>',encoding='<STR_LIT>').read(),<EOL>user=user,<EOL>group=group,<EOL>loglevel=loglevel,<EOL>encoding='<STR_LIT>')<EOL><DEDENT><DEDENT><DEDENT>self.handle_note_after(note=note)<EOL>return True<EOL>
Send directory and all contents recursively from host machine to given path. It will automatically make directories on the target. @param path: Path to send directory to (places hostfilepath inside path as a subfolder) @param hostfilepath: Path to file from host to send to target @param expect: See send() @param shutit_pexpect_child: See send() @param note: See send() @param user: Set ownership to this user (defaults to whoami) @param group: Set group to this user (defaults to first group in groups) @type path: string @type hostfilepath: string
f10347:c2:m26
def file_exists(self,<EOL>filename,<EOL>shutit_pexpect_child=None,<EOL>directory=False,<EOL>note=None,<EOL>loglevel=logging.DEBUG):
shutit_global.shutit_global_object.yield_to_draw()<EOL>shutit_pexpect_child = shutit_pexpect_child or self.get_current_shutit_pexpect_session().pexpect_child<EOL>shutit_pexpect_session = self.get_shutit_pexpect_session_from_child(shutit_pexpect_child)<EOL>return shutit_pexpect_session.file_exists(filename=filename,directory=directory,note=note,loglevel=loglevel)<EOL>
Return True if file exists on the target host, else False @param filename: Filename to determine the existence of. @param shutit_pexpect_child: See send() @param directory: Indicate that the file is a directory. @param note: See send() @type filename: string @type directory: boolean @rtype: boolean
f10347:c2:m27
def get_file_perms(self,<EOL>filename,<EOL>shutit_pexpect_child=None,<EOL>note=None,<EOL>loglevel=logging.DEBUG):
shutit_global.shutit_global_object.yield_to_draw()<EOL>shutit_pexpect_child = shutit_pexpect_child or self.get_current_shutit_pexpect_session().pexpect_child<EOL>shutit_pexpect_session = self.get_shutit_pexpect_session_from_child(shutit_pexpect_child)<EOL>return shutit_pexpect_session.get_file_perms(filename,note=note,loglevel=loglevel)<EOL>
Returns the permissions of the file on the target as an octal string triplet. @param filename: Filename to get permissions of. @param shutit_pexpect_child: See send() @param note: See send() @type filename: string @rtype: string
f10347:c2:m28
def remove_line_from_file(self,<EOL>line,<EOL>filename,<EOL>shutit_pexpect_child=None,<EOL>match_regexp=None,<EOL>literal=False,<EOL>note=None,<EOL>loglevel=logging.DEBUG):
shutit_global.shutit_global_object.yield_to_draw()<EOL>shutit_pexpect_child = shutit_pexpect_child or self.get_current_shutit_pexpect_session().pexpect_child<EOL>shutit_pexpect_session = self.get_shutit_pexpect_session_from_child(shutit_pexpect_child)<EOL>return shutit_pexpect_session.remove_line_from_file(line,filename,match_regexp=match_regexp,literal=literal,note=note,loglevel=loglevel)<EOL>
Removes line from file, if it exists. Must be exactly the line passed in to match. Returns True if there were no problems, False if there were. @param line: Line to remove. @param filename Filename to remove it from. @param shutit_pexpect_child: See send() @param match_regexp: If supplied, a regexp to look for in the file instead of the line itself, handy if the line has awkward characters in it. @param literal: If true, then simply grep for the exact string without bash interpretation. (Default: False) @param note: See send() @type line: string @type filename: string @type match_regexp: string @type literal: boolean @return: True if the line was matched and deleted, False otherwise. @rtype: boolean
f10347:c2:m29
def change_text(self,<EOL>text,<EOL>fname,<EOL>pattern=None,<EOL>expect=None,<EOL>shutit_pexpect_child=None,<EOL>before=False,<EOL>force=False,<EOL>delete=False,<EOL>note=None,<EOL>replace=False,<EOL>line_oriented=True,<EOL>create=True,<EOL>loglevel=logging.DEBUG):
shutit_global.shutit_global_object.yield_to_draw()<EOL>shutit_pexpect_child = shutit_pexpect_child or self.get_current_shutit_pexpect_session().pexpect_child<EOL>expect = expect or self.get_current_shutit_pexpect_session().default_expect<EOL>shutit_pexpect_session = self.get_shutit_pexpect_session_from_child(shutit_pexpect_child)<EOL>return shutit_pexpect_session.change_text(text,<EOL>fname,<EOL>pattern=pattern,<EOL>before=before,<EOL>force=force,<EOL>delete=delete,<EOL>note=note,<EOL>replace=replace,<EOL>line_oriented=line_oriented,<EOL>create=create,<EOL>loglevel=loglevel)<EOL>
Change text in a file. Returns None if there was no match for the regexp, True if it was matched and replaced, and False if the file did not exist or there was some other problem. @param text: Text to insert. @param fname: Filename to insert text to @param pattern: Regexp for a line to match and insert after/before/replace. If none, put at end of file. @param expect: See send() @param shutit_pexpect_child: See send() @param before: Whether to place the text before or after the matched text. @param force: Force the insertion even if the text is in the file. @param delete: Delete text from file rather than insert @param replace: Replace matched text with passed-in text. If nothing matches, then append. @param note: See send() @param line_oriented: Consider the pattern on a per-line basis (default True). Can match any continuous section of the line, eg 'b.*d' will match the line: 'abcde' If not line_oriented, the regexp is considered on with the flags re.DOTALL, re.MULTILINE enabled
f10347:c2:m30
def insert_text(self,<EOL>text,<EOL>fname,<EOL>pattern=None,<EOL>expect=None,<EOL>shutit_pexpect_child=None,<EOL>before=False,<EOL>force=False,<EOL>note=None,<EOL>replace=False,<EOL>line_oriented=True,<EOL>create=True,<EOL>loglevel=logging.DEBUG):
shutit_global.shutit_global_object.yield_to_draw()<EOL>return self.change_text(text=text,<EOL>fname=fname,<EOL>pattern=pattern,<EOL>expect=expect,<EOL>shutit_pexpect_child=shutit_pexpect_child,<EOL>before=before,<EOL>force=force,<EOL>note=note,<EOL>line_oriented=line_oriented,<EOL>create=create,<EOL>replace=replace,<EOL>delete=False,<EOL>loglevel=loglevel)<EOL>
Insert a chunk of text at the end of a file, or after (or before) the first matching pattern in given file fname. See change_text
f10347:c2:m31
def delete_text(self,<EOL>text,<EOL>fname,<EOL>pattern=None,<EOL>expect=None,<EOL>shutit_pexpect_child=None,<EOL>note=None,<EOL>before=False,<EOL>force=False,<EOL>line_oriented=True,<EOL>loglevel=logging.DEBUG):
shutit_global.shutit_global_object.yield_to_draw()<EOL>return self.change_text(text,<EOL>fname,<EOL>pattern,<EOL>expect,<EOL>shutit_pexpect_child,<EOL>before,<EOL>force,<EOL>note=note,<EOL>delete=True,<EOL>line_oriented=line_oriented,<EOL>loglevel=loglevel)<EOL>
Delete a chunk of text from a file. See insert_text.
f10347:c2:m32
def replace_text(self,<EOL>text,<EOL>fname,<EOL>pattern=None,<EOL>expect=None,<EOL>shutit_pexpect_child=None,<EOL>note=None,<EOL>before=False,<EOL>force=False,<EOL>line_oriented=True,<EOL>loglevel=logging.DEBUG):
shutit_global.shutit_global_object.yield_to_draw()<EOL>return self.change_text(text,<EOL>fname,<EOL>pattern,<EOL>expect,<EOL>shutit_pexpect_child,<EOL>before,<EOL>force,<EOL>note=note,<EOL>line_oriented=line_oriented,<EOL>replace=True,<EOL>loglevel=loglevel)<EOL>
Replace a chunk of text from a file. See insert_text.
f10347:c2:m33
def add_line_to_file(self, line, filename, expect=None, shutit_pexpect_child=None, match_regexp=None, loglevel=logging.DEBUG):
shutit_global.shutit_global_object.yield_to_draw()<EOL>if isinstance(line, str):<EOL><INDENT>lines = [line]<EOL><DEDENT>elif isinstance(line, list):<EOL><INDENT>lines = line<EOL>match_regexp = None<EOL><DEDENT>fail = False<EOL>for fline in lines:<EOL><INDENT>if match_regexp is None:<EOL><INDENT>this_match_regexp = fline<EOL><DEDENT>else:<EOL><INDENT>this_match_regexp = match_regexp<EOL><DEDENT>if not self.replace_text(fline,<EOL>filename,<EOL>pattern=this_match_regexp,<EOL>shutit_pexpect_child=shutit_pexpect_child,<EOL>expect=expect,<EOL>loglevel=loglevel):<EOL><INDENT>fail = True<EOL><DEDENT><DEDENT>if fail:<EOL><INDENT>return False<EOL><DEDENT>return True<EOL>
Deprecated. Use replace/insert_text instead. Adds line to file if it doesn't exist (unless Force is set, which it is not by default). Creates the file if it doesn't exist. Must be exactly the line passed in to match. Returns True if line(s) added OK, False if not. If you have a lot of non-unique lines to add, it's a good idea to have a sentinel value to add first, and then if that returns true, force the remainder. @param line: Line to add. If a list, processed per-item, and match_regexp ignored. @param filename: Filename to add it to. @param expect: See send() @param shutit_pexpect_child: See send() @param match_regexp: If supplied, a regexp to look for in the file instead of the line itself, handy if the line has awkward characters in it. @type line: string @type filename: string @type match_regexp: string
f10347:c2:m34
def add_to_bashrc(self, line, shutit_pexpect_child=None, match_regexp=None, note=None, loglevel=logging.DEBUG):
shutit_global.shutit_global_object.yield_to_draw()<EOL>shutit_pexpect_child = shutit_pexpect_child or self.get_current_shutit_pexpect_session().pexpect_child<EOL>shutit_pexpect_session = self.get_shutit_pexpect_session_from_child(shutit_pexpect_child)<EOL>shutit_pexpect_session.add_to_bashrc(line,match_regexp=match_regexp,note=note,loglevel=loglevel)<EOL>return True<EOL>
Takes care of adding a line to everyone's bashrc (/etc/bash.bashrc, /etc/profile). @param line: Line to add. @param shutit_pexpect_child: See send() @param match_regexp: See add_line_to_file() @param note: See send()
f10347:c2:m35
def get_url(self,<EOL>filename,<EOL>locations,<EOL>command='<STR_LIT>',<EOL>shutit_pexpect_child=None,<EOL>timeout=shutit_global.shutit_global_object.default_timeout,<EOL>fail_on_empty_before=True,<EOL>record_command=True,<EOL>exit_values=None,<EOL>retry=<NUM_LIT:3>,<EOL>note=None,<EOL>loglevel=logging.DEBUG):
shutit_global.shutit_global_object.yield_to_draw()<EOL>shutit_pexpect_child = shutit_pexpect_child or self.get_current_shutit_pexpect_session().pexpect_child<EOL>shutit_pexpect_session = self.get_shutit_pexpect_session_from_child(shutit_pexpect_child)<EOL>return shutit_pexpect_session.get_url(filename,<EOL>locations,<EOL>send=command,<EOL>timeout=timeout,<EOL>fail_on_empty_before=fail_on_empty_before,<EOL>record_command=record_command,<EOL>exit_values=exit_values,<EOL>retry=retry,<EOL>note=note,<EOL>loglevel=loglevel)<EOL>
Handles the getting of a url for you. Example: get_url('somejar.jar', ['ftp://loc.org','http://anotherloc.com/jars']) @param filename: name of the file to download @param locations: list of URLs whence the file can be downloaded @param command: program to use to download the file (Default: wget) @param shutit_pexpect_child: See send() @param timeout: See send() @param fail_on_empty_before: See send() @param record_command: See send() @param exit_values: See send() @param retry: How many times to retry the download in case of failure. Default: 3 @param note: See send() @type filename: string @type locations: list of strings @type retry: integer @return: True if the download was completed successfully, False otherwise. @rtype: boolean
f10347:c2:m36
def user_exists(self,<EOL>user,<EOL>shutit_pexpect_child=None,<EOL>note=None,<EOL>loglevel=logging.DEBUG):
shutit_global.shutit_global_object.yield_to_draw()<EOL>shutit_pexpect_child = shutit_pexpect_child or self.get_current_shutit_pexpect_session().pexpect_child<EOL>shutit_pexpect_session = self.get_shutit_pexpect_session_from_child(shutit_pexpect_child)<EOL>return shutit_pexpect_session(user,note=note,loglevel=loglevel)<EOL>
Returns true if the specified username exists. @param user: username to check for @param shutit_pexpect_child: See send() @param note: See send() @type user: string @rtype: boolean
f10347:c2:m37
def package_installed(self,<EOL>package,<EOL>shutit_pexpect_child=None,<EOL>note=None,<EOL>loglevel=logging.DEBUG):
shutit_pexpect_child = shutit_pexpect_child or self.get_current_shutit_pexpect_session().pexpect_child<EOL>shutit_pexpect_session = self.get_shutit_pexpect_session_from_child(shutit_pexpect_child)<EOL>return shutit_pexpect_session(package,note=note,loglevel=loglevel)<EOL>
Returns True if we can be sure the package is installed. @param package: Package as a string, eg 'wget'. @param shutit_pexpect_child: See send() @param note: See send() @rtype: boolean
f10347:c2:m38
def is_shutit_installed(self,<EOL>module_id,<EOL>note=None,<EOL>loglevel=logging.DEBUG):
shutit_global.shutit_global_object.yield_to_draw()<EOL>shutit_pexpect_session = self.get_current_shutit_pexpect_session()<EOL>return shutit_pexpect_session.is_shutit_installed(module_id,note=note,loglevel=loglevel)<EOL>
Helper proc to determine whether shutit has installed already here by placing a file in the db. @param module_id: Identifying string of shutit module @param note: See send()
f10347:c2:m40
def ls(self,<EOL>directory,<EOL>note=None,<EOL>loglevel=logging.DEBUG):
shutit_global.shutit_global_object.yield_to_draw()<EOL>shutit_pexpect_session = self.get_current_shutit_pexpect_session()<EOL>return shutit_pexpect_session.is_shutit_installed(directory,note=note,loglevel=loglevel)<EOL>
Helper proc to list files in a directory @param directory: directory to list. If the directory doesn't exist, shutit.fail() is called (i.e. the build fails.) @param note: See send() @type directory: string @rtype: list of strings
f10347:c2:m41
def get_file(self,<EOL>target_path,<EOL>host_path,<EOL>note=None,<EOL>loglevel=logging.DEBUG):
shutit_global.shutit_global_object.yield_to_draw()<EOL>self.handle_note(note)<EOL>if self.build['<STR_LIT>'] != '<STR_LIT>':<EOL><INDENT>return False<EOL><DEDENT>shutit_pexpect_child = self.get_shutit_pexpect_session_from_id('<STR_LIT>').pexpect_child<EOL>expect = self.expect_prompts['<STR_LIT>']<EOL>self.send('<STR_LIT>' + self.target['<STR_LIT>'] + '<STR_LIT::>' + target_path + '<STR_LIT:U+0020>' + host_path,<EOL>shutit_pexpect_child=shutit_pexpect_child,<EOL>expect=expect,<EOL>check_exit=False,<EOL>echo=False,<EOL>loglevel=loglevel)<EOL>self.handle_note_after(note=note)<EOL>return True<EOL>
Copy a file from the target machine to the host machine @param target_path: path to file in the target @param host_path: path to file on the host machine (e.g. copy test) @param note: See send() @type target_path: string @type host_path: string @return: boolean @rtype: string
f10347:c2:m42
def prompt_cfg(self, msg, sec, name, ispass=False):
shutit_global.shutit_global_object.yield_to_draw()<EOL>cfgstr = '<STR_LIT>' % (sec, name)<EOL>config_parser = self.config_parser<EOL>usercfg = os.path.join(self.host['<STR_LIT>'], '<STR_LIT>')<EOL>self.log('<STR_LIT>' % (cfgstr,),transient=True,level=logging.INFO)<EOL>self.log('<STR_LIT:\n>' + msg + '<STR_LIT:\n>',transient=True,level=logging.INFO)<EOL>if not shutit_global.shutit_global_object.determine_interactive():<EOL><INDENT>self.fail('<STR_LIT>', throw_exception=False) <EOL><DEDENT>if config_parser.has_option(sec, name):<EOL><INDENT>whereset = config_parser.whereset(sec, name)<EOL>if usercfg == whereset:<EOL><INDENT>self.fail(cfgstr + '<STR_LIT>' + usercfg + '<STR_LIT>', throw_exception=False) <EOL><DEDENT>for subcp, filename, _ in reversed(config_parser.layers):<EOL><INDENT>if filename == whereset:<EOL><INDENT>self.fail(cfgstr + '<STR_LIT>' + filename + '<STR_LIT>', throw_exception=False) <EOL><DEDENT>elif filename == usercfg:<EOL><INDENT>break<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>pass<EOL><DEDENT>if ispass:<EOL><INDENT>val = getpass.getpass('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>val = shutit_util.util_raw_input(prompt='<STR_LIT>')<EOL><DEDENT>is_excluded = (<EOL>config_parser.has_option('<STR_LIT>', sec) and<EOL>name in config_parser.get('<STR_LIT>', sec).split()<EOL>)<EOL>if not is_excluded:<EOL><INDENT>usercp = [<EOL>subcp for subcp, filename, _ in config_parser.layers<EOL>if filename == usercfg<EOL>][<NUM_LIT:0>]<EOL>if shutit_util.util_raw_input(prompt=shutit_util.colorise('<STR_LIT>', '<STR_LIT>'),default='<STR_LIT:y>') == '<STR_LIT:y>':<EOL><INDENT>sec_toset, name_toset, val_toset = sec, name, val<EOL><DEDENT>else:<EOL><INDENT>if config_parser.has_option('<STR_LIT>', sec):<EOL><INDENT>excluded = config_parser.get('<STR_LIT>', sec).split()<EOL><DEDENT>else:<EOL><INDENT>excluded = []<EOL><DEDENT>excluded.append(name)<EOL>excluded = '<STR_LIT:U+0020>'.join(excluded)<EOL>sec_toset, name_toset, val_toset = '<STR_LIT>', sec, excluded<EOL><DEDENT>if not usercp.has_section(sec_toset):<EOL><INDENT>usercp.add_section(sec_toset)<EOL><DEDENT>usercp.set(sec_toset, name_toset, val_toset)<EOL>usercp.write(open(usercfg, '<STR_LIT:w>'))<EOL>config_parser.reload()<EOL><DEDENT>return val<EOL>
Prompt for a config value, optionally saving it to the user-level cfg. Only runs if we are in an interactive mode. @param msg: Message to display to user. @param sec: Section of config to add to. @param name: Config item name. @param ispass: If True, hide the input from the terminal. Default: False. @type msg: string @type sec: string @type name: string @type ispass: boolean @return: the value entered by the user @rtype: string
f10347:c2:m43
def step_through(self, msg='<STR_LIT>', shutit_pexpect_child=None, level=<NUM_LIT:1>, print_input=True, value=True):
shutit_global.shutit_global_object.yield_to_draw()<EOL>shutit_pexpect_child = shutit_pexpect_child or self.get_current_shutit_pexpect_session().pexpect_child<EOL>shutit_pexpect_session = self.get_shutit_pexpect_session_from_child(shutit_pexpect_child)<EOL>if (not shutit_global.shutit_global_object.determine_interactive() or not shutit_global.shutit_global_object.interactive or<EOL>shutit_global.shutit_global_object.interactive < level):<EOL><INDENT>return True<EOL><DEDENT>self.build['<STR_LIT>'] = value<EOL>shutit_pexpect_session.pause_point(msg, print_input=print_input, level=level)<EOL>return True<EOL>
Implements a step-through function, using pause_point.
f10347:c2:m44
def interact(self,<EOL>msg='<STR_LIT>',<EOL>shutit_pexpect_child=None,<EOL>print_input=True,<EOL>level=<NUM_LIT:1>,<EOL>resize=True,<EOL>color='<STR_LIT>',<EOL>default_msg=None,<EOL>wait=-<NUM_LIT:1>):
shutit_global.shutit_global_object.yield_to_draw()<EOL>self.pause_point(msg=msg,<EOL>shutit_pexpect_child=shutit_pexpect_child,<EOL>print_input=print_input,<EOL>level=level,<EOL>resize=resize,<EOL>color=color,<EOL>default_msg=default_msg,<EOL>interact=True,<EOL>wait=wait)<EOL>
Same as pause_point, but sets up the terminal ready for unmediated interaction.
f10347:c2:m45
def pause_point(self,<EOL>msg='<STR_LIT>',<EOL>shutit_pexpect_child=None,<EOL>print_input=True,<EOL>level=<NUM_LIT:1>,<EOL>resize=True,<EOL>color='<STR_LIT>',<EOL>default_msg=None,<EOL>interact=False,<EOL>wait=-<NUM_LIT:1>):
shutit_global.shutit_global_object.yield_to_draw()<EOL>if (not shutit_global.shutit_global_object.determine_interactive() or shutit_global.shutit_global_object.interactive < <NUM_LIT:1> or<EOL>shutit_global.shutit_global_object.interactive < level):<EOL><INDENT>return True<EOL><DEDENT>shutit_pexpect_child = shutit_pexpect_child or self.get_current_shutit_pexpect_session().pexpect_child<EOL>log_trace_when_idle_original_value = shutit_global.shutit_global_object.log_trace_when_idle<EOL>shutit_global.shutit_global_object.log_trace_when_idle = False<EOL>if shutit_pexpect_child:<EOL><INDENT>if shutit_global.shutit_global_object.pane_manager is not None:<EOL><INDENT>shutit_global.shutit_global_object.pane_manager.draw_screen(draw_type='<STR_LIT>')<EOL>shutit_global.shutit_global_object.pane_manager.do_render = False<EOL><DEDENT>shutit_pexpect_session = self.get_shutit_pexpect_session_from_child(shutit_pexpect_child)<EOL>shutit_pexpect_session.pause_point(msg=msg,<EOL>print_input=print_input,<EOL>resize=resize,<EOL>color=color,<EOL>default_msg=default_msg,<EOL>wait=wait,<EOL>interact=interact)<EOL><DEDENT>else:<EOL><INDENT>self.log(msg,level=logging.DEBUG)<EOL>self.log('<STR_LIT>',level=logging.DEBUG)<EOL>shutit_global.shutit_global_object.handle_exit(exit_code=<NUM_LIT:1>)<EOL><DEDENT>if shutit_pexpect_child:<EOL><INDENT>if shutit_global.shutit_global_object.pane_manager is not None:<EOL><INDENT>shutit_global.shutit_global_object.pane_manager.do_render = True<EOL>shutit_global.shutit_global_object.pane_manager.draw_screen(draw_type='<STR_LIT>')<EOL><DEDENT><DEDENT>self.build['<STR_LIT>'] = False<EOL>shutit_global.shutit_global_object.log_trace_when_idle = log_trace_when_idle_original_value<EOL>return True<EOL>
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. @param msg: Message to display to user on pause point. @param shutit_pexpect_child: See send() @param print_input: Whether to take input at this point (i.e. interact), or simply pause pending any input. Default: True @param level: Minimum level to invoke the pause_point at. Default: 1 @param resize: If True, try to resize terminal. Default: False @param color: Color to print message (typically 31 for red, 32 for green) @param default_msg: Whether to print the standard blurb @param wait: Wait a few seconds rather than for input @type msg: string @type print_input: boolean @type level: integer @type resize: boolean @type wait: decimal @return: True if pause point handled ok, else false
f10347:c2:m46
def send_and_match_output(self,<EOL>send,<EOL>matches,<EOL>shutit_pexpect_child=None,<EOL>retry=<NUM_LIT:3>,<EOL>strip=True,<EOL>note=None,<EOL>echo=None,<EOL>loglevel=logging.DEBUG):
shutit_global.shutit_global_object.yield_to_draw()<EOL>shutit_pexpect_child = shutit_pexpect_child or self.get_current_shutit_pexpect_session().pexpect_child<EOL>shutit_pexpect_session = self.get_shutit_pexpect_session_from_child(shutit_pexpect_child)<EOL>return shutit_pexpect_session.send_and_match_output(send,<EOL>matches,<EOL>retry=retry,<EOL>strip=strip,<EOL>note=note,<EOL>echo=echo,<EOL>loglevel=loglevel)<EOL>
Returns true if the output of the command matches any of the strings in the matches list of regexp strings. Handles matching on a per-line basis and does not cross lines. @param send: See send() @param matches: String - or list of strings - of regexp(s) to check @param shutit_pexpect_child: See send() @param retry: Number of times to retry command (default 3) @param strip: Whether to strip output (defaults to True) @param note: See send() @type send: string @type matches: list @type retry: integer @type strip: boolean
f10347:c2:m47
def send_and_get_output(self,<EOL>send,<EOL>shutit_pexpect_child=None,<EOL>timeout=None,<EOL>retry=<NUM_LIT:3>,<EOL>strip=True,<EOL>preserve_newline=False,<EOL>note=None,<EOL>record_command=False,<EOL>echo=None,<EOL>fail_on_empty_before=True,<EOL>nonewline=False,<EOL>wait=False,<EOL>loglevel=logging.INFO):
shutit_global.shutit_global_object.yield_to_draw()<EOL>shutit_pexpect_child = shutit_pexpect_child or self.get_current_shutit_pexpect_session().pexpect_child<EOL>shutit_pexpect_session = self.get_shutit_pexpect_session_from_child(shutit_pexpect_child)<EOL>ignore_background = not wait<EOL>return shutit_pexpect_session.send_and_get_output(send,<EOL>timeout=timeout,<EOL>retry=retry,<EOL>strip=strip,<EOL>preserve_newline=preserve_newline,<EOL>note=note,<EOL>record_command=record_command,<EOL>echo=echo,<EOL>fail_on_empty_before=fail_on_empty_before,<EOL>nonewline=nonewline,<EOL>ignore_background=ignore_background,<EOL>loglevel=loglevel)<EOL>
Returns the output of a command run. send() is called, and exit is not checked. @param send: See send() @param shutit_pexpect_child: See send() @param retry: Number of times to retry command (default 3) @param strip: Whether to strip output (defaults to True). Strips whitespace and ansi terminal codes @param note: See send() @param echo: See send() @type retry: integer @type strip: boolean
f10347:c2:m48
def install(self,<EOL>package,<EOL>shutit_pexpect_child=None,<EOL>options=None,<EOL>timeout=shutit_global.shutit_global_object.default_timeout,<EOL>force=False,<EOL>check_exit=True,<EOL>echo=None,<EOL>reinstall=False,<EOL>background=False,<EOL>wait=False,<EOL>block_other_commands=True,<EOL>note=None,<EOL>loglevel=logging.INFO):
shutit_global.shutit_global_object.yield_to_draw()<EOL>shutit_pexpect_child = shutit_pexpect_child or self.get_current_shutit_pexpect_session().pexpect_child<EOL>shutit_pexpect_session = self.get_shutit_pexpect_session_from_child(shutit_pexpect_child)<EOL>ignore_background = not wait<EOL>return shutit_pexpect_session.install(package,<EOL>options=options,<EOL>timeout=timeout,<EOL>force=force,<EOL>check_exit=check_exit,<EOL>reinstall=reinstall,<EOL>echo=echo,<EOL>note=note,<EOL>run_in_background=background,<EOL>ignore_background=ignore_background,<EOL>block_other_commands=block_other_commands,<EOL>loglevel=loglevel)<EOL>
Distro-independent install function. Takes a package name and runs the relevant install function. @param package: Package to install, which is run through package_map @param shutit_pexpect_child: See send() @param timeout: Timeout (s) to wait for finish of install. Defaults to 3600. @param options: Dictionary for specific options per install tool. Overrides any arguments passed into this function. @param force: Force if necessary. Defaults to False @param check_exit: If False, failure to install is ok (default True) @param reinstall: Advise a reinstall where possible (default False) @param note: See send() @type package: string @type timeout: integer @type options: dict @type force: boolean @type check_exit: boolean @type reinstall: boolean @return: True if all ok (ie it's installed), else False. @rtype: boolean
f10347:c2:m49
def remove(self,<EOL>package,<EOL>shutit_pexpect_child=None,<EOL>options=None,<EOL>echo=None,<EOL>timeout=shutit_global.shutit_global_object.default_timeout,<EOL>note=None):
shutit_global.shutit_global_object.yield_to_draw()<EOL>if package.find('<STR_LIT:U+0020>') != -<NUM_LIT:1>:<EOL><INDENT>for p in package.split('<STR_LIT:U+0020>'):<EOL><INDENT>self.install(p,shutit_pexpect_child=shutit_pexpect_child,options=options,timeout=timeout,note=note)<EOL><DEDENT><DEDENT>shutit_pexpect_child = shutit_pexpect_child or self.get_current_shutit_pexpect_session().pexpect_child<EOL>shutit_pexpect_session = self.get_shutit_pexpect_session_from_child(shutit_pexpect_child)<EOL>return shutit_pexpect_session.remove(package,<EOL>echo=echo,<EOL>options=options,<EOL>timeout=timeout,<EOL>note=note)<EOL>
Distro-independent remove function. Takes a package name and runs relevant remove function. @param package: Package to remove, which is run through package_map. @param shutit_pexpect_child: See send() @param options: Dict of options to pass to the remove command, mapped by install_type. @param timeout: See send(). Default: 3600 @param note: See send() @return: True if all ok (i.e. the package was successfully removed), False otherwise. @rtype: boolean
f10347:c2:m50
def get_env_pass(self,<EOL>user=None,<EOL>msg=None,<EOL>shutit_pexpect_child=None,<EOL>note=None):
shutit_global.shutit_global_object.yield_to_draw()<EOL>shutit_pexpect_child = shutit_pexpect_child or self.get_current_shutit_pexpect_session().pexpect_child<EOL>shutit_pexpect_session = self.get_shutit_pexpect_session_from_child(shutit_pexpect_child)<EOL>return shutit_pexpect_session.get_env_pass(user=user,<EOL>msg=msg,<EOL>note=note)<EOL>
Gets a password from the user if one is not already recorded for this environment. @param user: username we are getting password for @param msg: message to put out there
f10347:c2:m51
def whoarewe(self,<EOL>shutit_pexpect_child=None,<EOL>note=None,<EOL>loglevel=logging.DEBUG):
shutit_global.shutit_global_object.yield_to_draw()<EOL>shutit_pexpect_child = shutit_pexpect_child or self.get_current_shutit_pexpect_session().pexpect_child<EOL>shutit_pexpect_session = self.get_shutit_pexpect_session_from_child(shutit_pexpect_child)<EOL>return shutit_pexpect_session.whoarewe(note=note,<EOL>loglevel=loglevel)<EOL>
Returns the current group. @param shutit_pexpect_child: See send() @param note: See send() @return: the first group found @rtype: string
f10347:c2:m52
def login(self,<EOL>command='<STR_LIT>',<EOL>user=None,<EOL>password=None,<EOL>prompt_prefix=None,<EOL>expect=None,<EOL>timeout=shutit_global.shutit_global_object.default_timeout,<EOL>escape=False,<EOL>echo=None,<EOL>note=None,<EOL>go_home=True,<EOL>fail_on_fail=True,<EOL>is_ssh=True,<EOL>check_sudo=True,<EOL>loglevel=logging.DEBUG):
shutit_global.shutit_global_object.yield_to_draw()<EOL>shutit_pexpect_session = self.get_current_shutit_pexpect_session()<EOL>return shutit_pexpect_session.login(ShutItSendSpec(shutit_pexpect_session,<EOL>user=user,<EOL>send=command,<EOL>password=password,<EOL>prompt_prefix=prompt_prefix,<EOL>expect=expect,<EOL>timeout=timeout,<EOL>escape=escape,<EOL>echo=echo,<EOL>note=note,<EOL>go_home=go_home,<EOL>fail_on_fail=fail_on_fail,<EOL>is_ssh=is_ssh,<EOL>check_sudo=check_sudo,<EOL>loglevel=loglevel))<EOL>
Logs user in on default child.
f10347:c2:m53
def logout_all(self,<EOL>command='<STR_LIT>',<EOL>note=None,<EOL>echo=None,<EOL>timeout=shutit_global.shutit_global_object.default_timeout,<EOL>nonewline=False,<EOL>loglevel=logging.DEBUG):
shutit_global.shutit_global_object.yield_to_draw()<EOL>for key in self.shutit_pexpect_sessions:<EOL><INDENT>shutit_pexpect_session = self.shutit_pexpect_sessions[key]<EOL>shutit_pexpect_session.logout_all(ShutItSendSpec(shutit_pexpect_session,<EOL>send=command,<EOL>note=note,<EOL>timeout=timeout,<EOL>nonewline=nonewline,<EOL>loglevel=loglevel,<EOL>echo=echo))<EOL><DEDENT>return True<EOL>
Logs the user out of all pexpect sessions within this ShutIt object. @param command: Command to run to log out (default=exit) @param note: See send()
f10347:c2:m54
def logout(self,<EOL>command='<STR_LIT>',<EOL>note=None,<EOL>echo=None,<EOL>timeout=shutit_global.shutit_global_object.default_timeout,<EOL>nonewline=False,<EOL>loglevel=logging.DEBUG):
shutit_global.shutit_global_object.yield_to_draw()<EOL>shutit_pexpect_session = self.get_current_shutit_pexpect_session()<EOL>return shutit_pexpect_session.logout(ShutItSendSpec(shutit_pexpect_session,<EOL>send=command,<EOL>note=note,<EOL>timeout=timeout,<EOL>nonewline=nonewline,<EOL>loglevel=loglevel,<EOL>echo=echo))<EOL>
Logs the user out. Assumes that login has been called. If login has never been called, throw an error. @param command: Command to run to log out (default=exit) @param note: See send()
f10347:c2:m55
def get_memory(self,<EOL>shutit_pexpect_child=None,<EOL>note=None):
shutit_global.shutit_global_object.yield_to_draw()<EOL>shutit_pexpect_child = shutit_pexpect_child or self.get_current_shutit_pexpect_session().pexpect_child<EOL>shutit_pexpect_session = self.get_shutit_pexpect_session_from_child(shutit_pexpect_child)<EOL>return shutit_pexpect_session.get_memory(note=note)<EOL>
Returns memory available for use in k as an int
f10347:c2:m57