sequence
stringlengths 546
16.2k
| code
stringlengths 108
19.3k
|
---|---|
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:put_file; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 4, identifier:self; 5, identifier:file; 6, identifier:object_type; 7, identifier:object_id; 8, identifier:width; 9, identifier:height; 10, identifier:mimetype; 11, identifier:reproducible; 12, block; 12, 13; 12, 15; 13, expression_statement; 13, 14; 14, comment; 15, raise_statement; 15, 16; 16, call; 16, 17; 16, 18; 17, identifier:NotImplementedError; 18, argument_list; 18, 19; 19, string:'put_file() has to be implemented' | def put_file(self, file, object_type, object_id, width, height, mimetype,
reproducible):
"""Puts the ``file`` of the image.
:param file: the image file to put
:type file: file-like object, :class:`file`
:param object_type: the object type of the image to put
e.g. ``'comics.cover'``
:type object_type: :class:`str`
:param object_id: the object identifier number of the image to put
:type object_id: :class:`numbers.Integral`
:param width: the width of the image to put
:type width: :class:`numbers.Integral`
:param height: the height of the image to put
:type height: :class:`numbers.Integral`
:param mimetype: the mimetype of the image to put
e.g. ``'image/jpeg'``
:type mimetype: :class:`str`
:param reproducible: :const:`True` only if it's reproducible by
computing e.g. resized thumbnails.
:const:`False` if it cannot be reproduced
e.g. original images
:type reproducible: :class:`bool`
.. note::
This is an abstract method which has to be implemented
(overridden) by subclasses.
It's not for consumers but implementations, so consumers
should use :meth:`store()` method instead of this.
"""
raise NotImplementedError('put_file() has to be implemented') |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_original_images; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, dictionary_splat_pattern; 5, 6; 6, identifier:kwargs; 7, block; 7, 8; 7, 10; 7, 46; 7, 180; 8, expression_statement; 8, 9; 9, comment; 10, function_definition; 10, 11; 10, 12; 10, 14; 11, function_name:test; 12, parameters; 12, 13; 13, identifier:image; 14, block; 14, 15; 14, 23; 14, 44; 15, if_statement; 15, 16; 15, 20; 16, not_operator; 16, 17; 17, attribute; 17, 18; 17, 19; 18, identifier:image; 19, identifier:original; 20, block; 20, 21; 21, return_statement; 21, 22; 22, False; 23, for_statement; 23, 24; 23, 27; 23, 32; 24, pattern_list; 24, 25; 24, 26; 25, identifier:filter; 26, identifier:value; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:kwargs; 30, identifier:items; 31, argument_list; 32, block; 32, 33; 33, if_statement; 33, 34; 33, 41; 34, comparison_operator:!=; 34, 35; 34, 40; 35, call; 35, 36; 35, 37; 36, identifier:getattr; 37, argument_list; 37, 38; 37, 39; 38, identifier:image; 39, identifier:filter; 40, identifier:value; 41, block; 41, 42; 42, return_statement; 42, 43; 43, False; 44, return_statement; 44, 45; 45, True; 46, if_statement; 46, 47; 46, 57; 46, 157; 47, comparison_operator:is; 47, 48; 47, 56; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:Session; 51, identifier:object_session; 52, argument_list; 52, 53; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:instance; 56, None; 57, block; 57, 58; 57, 62; 57, 83; 57, 92; 57, 131; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:images; 61, list:[]; 62, for_statement; 62, 63; 62, 66; 62, 69; 63, pattern_list; 63, 64; 63, 65; 64, identifier:image; 65, identifier:store; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:_stored_images; 69, block; 69, 70; 70, if_statement; 70, 71; 70, 75; 71, call; 71, 72; 71, 73; 72, identifier:test; 73, argument_list; 73, 74; 74, identifier:image; 75, block; 75, 76; 76, expression_statement; 76, 77; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:images; 80, identifier:append; 81, argument_list; 81, 82; 82, identifier:image; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:state; 86, call; 86, 87; 86, 88; 87, identifier:instance_state; 88, argument_list; 88, 89; 89, attribute; 89, 90; 89, 91; 90, identifier:self; 91, identifier:instance; 92, try_statement; 92, 93; 92, 108; 92, 112; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:added; 97, attribute; 97, 98; 97, 107; 98, subscript; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:state; 101, identifier:committed_state; 102, attribute; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:self; 105, identifier:attr; 106, identifier:key; 107, identifier:added_items; 108, except_clause; 108, 109; 108, 110; 109, identifier:KeyError; 110, block; 110, 111; 111, pass_statement; 112, else_clause; 112, 113; 113, block; 113, 114; 114, for_statement; 114, 115; 114, 116; 114, 117; 115, identifier:image; 116, identifier:added; 117, block; 117, 118; 118, if_statement; 118, 119; 118, 123; 119, call; 119, 120; 119, 121; 120, identifier:test; 121, argument_list; 121, 122; 122, identifier:image; 123, block; 123, 124; 124, expression_statement; 124, 125; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:images; 128, identifier:append; 129, argument_list; 129, 130; 130, identifier:image; 131, if_statement; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:self; 134, identifier:session; 135, block; 135, 136; 136, for_statement; 136, 137; 136, 138; 136, 143; 137, identifier:image; 138, attribute; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:self; 141, identifier:session; 142, identifier:new; 143, block; 143, 144; 144, if_statement; 144, 145; 144, 149; 145, call; 145, 146; 145, 147; 146, identifier:test; 147, argument_list; 147, 148; 148, identifier:image; 149, block; 149, 150; 150, expression_statement; 150, 151; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:images; 154, identifier:append; 155, argument_list; 155, 156; 156, identifier:image; 157, else_clause; 157, 158; 158, block; 158, 159; 158, 172; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:query; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:self; 165, identifier:filter_by; 166, argument_list; 166, 167; 166, 170; 167, keyword_argument; 167, 168; 167, 169; 168, identifier:original; 169, True; 170, dictionary_splat; 170, 171; 171, identifier:kwargs; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:images; 175, call; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:query; 178, identifier:all; 179, argument_list; 180, return_statement; 180, 181; 181, identifier:images | def _original_images(self, **kwargs):
"""A list of the original images.
:returns: A list of the original images.
:rtype: :class:`typing.Sequence`\ [:class:`Image`]
"""
def test(image):
if not image.original:
return False
for filter, value in kwargs.items():
if getattr(image, filter) != value:
return False
return True
if Session.object_session(self.instance) is None:
images = []
for image, store in self._stored_images:
if test(image):
images.append(image)
state = instance_state(self.instance)
try:
added = state.committed_state[self.attr.key].added_items
except KeyError:
pass
else:
for image in added:
if test(image):
images.append(image)
if self.session:
for image in self.session.new:
if test(image):
images.append(image)
else:
query = self.filter_by(original=True, **kwargs)
images = query.all()
return images |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:from_file; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:self; 5, identifier:file; 6, default_parameter; 6, 7; 6, 8; 7, identifier:store; 8, identifier:current_store; 9, default_parameter; 9, 10; 9, 11; 10, identifier:extra_args; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:extra_kwargs; 14, None; 15, block; 15, 16; 15, 18; 15, 33; 15, 41; 15, 49; 15, 56; 16, expression_statement; 16, 17; 17, comment; 18, if_statement; 18, 19; 18, 26; 19, call; 19, 20; 19, 21; 20, identifier:isinstance; 21, argument_list; 21, 22; 21, 23; 22, identifier:file; 23, attribute; 23, 24; 23, 25; 24, identifier:cgi; 25, identifier:FieldStorage; 26, block; 26, 27; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:file; 30, attribute; 30, 31; 30, 32; 31, identifier:file; 32, identifier:file; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:data; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:io; 39, identifier:BytesIO; 40, argument_list; 41, expression_statement; 41, 42; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:shutil; 45, identifier:copyfileobj; 46, argument_list; 46, 47; 46, 48; 47, identifier:file; 48, identifier:data; 49, expression_statement; 49, 50; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:data; 53, identifier:seek; 54, argument_list; 54, 55; 55, integer:0; 56, return_statement; 56, 57; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:from_raw_file; 61, argument_list; 61, 62; 61, 63; 61, 64; 61, 67; 61, 70; 62, identifier:data; 63, identifier:store; 64, keyword_argument; 64, 65; 64, 66; 65, identifier:original; 66, True; 67, keyword_argument; 67, 68; 67, 69; 68, identifier:extra_args; 69, identifier:extra_args; 70, keyword_argument; 70, 71; 70, 72; 71, identifier:extra_kwargs; 72, identifier:extra_kwargs | def from_file(self, file, store=current_store,
extra_args=None, extra_kwargs=None):
"""Stores the ``file`` for the image into the ``store``.
:param file: the readable file of the image
:type file: file-like object, :class:`file`
:param store: the storage to store the file.
:data:`~sqlalchemy_imageattach.context.current_store`
by default
:type store: :class:`~sqlalchemy_imageattach.store.Store`
:param extra_args: additional arguments to pass to the model's
constructor.
:type extra_args: :class:`collections.abc.Sequence`
:param extra_kwargs: additional keyword arguments to pass to the
model's constructor.
:type extra_kwargs: :class:`typing.Mapping`\ [:class:`str`,
:class:`object`]
:returns: the created image instance
:rtype: :class:`Image`
.. versionadded:: 1.0.0
The ``extra_args`` and ``extra_kwargs`` options.
"""
if isinstance(file, cgi.FieldStorage):
file = file.file
data = io.BytesIO()
shutil.copyfileobj(file, data)
data.seek(0)
return self.from_raw_file(data, store, original=True,
extra_args=extra_args,
extra_kwargs=extra_kwargs) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:copy_modules; 3, parameters; 3, 4; 3, 7; 3, 10; 4, default_parameter; 4, 5; 4, 6; 5, identifier:filespath; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:modules_path; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:verbose; 12, None; 13, block; 13, 14; 13, 16; 13, 17; 13, 114; 13, 115; 13, 127; 13, 145; 13, 146; 13, 159; 13, 176; 13, 220; 13, 221; 13, 233; 14, expression_statement; 14, 15; 15, string:''' Copy over the tree module files into your path '''; 16, comment; 17, if_statement; 17, 18; 17, 20; 18, not_operator; 18, 19; 19, identifier:modules_path; 20, block; 20, 21; 20, 30; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:modulepath; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:os; 27, identifier:getenv; 28, argument_list; 28, 29; 29, string:"MODULEPATH"; 30, if_statement; 30, 31; 30, 33; 30, 41; 31, not_operator; 31, 32; 32, identifier:modulepath; 33, block; 33, 34; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:modules_path; 37, call; 37, 38; 37, 39; 38, identifier:input; 39, argument_list; 39, 40; 40, string:'Enter the root path for your module files:'; 41, else_clause; 41, 42; 42, block; 42, 43; 42, 52; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:split_mods; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:modulepath; 49, identifier:split; 50, argument_list; 50, 51; 51, string:':'; 52, if_statement; 52, 53; 52, 59; 52, 106; 53, comparison_operator:>; 53, 54; 53, 58; 54, call; 54, 55; 54, 56; 55, identifier:len; 56, argument_list; 56, 57; 57, identifier:split_mods; 58, integer:1; 59, block; 59, 60; 59, 68; 60, if_statement; 60, 61; 60, 62; 61, identifier:verbose; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, call; 64, 65; 64, 66; 65, identifier:print; 66, argument_list; 66, 67; 67, string:'Multiple module paths found. Finding all that contain a tree directory.'; 68, for_statement; 68, 69; 68, 70; 68, 71; 69, identifier:mfile; 70, identifier:split_mods; 71, block; 71, 72; 72, if_statement; 72, 73; 72, 89; 72, 103; 73, call; 73, 74; 73, 79; 74, attribute; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:os; 77, identifier:path; 78, identifier:exists; 79, argument_list; 79, 80; 80, call; 80, 81; 80, 86; 81, attribute; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:os; 84, identifier:path; 85, identifier:join; 86, argument_list; 86, 87; 86, 88; 87, identifier:mfile; 88, string:'tree'; 89, block; 89, 90; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 93; 92, identifier:copy_modules; 93, argument_list; 93, 94; 93, 97; 93, 100; 94, keyword_argument; 94, 95; 94, 96; 95, identifier:filespath; 96, identifier:filespath; 97, keyword_argument; 97, 98; 97, 99; 98, identifier:modules_path; 99, identifier:mfile; 100, keyword_argument; 100, 101; 100, 102; 101, identifier:verbose; 102, identifier:verbose; 103, else_clause; 103, 104; 104, block; 104, 105; 105, return_statement; 106, else_clause; 106, 107; 107, block; 107, 108; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:modules_path; 111, subscript; 111, 112; 111, 113; 112, identifier:split_mods; 113, integer:0; 114, comment; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:tree_mod; 118, call; 118, 119; 118, 124; 119, attribute; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:os; 122, identifier:path; 123, identifier:join; 124, argument_list; 124, 125; 124, 126; 125, identifier:modules_path; 126, string:'tree'; 127, if_statement; 127, 128; 127, 137; 128, not_operator; 128, 129; 129, call; 129, 130; 129, 135; 130, attribute; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:os; 133, identifier:path; 134, identifier:isdir; 135, argument_list; 135, 136; 136, identifier:tree_mod; 137, block; 137, 138; 138, expression_statement; 138, 139; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:os; 142, identifier:makedirs; 143, argument_list; 143, 144; 144, identifier:tree_mod; 145, comment; 146, if_statement; 146, 147; 146, 148; 147, identifier:verbose; 148, block; 148, 149; 149, expression_statement; 149, 150; 150, call; 150, 151; 150, 152; 151, identifier:print; 152, argument_list; 152, 153; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, string:'Copying modules from etc/ into {0}'; 156, identifier:format; 157, argument_list; 157, 158; 158, identifier:tree_mod; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:module_files; 162, call; 162, 163; 162, 166; 163, attribute; 163, 164; 163, 165; 164, identifier:glob; 165, identifier:glob; 166, argument_list; 166, 167; 167, call; 167, 168; 167, 173; 168, attribute; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:os; 171, identifier:path; 172, identifier:join; 173, argument_list; 173, 174; 173, 175; 174, identifier:filespath; 175, string:'*.module'; 176, for_statement; 176, 177; 176, 178; 176, 179; 177, identifier:mfile; 178, identifier:module_files; 179, block; 179, 180; 179, 200; 179, 212; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 183; 182, identifier:base; 183, subscript; 183, 184; 183, 199; 184, call; 184, 185; 184, 190; 185, attribute; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:os; 188, identifier:path; 189, identifier:splitext; 190, argument_list; 190, 191; 191, call; 191, 192; 191, 197; 192, attribute; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:os; 195, identifier:path; 196, identifier:basename; 197, argument_list; 197, 198; 198, identifier:mfile; 199, integer:0; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 203; 202, identifier:tree_out; 203, call; 203, 204; 203, 209; 204, attribute; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:os; 207, identifier:path; 208, identifier:join; 209, argument_list; 209, 210; 209, 211; 210, identifier:tree_mod; 211, identifier:base; 212, expression_statement; 212, 213; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:shutil; 216, identifier:copy2; 217, argument_list; 217, 218; 217, 219; 218, identifier:mfile; 219, identifier:tree_out; 220, comment; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 224; 223, identifier:version; 224, call; 224, 225; 224, 230; 225, attribute; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:os; 228, identifier:path; 229, identifier:join; 230, argument_list; 230, 231; 230, 232; 231, identifier:filespath; 232, string:'.version'; 233, if_statement; 233, 234; 233, 242; 234, call; 234, 235; 234, 240; 235, attribute; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:os; 238, identifier:path; 239, identifier:isfile; 240, argument_list; 240, 241; 241, identifier:version; 242, block; 242, 243; 243, expression_statement; 243, 244; 244, call; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:shutil; 247, identifier:copy2; 248, argument_list; 248, 249; 248, 250; 249, identifier:version; 250, identifier:tree_mod | def copy_modules(filespath=None, modules_path=None, verbose=None):
''' Copy over the tree module files into your path '''
# find or define a modules path
if not modules_path:
modulepath = os.getenv("MODULEPATH")
if not modulepath:
modules_path = input('Enter the root path for your module files:')
else:
split_mods = modulepath.split(':')
if len(split_mods) > 1:
if verbose:
print('Multiple module paths found. Finding all that contain a tree directory.')
for mfile in split_mods:
if os.path.exists(os.path.join(mfile, 'tree')):
copy_modules(filespath=filespath, modules_path=mfile, verbose=verbose)
else:
return
else:
modules_path = split_mods[0]
# check for the tree module directory
tree_mod = os.path.join(modules_path, 'tree')
if not os.path.isdir(tree_mod):
os.makedirs(tree_mod)
# copy the modules into the tree
if verbose:
print('Copying modules from etc/ into {0}'.format(tree_mod))
module_files = glob.glob(os.path.join(filespath, '*.module'))
for mfile in module_files:
base = os.path.splitext(os.path.basename(mfile))[0]
tree_out = os.path.join(tree_mod, base)
shutil.copy2(mfile, tree_out)
# copy the default version into the tree
version = os.path.join(filespath, '.version')
if os.path.isfile(version):
shutil.copy2(version, tree_mod) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:_repr_html_; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:indices; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:iops; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:lx; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:li; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:lls; 19, None; 20, block; 20, 21; 20, 23; 20, 29; 20, 35; 20, 49; 20, 88; 20, 113; 20, 117; 20, 150; 20, 151; 20, 156; 20, 163; 20, 170; 20, 184; 20, 212; 20, 238; 20, 249; 20, 308; 21, expression_statement; 21, 22; 22, comment; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:filter_; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:_current_slice_; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:vals; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:flat; 35, if_statement; 35, 36; 35, 39; 36, comparison_operator:is; 36, 37; 36, 38; 37, identifier:indices; 38, None; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:indices; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:_indices; 47, argument_list; 47, 48; 48, identifier:filter_; 49, if_statement; 49, 50; 49, 53; 50, comparison_operator:is; 50, 51; 50, 52; 51, identifier:iops; 52, None; 53, block; 53, 54; 53, 63; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:ravi; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:_raveled_index; 61, argument_list; 61, 62; 62, identifier:filter_; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:iops; 66, call; 66, 67; 66, 68; 67, identifier:OrderedDict; 68, generator_expression; 68, 69; 68, 77; 69, list:[name, iop.properties_for(ravi)]; 69, 70; 69, 71; 70, identifier:name; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:iop; 74, identifier:properties_for; 75, argument_list; 75, 76; 76, identifier:ravi; 77, for_in_clause; 77, 78; 77, 81; 78, pattern_list; 78, 79; 78, 80; 79, identifier:name; 80, identifier:iop; 81, call; 81, 82; 81, 87; 82, attribute; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:self; 85, identifier:_index_operations; 86, identifier:items; 87, argument_list; 88, if_statement; 88, 89; 88, 92; 89, comparison_operator:is; 89, 90; 89, 91; 90, identifier:lls; 91, None; 92, block; 92, 93; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:lls; 96, list_comprehension; 96, 97; 96, 104; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:self; 100, identifier:_max_len_names; 101, argument_list; 101, 102; 101, 103; 102, identifier:iop; 103, identifier:name; 104, for_in_clause; 104, 105; 104, 108; 105, pattern_list; 105, 106; 105, 107; 106, identifier:name; 107, identifier:iop; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:iops; 111, identifier:items; 112, argument_list; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:header_format; 116, comment; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:header; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:header_format; 123, identifier:format; 124, argument_list; 124, 125; 124, 132; 124, 135; 125, keyword_argument; 125, 126; 125, 127; 126, identifier:x; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:self; 130, identifier:hierarchy_name; 131, argument_list; 132, keyword_argument; 132, 133; 132, 134; 133, identifier:i; 134, identifier:__index_name__; 135, keyword_argument; 135, 136; 135, 137; 136, identifier:iops; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, string:"</b></th><th><b>"; 140, identifier:join; 141, argument_list; 141, 142; 142, call; 142, 143; 142, 144; 143, identifier:list; 144, argument_list; 144, 145; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:iops; 148, identifier:keys; 149, argument_list; 150, comment; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:to_print; 154, list:["""<style type="text/css">
.tg {padding:2px 3px;word-break:normal;border-collapse:collapse;border-spacing:0;border-color:#DCDCDC;margin:0px auto;width:100%;}
.tg td{font-family:"Courier New", Courier, monospace !important;font-weight:bold;color:#444;background-color:#F7FDFA;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:#DCDCDC;}
.tg th{font-family:"Courier New", Courier, monospace !important;font-weight:normal;color:#fff;background-color:#26ADE4;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:#DCDCDC;}
.tg .tg-left{font-family:"Courier New", Courier, monospace !important;font-weight:normal;text-align:left;}
.tg .tg-right{font-family:"Courier New", Courier, monospace !important;font-weight:normal;text-align:right;}
</style>"""]; 154, 155; 155, comment; 156, expression_statement; 156, 157; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:to_print; 160, identifier:append; 161, argument_list; 161, 162; 162, string:'<table class="tg">'; 163, expression_statement; 163, 164; 164, call; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:to_print; 167, identifier:append; 168, argument_list; 168, 169; 169, identifier:header; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 173; 172, identifier:format_spec; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:self; 176, identifier:_format_spec; 177, argument_list; 177, 178; 177, 179; 177, 180; 177, 181; 177, 182; 177, 183; 178, identifier:indices; 179, identifier:iops; 180, identifier:lx; 181, identifier:li; 182, identifier:lls; 183, False; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 191; 186, subscript; 186, 187; 186, 188; 187, identifier:format_spec; 188, slice; 188, 189; 188, 190; 189, colon; 190, integer:2; 191, list:["<tr><td class=tg-left>{i}</td>".format(i=format_spec[0]), "<td class=tg-right>{i}</td>".format(i=format_spec[1])]; 191, 192; 191, 202; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, string:"<tr><td class=tg-left>{i}</td>"; 195, identifier:format; 196, argument_list; 196, 197; 197, keyword_argument; 197, 198; 197, 199; 198, identifier:i; 199, subscript; 199, 200; 199, 201; 200, identifier:format_spec; 201, integer:0; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, string:"<td class=tg-right>{i}</td>"; 205, identifier:format; 206, argument_list; 206, 207; 207, keyword_argument; 207, 208; 207, 209; 208, identifier:i; 209, subscript; 209, 210; 209, 211; 210, identifier:format_spec; 211, integer:1; 212, for_statement; 212, 213; 212, 214; 212, 222; 213, identifier:i; 214, call; 214, 215; 214, 216; 215, identifier:range; 216, argument_list; 216, 217; 216, 218; 217, integer:2; 218, call; 218, 219; 218, 220; 219, identifier:len; 220, argument_list; 220, 221; 221, identifier:format_spec; 222, block; 222, 223; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 228; 225, subscript; 225, 226; 225, 227; 226, identifier:format_spec; 227, identifier:i; 228, call; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, string:'<td class=tg-left>{c}</td>'; 231, identifier:format; 232, argument_list; 232, 233; 233, keyword_argument; 233, 234; 233, 235; 234, identifier:c; 235, subscript; 235, 236; 235, 237; 236, identifier:format_spec; 237, identifier:i; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 241; 240, identifier:format_spec; 241, binary_operator:+; 241, 242; 241, 248; 242, call; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, string:""; 245, identifier:join; 246, argument_list; 246, 247; 247, identifier:format_spec; 248, string:'</tr>'; 249, for_statement; 249, 250; 249, 251; 249, 257; 250, identifier:i; 251, call; 251, 252; 251, 253; 252, identifier:range; 253, argument_list; 253, 254; 254, attribute; 254, 255; 254, 256; 255, identifier:self; 256, identifier:size; 257, block; 257, 258; 258, expression_statement; 258, 259; 259, call; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, identifier:to_print; 262, identifier:append; 263, argument_list; 263, 264; 264, call; 264, 265; 264, 268; 265, attribute; 265, 266; 265, 267; 266, identifier:format_spec; 267, identifier:format; 268, argument_list; 268, 269; 268, 274; 268, 285; 269, keyword_argument; 269, 270; 269, 271; 270, identifier:index; 271, subscript; 271, 272; 271, 273; 272, identifier:indices; 273, identifier:i; 274, keyword_argument; 274, 275; 274, 276; 275, identifier:value; 276, call; 276, 277; 276, 280; 277, attribute; 277, 278; 277, 279; 278, string:"{1:.{0}f}"; 279, identifier:format; 280, argument_list; 280, 281; 280, 282; 281, identifier:__precision__; 282, subscript; 282, 283; 282, 284; 283, identifier:vals; 284, identifier:i; 285, dictionary_splat; 285, 286; 286, call; 286, 287; 286, 288; 287, identifier:dict; 288, generator_expression; 288, 289; 288, 305; 289, tuple; 289, 290; 289, 291; 290, identifier:name; 291, call; 291, 292; 291, 295; 292, attribute; 292, 293; 292, 294; 293, string:' '; 294, identifier:join; 295, argument_list; 295, 296; 296, call; 296, 297; 296, 298; 297, identifier:map; 298, argument_list; 298, 299; 298, 300; 299, identifier:str; 300, subscript; 300, 301; 300, 304; 301, subscript; 301, 302; 301, 303; 302, identifier:iops; 303, identifier:name; 304, identifier:i; 305, for_in_clause; 305, 306; 305, 307; 306, identifier:name; 307, identifier:iops; 308, return_statement; 308, 309; 309, call; 309, 310; 309, 313; 310, attribute; 310, 311; 310, 312; 311, string:'\n'; 312, identifier:join; 313, argument_list; 313, 314; 314, identifier:to_print | def _repr_html_(self, indices=None, iops=None, lx=None, li=None, lls=None):
"""Representation of the parameter in html for notebook display."""
filter_ = self._current_slice_
vals = self.flat
if indices is None: indices = self._indices(filter_)
if iops is None:
ravi = self._raveled_index(filter_)
iops = OrderedDict([name, iop.properties_for(ravi)] for name, iop in self._index_operations.items())
if lls is None: lls = [self._max_len_names(iop, name) for name, iop in iops.items()]
header_format = """
<tr>
<th><b>{i}</b></th>
<th><b>{x}</b></th>
<th><b>{iops}</b></th>
</tr>"""
header = header_format.format(x=self.hierarchy_name(), i=__index_name__, iops="</b></th><th><b>".join(list(iops.keys()))) # nice header for printing
to_print = ["""<style type="text/css">
.tg {padding:2px 3px;word-break:normal;border-collapse:collapse;border-spacing:0;border-color:#DCDCDC;margin:0px auto;width:100%;}
.tg td{font-family:"Courier New", Courier, monospace !important;font-weight:bold;color:#444;background-color:#F7FDFA;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:#DCDCDC;}
.tg th{font-family:"Courier New", Courier, monospace !important;font-weight:normal;color:#fff;background-color:#26ADE4;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:#DCDCDC;}
.tg .tg-left{font-family:"Courier New", Courier, monospace !important;font-weight:normal;text-align:left;}
.tg .tg-right{font-family:"Courier New", Courier, monospace !important;font-weight:normal;text-align:right;}
</style>"""]
to_print.append('<table class="tg">')
to_print.append(header)
format_spec = self._format_spec(indices, iops, lx, li, lls, False)
format_spec[:2] = ["<tr><td class=tg-left>{i}</td>".format(i=format_spec[0]), "<td class=tg-right>{i}</td>".format(i=format_spec[1])]
for i in range(2, len(format_spec)):
format_spec[i] = '<td class=tg-left>{c}</td>'.format(c=format_spec[i])
format_spec = "".join(format_spec) + '</tr>'
for i in range(self.size):
to_print.append(format_spec.format(index=indices[i], value="{1:.{0}f}".format(__precision__, vals[i]), **dict((name, ' '.join(map(str, iops[name][i]))) for name in iops)))
return '\n'.join(to_print) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 22; 2, function_name:optimize_restarts; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:num_restarts; 7, integer:10; 8, default_parameter; 8, 9; 8, 10; 9, identifier:robust; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:verbose; 13, True; 14, default_parameter; 14, 15; 14, 16; 15, identifier:parallel; 16, False; 17, default_parameter; 17, 18; 17, 19; 18, identifier:num_processes; 19, None; 20, dictionary_splat_pattern; 20, 21; 21, identifier:kwargs; 22, block; 22, 23; 22, 25; 22, 34; 22, 44; 22, 141; 22, 239; 22, 293; 23, expression_statement; 23, 24; 24, comment; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:initial_length; 28, call; 28, 29; 28, 30; 29, identifier:len; 30, argument_list; 30, 31; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:optimization_runs; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:initial_parameters; 37, call; 37, 38; 37, 43; 38, attribute; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:optimizer_array; 42, identifier:copy; 43, argument_list; 44, if_statement; 44, 45; 44, 46; 44, 47; 45, identifier:parallel; 46, comment; 47, block; 47, 48; 48, try_statement; 48, 49; 48, 121; 49, block; 49, 50; 49, 61; 49, 76; 49, 93; 49, 109; 49, 115; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:pool; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:mp; 56, identifier:Pool; 57, argument_list; 57, 58; 58, keyword_argument; 58, 59; 58, 60; 59, identifier:processes; 60, identifier:num_processes; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:obs; 64, list_comprehension; 64, 65; 64, 70; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:copy; 69, argument_list; 70, for_in_clause; 70, 71; 70, 72; 71, identifier:i; 72, call; 72, 73; 72, 74; 73, identifier:range; 74, argument_list; 74, 75; 75, identifier:num_restarts; 76, expression_statement; 76, 77; 77, list_comprehension; 77, 78; 77, 85; 78, call; 78, 79; 78, 84; 79, attribute; 79, 80; 79, 83; 80, subscript; 80, 81; 80, 82; 81, identifier:obs; 82, identifier:i; 83, identifier:randomize; 84, argument_list; 85, for_in_clause; 85, 86; 85, 87; 86, identifier:i; 87, call; 87, 88; 87, 89; 88, identifier:range; 89, argument_list; 89, 90; 90, binary_operator:-; 90, 91; 90, 92; 91, identifier:num_restarts; 92, integer:1; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:jobs; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:pool; 99, identifier:map; 100, argument_list; 100, 101; 100, 102; 101, identifier:opt_wrapper; 102, list_comprehension; 102, 103; 102, 106; 103, tuple; 103, 104; 103, 105; 104, identifier:o; 105, identifier:kwargs; 106, for_in_clause; 106, 107; 106, 108; 107, identifier:o; 108, identifier:obs; 109, expression_statement; 109, 110; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:pool; 113, identifier:close; 114, argument_list; 115, expression_statement; 115, 116; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:pool; 119, identifier:join; 120, argument_list; 121, except_clause; 121, 122; 121, 123; 122, identifier:KeyboardInterrupt; 123, block; 123, 124; 123, 129; 123, 135; 124, expression_statement; 124, 125; 125, call; 125, 126; 125, 127; 126, identifier:print; 127, argument_list; 127, 128; 128, string:"Ctrl+c received, terminating and joining pool."; 129, expression_statement; 129, 130; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:pool; 133, identifier:terminate; 134, argument_list; 135, expression_statement; 135, 136; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:pool; 139, identifier:join; 140, argument_list; 141, for_statement; 141, 142; 141, 143; 141, 147; 142, identifier:i; 143, call; 143, 144; 143, 145; 144, identifier:range; 145, argument_list; 145, 146; 146, identifier:num_restarts; 147, block; 147, 148; 148, try_statement; 148, 149; 148, 212; 149, block; 149, 150; 149, 187; 150, if_statement; 150, 151; 150, 153; 150, 173; 151, not_operator; 151, 152; 152, identifier:parallel; 153, block; 153, 154; 153, 165; 154, if_statement; 154, 155; 154, 158; 155, comparison_operator:>; 155, 156; 155, 157; 156, identifier:i; 157, integer:0; 158, block; 158, 159; 159, expression_statement; 159, 160; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:self; 163, identifier:randomize; 164, argument_list; 165, expression_statement; 165, 166; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:self; 169, identifier:optimize; 170, argument_list; 170, 171; 171, dictionary_splat; 171, 172; 172, identifier:kwargs; 173, else_clause; 173, 174; 173, 175; 174, comment; 175, block; 175, 176; 176, expression_statement; 176, 177; 177, call; 177, 178; 177, 183; 178, attribute; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:self; 181, identifier:optimization_runs; 182, identifier:append; 183, argument_list; 183, 184; 184, subscript; 184, 185; 184, 186; 185, identifier:jobs; 186, identifier:i; 187, if_statement; 187, 188; 187, 189; 188, identifier:verbose; 189, block; 189, 190; 190, expression_statement; 190, 191; 191, call; 191, 192; 191, 193; 192, identifier:print; 193, argument_list; 193, 194; 194, parenthesized_expression; 194, 195; 195, call; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, string:"Optimization restart {0}/{1}, f = {2}"; 198, identifier:format; 199, argument_list; 199, 200; 199, 203; 199, 204; 200, binary_operator:+; 200, 201; 200, 202; 201, identifier:i; 202, integer:1; 203, identifier:num_restarts; 204, attribute; 204, 205; 204, 211; 205, subscript; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:self; 208, identifier:optimization_runs; 209, unary_operator:-; 209, 210; 210, integer:1; 211, identifier:f_opt; 212, except_clause; 212, 213; 212, 217; 213, as_pattern; 213, 214; 213, 215; 214, identifier:Exception; 215, as_pattern_target; 215, 216; 216, identifier:e; 217, block; 217, 218; 218, if_statement; 218, 219; 218, 220; 218, 235; 219, identifier:robust; 220, block; 220, 221; 221, expression_statement; 221, 222; 222, call; 222, 223; 222, 224; 223, identifier:print; 224, argument_list; 224, 225; 225, parenthesized_expression; 225, 226; 226, call; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, string:"Warning - optimization restart {0}/{1} failed"; 229, identifier:format; 230, argument_list; 230, 231; 230, 234; 231, binary_operator:+; 231, 232; 231, 233; 232, identifier:i; 233, integer:1; 234, identifier:num_restarts; 235, else_clause; 235, 236; 236, block; 236, 237; 237, raise_statement; 237, 238; 238, identifier:e; 239, if_statement; 239, 240; 239, 248; 239, 249; 239, 285; 240, comparison_operator:>; 240, 241; 240, 247; 241, call; 241, 242; 241, 243; 242, identifier:len; 243, argument_list; 243, 244; 244, attribute; 244, 245; 244, 246; 245, identifier:self; 246, identifier:optimization_runs; 247, identifier:initial_length; 248, comment; 249, block; 249, 250; 249, 271; 250, expression_statement; 250, 251; 251, assignment; 251, 252; 251, 253; 252, identifier:i; 253, call; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, identifier:np; 256, identifier:argmin; 257, argument_list; 257, 258; 258, list_comprehension; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:o; 261, identifier:f_opt; 262, for_in_clause; 262, 263; 262, 264; 263, identifier:o; 264, subscript; 264, 265; 264, 268; 265, attribute; 265, 266; 265, 267; 266, identifier:self; 267, identifier:optimization_runs; 268, slice; 268, 269; 268, 270; 269, identifier:initial_length; 270, colon; 271, expression_statement; 271, 272; 272, assignment; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:self; 275, identifier:optimizer_array; 276, attribute; 276, 277; 276, 284; 277, subscript; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, identifier:self; 280, identifier:optimization_runs; 281, binary_operator:+; 281, 282; 281, 283; 282, identifier:initial_length; 283, identifier:i; 284, identifier:x_opt; 285, else_clause; 285, 286; 286, block; 286, 287; 287, expression_statement; 287, 288; 288, assignment; 288, 289; 288, 292; 289, attribute; 289, 290; 289, 291; 290, identifier:self; 291, identifier:optimizer_array; 292, identifier:initial_parameters; 293, return_statement; 293, 294; 294, attribute; 294, 295; 294, 296; 295, identifier:self; 296, identifier:optimization_runs | def optimize_restarts(self, num_restarts=10, robust=False, verbose=True, parallel=False, num_processes=None, **kwargs):
"""
Perform random restarts of the model, and set the model to the best
seen solution.
If the robust flag is set, exceptions raised during optimizations will
be handled silently. If _all_ runs fail, the model is reset to the
existing parameter values.
\*\*kwargs are passed to the optimizer.
:param num_restarts: number of restarts to use (default 10)
:type num_restarts: int
:param robust: whether to handle exceptions silently or not (default False)
:type robust: bool
:param parallel: whether to run each restart as a separate process. It relies on the multiprocessing module.
:type parallel: bool
:param num_processes: number of workers in the multiprocessing pool
:type numprocesses: int
:param max_f_eval: maximum number of function evaluations
:type max_f_eval: int
:param max_iters: maximum number of iterations
:type max_iters: int
:param messages: whether to display during optimisation
:type messages: bool
.. note::
If num_processes is None, the number of workes in the
multiprocessing pool is automatically set to the number of processors
on the current machine.
"""
initial_length = len(self.optimization_runs)
initial_parameters = self.optimizer_array.copy()
if parallel: #pragma: no cover
try:
pool = mp.Pool(processes=num_processes)
obs = [self.copy() for i in range(num_restarts)]
[obs[i].randomize() for i in range(num_restarts-1)]
jobs = pool.map(opt_wrapper, [(o,kwargs) for o in obs])
pool.close()
pool.join()
except KeyboardInterrupt:
print("Ctrl+c received, terminating and joining pool.")
pool.terminate()
pool.join()
for i in range(num_restarts):
try:
if not parallel:
if i > 0:
self.randomize()
self.optimize(**kwargs)
else:#pragma: no cover
self.optimization_runs.append(jobs[i])
if verbose:
print(("Optimization restart {0}/{1}, f = {2}".format(i + 1, num_restarts, self.optimization_runs[-1].f_opt)))
except Exception as e:
if robust:
print(("Warning - optimization restart {0}/{1} failed".format(i + 1, num_restarts)))
else:
raise e
if len(self.optimization_runs) > initial_length:
# This works, since failed jobs don't get added to the optimization_runs.
i = np.argmin([o.f_opt for o in self.optimization_runs[initial_length:]])
self.optimizer_array = self.optimization_runs[initial_length + i].x_opt
else:
self.optimizer_array = initial_parameters
return self.optimization_runs |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:optimizer_array; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 44; 5, 106; 5, 128; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 30; 9, boolean_operator:or; 9, 10; 9, 21; 10, comparison_operator:is; 10, 11; 10, 20; 11, call; 11, 12; 11, 17; 12, attribute; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:__dict__; 16, identifier:get; 17, argument_list; 17, 18; 17, 19; 18, string:'_optimizer_copy_'; 19, None; 20, None; 21, comparison_operator:!=; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:size; 25, attribute; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:_optimizer_copy_; 29, identifier:size; 30, block; 30, 31; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:_optimizer_copy_; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:np; 39, identifier:empty; 40, argument_list; 40, 41; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:size; 44, if_statement; 44, 45; 44, 49; 45, not_operator; 45, 46; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:_optimizer_copy_transformed; 49, block; 49, 50; 49, 62; 49, 63; 49, 64; 49, 100; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 57; 52, attribute; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:_optimizer_copy_; 56, identifier:flat; 57, attribute; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:param_array; 61, identifier:flat; 62, comment; 63, comment; 64, expression_statement; 64, 65; 65, list_comprehension; 65, 66; 65, 85; 65, 96; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:np; 69, identifier:put; 70, argument_list; 70, 71; 70, 74; 70, 75; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:_optimizer_copy_; 74, identifier:ind; 75, call; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:c; 78, identifier:finv; 79, argument_list; 79, 80; 80, subscript; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:self; 83, identifier:param_array; 84, identifier:ind; 85, for_in_clause; 85, 86; 85, 89; 86, pattern_list; 86, 87; 86, 88; 87, identifier:c; 88, identifier:ind; 89, call; 89, 90; 89, 95; 90, attribute; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:self; 93, identifier:constraints; 94, identifier:items; 95, argument_list; 96, if_clause; 96, 97; 97, comparison_operator:!=; 97, 98; 97, 99; 98, identifier:c; 99, identifier:__fixed__; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:self; 104, identifier:_optimizer_copy_transformed; 105, True; 106, if_statement; 106, 107; 106, 112; 106, 113; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:self; 110, identifier:_has_fixes; 111, argument_list; 112, comment; 113, block; 113, 114; 113, 120; 114, expression_statement; 114, 115; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:self; 118, identifier:_ensure_fixes; 119, argument_list; 120, return_statement; 120, 121; 121, subscript; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:self; 124, identifier:_optimizer_copy_; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:_fixes_; 128, return_statement; 128, 129; 129, attribute; 129, 130; 129, 131; 130, identifier:self; 131, identifier:_optimizer_copy_ | def optimizer_array(self):
"""
Array for the optimizer to work on.
This array always lives in the space for the optimizer.
Thus, it is untransformed, going from Transformations.
Setting this array, will make sure the transformed parameters for this model
will be set accordingly. It has to be set with an array, retrieved from
this method, as e.g. fixing will resize the array.
The optimizer should only interfere with this array, such that transformations
are secured.
"""
if self.__dict__.get('_optimizer_copy_', None) is None or self.size != self._optimizer_copy_.size:
self._optimizer_copy_ = np.empty(self.size)
if not self._optimizer_copy_transformed:
self._optimizer_copy_.flat = self.param_array.flat
#py3 fix
#[np.put(self._optimizer_copy_, ind, c.finv(self.param_array[ind])) for c, ind in self.constraints.iteritems() if c != __fixed__]
[np.put(self._optimizer_copy_, ind, c.finv(self.param_array[ind])) for c, ind in self.constraints.items() if c != __fixed__]
self._optimizer_copy_transformed = True
if self._has_fixes():# or self._has_ties()):
self._ensure_fixes()
return self._optimizer_copy_[self._fixes_]
return self._optimizer_copy_ |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_parse_content; 3, parameters; 3, 4; 4, identifier:fh; 5, block; 5, 6; 5, 8; 5, 15; 5, 19; 5, 327; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:content; 11, call; 11, 12; 11, 13; 12, identifier:iter; 13, argument_list; 13, 14; 14, identifier:fh; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:deps; 18, dictionary; 19, for_statement; 19, 20; 19, 21; 19, 22; 19, 23; 20, identifier:line; 21, identifier:content; 22, comment; 23, block; 23, 24; 23, 30; 23, 31; 23, 37; 23, 38; 23, 46; 23, 55; 23, 64; 23, 65; 23, 71; 23, 83; 23, 84; 23, 101; 23, 109; 23, 119; 23, 136; 23, 145; 23, 146; 23, 154; 23, 197; 23, 208; 23, 209; 23, 220; 23, 221; 23, 231; 23, 232; 23, 294; 23, 295; 23, 302; 23, 308; 23, 314; 24, if_statement; 24, 25; 24, 28; 25, comparison_operator:not; 25, 26; 25, 27; 26, string:'fades'; 27, identifier:line; 28, block; 28, 29; 29, continue_statement; 30, comment; 31, if_statement; 31, 32; 31, 35; 32, comparison_operator:not; 32, 33; 32, 34; 33, string:'#'; 34, identifier:line; 35, block; 35, 36; 36, continue_statement; 37, comment; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:line; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:line; 44, identifier:strip; 45, argument_list; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:index_of_last_fades; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:line; 52, identifier:rfind; 53, argument_list; 53, 54; 54, string:'fades'; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:index_of_first_hash; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:line; 61, identifier:index; 62, argument_list; 62, 63; 63, string:'#'; 64, comment; 65, if_statement; 65, 66; 65, 69; 66, comparison_operator:>; 66, 67; 66, 68; 67, identifier:index_of_first_hash; 68, identifier:index_of_last_fades; 69, block; 69, 70; 70, continue_statement; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 76; 73, pattern_list; 73, 74; 73, 75; 74, identifier:import_part; 75, identifier:fades_part; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:line; 79, identifier:rsplit; 80, argument_list; 80, 81; 80, 82; 81, string:"#"; 82, integer:1; 83, comment; 84, if_statement; 84, 85; 84, 88; 85, comparison_operator:not; 85, 86; 85, 87; 86, string:"fades"; 87, identifier:fades_part; 88, block; 88, 89; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 94; 91, pattern_list; 91, 92; 91, 93; 92, identifier:import_part; 93, identifier:fades_part; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:import_part; 97, identifier:rsplit; 98, argument_list; 98, 99; 98, 100; 99, string:"#"; 100, integer:1; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:fades_part; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:fades_part; 107, identifier:strip; 108, argument_list; 109, if_statement; 109, 110; 109, 117; 110, not_operator; 110, 111; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:fades_part; 114, identifier:startswith; 115, argument_list; 115, 116; 116, string:"fades"; 117, block; 117, 118; 118, continue_statement; 119, if_statement; 119, 120; 119, 122; 119, 123; 119, 124; 120, not_operator; 120, 121; 121, identifier:import_part; 122, comment; 123, comment; 124, block; 124, 125; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:import_part; 128, call; 128, 129; 128, 135; 129, attribute; 129, 130; 129, 134; 130, call; 130, 131; 130, 132; 131, identifier:next; 132, argument_list; 132, 133; 133, identifier:content; 134, identifier:strip; 135, argument_list; 136, if_statement; 136, 137; 136, 143; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:import_part; 140, identifier:startswith; 141, argument_list; 141, 142; 142, string:'#'; 143, block; 143, 144; 144, continue_statement; 145, comment; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:import_tokens; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:import_part; 152, identifier:split; 153, argument_list; 154, if_statement; 154, 155; 154, 160; 154, 167; 154, 186; 155, comparison_operator:==; 155, 156; 155, 159; 156, subscript; 156, 157; 156, 158; 157, identifier:import_tokens; 158, integer:0; 159, string:'import'; 160, block; 160, 161; 161, expression_statement; 161, 162; 162, assignment; 162, 163; 162, 164; 163, identifier:module_path; 164, subscript; 164, 165; 164, 166; 165, identifier:import_tokens; 166, integer:1; 167, elif_clause; 167, 168; 167, 179; 168, boolean_operator:and; 168, 169; 168, 174; 169, comparison_operator:==; 169, 170; 169, 173; 170, subscript; 170, 171; 170, 172; 171, identifier:import_tokens; 172, integer:0; 173, string:'from'; 174, comparison_operator:==; 174, 175; 174, 178; 175, subscript; 175, 176; 175, 177; 176, identifier:import_tokens; 177, integer:2; 178, string:'import'; 179, block; 179, 180; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 183; 182, identifier:module_path; 183, subscript; 183, 184; 183, 185; 184, identifier:import_tokens; 185, integer:1; 186, else_clause; 186, 187; 187, block; 187, 188; 187, 196; 188, expression_statement; 188, 189; 189, call; 189, 190; 189, 193; 190, attribute; 190, 191; 190, 192; 191, identifier:logger; 192, identifier:debug; 193, argument_list; 193, 194; 193, 195; 194, string:"Not understood import info: %s"; 195, identifier:import_tokens; 196, continue_statement; 197, expression_statement; 197, 198; 198, assignment; 198, 199; 198, 200; 199, identifier:module; 200, subscript; 200, 201; 200, 207; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:module_path; 204, identifier:split; 205, argument_list; 205, 206; 206, string:"."; 207, integer:0; 208, comment; 209, if_statement; 209, 210; 209, 213; 210, comparison_operator:in; 210, 211; 210, 212; 211, identifier:module; 212, identifier:PKG_NAMES_DB; 213, block; 213, 214; 214, expression_statement; 214, 215; 215, assignment; 215, 216; 215, 217; 216, identifier:module; 217, subscript; 217, 218; 217, 219; 218, identifier:PKG_NAMES_DB; 219, identifier:module; 220, comment; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 224; 223, identifier:module; 224, call; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:module; 227, identifier:replace; 228, argument_list; 228, 229; 228, 230; 229, string:'_'; 230, string:'-'; 231, comment; 232, if_statement; 232, 233; 232, 253; 232, 254; 232, 255; 232, 266; 232, 283; 233, boolean_operator:or; 233, 234; 233, 240; 234, comparison_operator:==; 234, 235; 234, 239; 235, call; 235, 236; 235, 237; 236, identifier:len; 237, argument_list; 237, 238; 238, identifier:fades_part; 239, integer:5; 240, comparison_operator:in; 240, 241; 240, 252; 241, subscript; 241, 242; 241, 251; 242, call; 242, 243; 242, 250; 243, attribute; 243, 244; 243, 249; 244, subscript; 244, 245; 244, 246; 245, identifier:fades_part; 246, slice; 246, 247; 246, 248; 247, integer:5; 248, colon; 249, identifier:strip; 250, argument_list; 251, integer:0; 252, string:"<>=!"; 253, comment; 254, comment; 255, block; 255, 256; 256, expression_statement; 256, 257; 257, assignment; 257, 258; 257, 259; 258, identifier:requirement; 259, binary_operator:+; 259, 260; 259, 261; 260, identifier:module; 261, subscript; 261, 262; 261, 263; 262, identifier:fades_part; 263, slice; 263, 264; 263, 265; 264, integer:5; 265, colon; 266, elif_clause; 266, 267; 266, 272; 266, 273; 267, comparison_operator:!=; 267, 268; 267, 271; 268, subscript; 268, 269; 268, 270; 269, identifier:fades_part; 270, integer:5; 271, string:" "; 272, comment; 273, block; 273, 274; 273, 282; 274, expression_statement; 274, 275; 275, call; 275, 276; 275, 279; 276, attribute; 276, 277; 276, 278; 277, identifier:logger; 278, identifier:warning; 279, argument_list; 279, 280; 279, 281; 280, string:"Not understood fades info: %r"; 281, identifier:fades_part; 282, continue_statement; 283, else_clause; 283, 284; 283, 285; 284, comment; 285, block; 285, 286; 286, expression_statement; 286, 287; 287, assignment; 287, 288; 287, 289; 288, identifier:requirement; 289, subscript; 289, 290; 289, 291; 290, identifier:fades_part; 291, slice; 291, 292; 291, 293; 292, integer:5; 293, colon; 294, comment; 295, expression_statement; 295, 296; 296, assignment; 296, 297; 296, 298; 297, identifier:parsed_req; 298, call; 298, 299; 298, 300; 299, identifier:parse_fade_requirement; 300, argument_list; 300, 301; 301, identifier:requirement; 302, if_statement; 302, 303; 302, 306; 303, comparison_operator:is; 303, 304; 303, 305; 304, identifier:parsed_req; 305, None; 306, block; 306, 307; 307, continue_statement; 308, expression_statement; 308, 309; 309, assignment; 309, 310; 309, 313; 310, pattern_list; 310, 311; 310, 312; 311, identifier:repo; 312, identifier:dependency; 313, identifier:parsed_req; 314, expression_statement; 314, 315; 315, call; 315, 316; 315, 325; 316, attribute; 316, 317; 316, 324; 317, call; 317, 318; 317, 321; 318, attribute; 318, 319; 318, 320; 319, identifier:deps; 320, identifier:setdefault; 321, argument_list; 321, 322; 321, 323; 322, identifier:repo; 323, list:[]; 324, identifier:append; 325, argument_list; 325, 326; 326, identifier:dependency; 327, return_statement; 327, 328; 328, identifier:deps | def _parse_content(fh):
"""Parse the content of a script to find marked dependencies."""
content = iter(fh)
deps = {}
for line in content:
# quickly discard most of the lines
if 'fades' not in line:
continue
# discard other string with 'fades' that isn't a comment
if '#' not in line:
continue
# assure that it's a well commented line and no other stuff
line = line.strip()
index_of_last_fades = line.rfind('fades')
index_of_first_hash = line.index('#')
# discard when fades does not appear after #
if index_of_first_hash > index_of_last_fades:
continue
import_part, fades_part = line.rsplit("#", 1)
# discard other comments in the same line that aren't for fades
if "fades" not in fades_part:
import_part, fades_part = import_part.rsplit("#", 1)
fades_part = fades_part.strip()
if not fades_part.startswith("fades"):
continue
if not import_part:
# the fades comment was done at the beginning of the line,
# which means that the import info is in the next one
import_part = next(content).strip()
if import_part.startswith('#'):
continue
# get module
import_tokens = import_part.split()
if import_tokens[0] == 'import':
module_path = import_tokens[1]
elif import_tokens[0] == 'from' and import_tokens[2] == 'import':
module_path = import_tokens[1]
else:
logger.debug("Not understood import info: %s", import_tokens)
continue
module = module_path.split(".")[0]
# If fades know the real name of the pkg. Replace it!
if module in PKG_NAMES_DB:
module = PKG_NAMES_DB[module]
# To match the "safe" name that pkg_resources creates:
module = module.replace('_', '-')
# get the fades info after 'fades' mark, if any
if len(fades_part) == 5 or fades_part[5:].strip()[0] in "<>=!":
# just the 'fades' mark, and maybe a version specification, the requirement is what
# was imported (maybe with that version comparison)
requirement = module + fades_part[5:]
elif fades_part[5] != " ":
# starts with fades but it's part of a longer weird word
logger.warning("Not understood fades info: %r", fades_part)
continue
else:
# more complex stuff, to be parsed as a normal requirement
requirement = fades_part[5:]
# parse and convert the requirement
parsed_req = parse_fade_requirement(requirement)
if parsed_req is None:
continue
repo, dependency = parsed_req
deps.setdefault(repo, []).append(dependency)
return deps |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_parse_docstring; 3, parameters; 3, 4; 4, identifier:fh; 5, block; 5, 6; 5, 8; 5, 19; 5, 53; 5, 73; 5, 139; 5, 146; 5, 161; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:find_fades; 11, attribute; 11, 12; 11, 18; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:re; 15, identifier:compile; 16, argument_list; 16, 17; 17, string:r'\b(fades)\b:'; 18, identifier:search; 19, for_statement; 19, 20; 19, 21; 19, 22; 19, 49; 20, identifier:line; 21, identifier:fh; 22, block; 22, 23; 22, 36; 23, if_statement; 23, 24; 23, 30; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:line; 27, identifier:startswith; 28, argument_list; 28, 29; 29, string:"'"; 30, block; 30, 31; 30, 35; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:quote; 34, string:"'"; 35, break_statement; 36, if_statement; 36, 37; 36, 43; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:line; 40, identifier:startswith; 41, argument_list; 41, 42; 42, string:'"'; 43, block; 43, 44; 43, 48; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:quote; 47, string:'"'; 48, break_statement; 49, else_clause; 49, 50; 50, block; 50, 51; 51, return_statement; 51, 52; 52, dictionary; 53, if_statement; 53, 54; 53, 59; 53, 60; 53, 67; 54, comparison_operator:==; 54, 55; 54, 58; 55, subscript; 55, 56; 55, 57; 56, identifier:line; 57, integer:1; 58, identifier:quote; 59, comment; 60, block; 60, 61; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:endquote; 64, binary_operator:*; 64, 65; 64, 66; 65, identifier:quote; 66, integer:3; 67, else_clause; 67, 68; 68, block; 68, 69; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:endquote; 72, identifier:quote; 73, if_statement; 73, 74; 73, 84; 73, 99; 74, comparison_operator:in; 74, 75; 74, 76; 75, identifier:endquote; 76, subscript; 76, 77; 76, 78; 77, identifier:line; 78, slice; 78, 79; 78, 83; 79, call; 79, 80; 79, 81; 80, identifier:len; 81, argument_list; 81, 82; 82, identifier:endquote; 83, colon; 84, block; 84, 85; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:docstring_lines; 88, list:[line[:line.index(endquote)]]; 88, 89; 89, subscript; 89, 90; 89, 91; 90, identifier:line; 91, slice; 91, 92; 91, 93; 92, colon; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:line; 96, identifier:index; 97, argument_list; 97, 98; 98, identifier:endquote; 99, else_clause; 99, 100; 100, block; 100, 101; 100, 106; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:docstring_lines; 104, list:[line]; 104, 105; 105, identifier:line; 106, for_statement; 106, 107; 106, 108; 106, 109; 107, identifier:line; 108, identifier:fh; 109, block; 109, 110; 109, 132; 110, if_statement; 110, 111; 110, 114; 111, comparison_operator:in; 111, 112; 111, 113; 112, identifier:endquote; 113, identifier:line; 114, block; 114, 115; 114, 131; 115, expression_statement; 115, 116; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:docstring_lines; 119, identifier:append; 120, argument_list; 120, 121; 121, subscript; 121, 122; 121, 123; 122, identifier:line; 123, slice; 123, 124; 123, 125; 124, colon; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:line; 128, identifier:index; 129, argument_list; 129, 130; 130, identifier:endquote; 131, break_statement; 132, expression_statement; 132, 133; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:docstring_lines; 136, identifier:append; 137, argument_list; 137, 138; 138, identifier:line; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:docstring_lines; 142, call; 142, 143; 142, 144; 143, identifier:iter; 144, argument_list; 144, 145; 145, identifier:docstring_lines; 146, for_statement; 146, 147; 146, 148; 146, 149; 146, 157; 147, identifier:doc_line; 148, identifier:docstring_lines; 149, block; 149, 150; 150, if_statement; 150, 151; 150, 155; 151, call; 151, 152; 151, 153; 152, identifier:find_fades; 153, argument_list; 153, 154; 154, identifier:doc_line; 155, block; 155, 156; 156, break_statement; 157, else_clause; 157, 158; 158, block; 158, 159; 159, return_statement; 159, 160; 160, dictionary; 161, return_statement; 161, 162; 162, call; 162, 163; 162, 164; 163, identifier:_parse_requirement; 164, argument_list; 164, 165; 165, call; 165, 166; 165, 167; 166, identifier:list; 167, argument_list; 167, 168; 168, identifier:docstring_lines | def _parse_docstring(fh):
"""Parse the docstrings of a script to find marked dependencies."""
find_fades = re.compile(r'\b(fades)\b:').search
for line in fh:
if line.startswith("'"):
quote = "'"
break
if line.startswith('"'):
quote = '"'
break
else:
return {}
if line[1] == quote:
# comment start with triple quotes
endquote = quote * 3
else:
endquote = quote
if endquote in line[len(endquote):]:
docstring_lines = [line[:line.index(endquote)]]
else:
docstring_lines = [line]
for line in fh:
if endquote in line:
docstring_lines.append(line[:line.index(endquote)])
break
docstring_lines.append(line)
docstring_lines = iter(docstring_lines)
for doc_line in docstring_lines:
if find_fades(doc_line):
break
else:
return {}
return _parse_requirement(list(docstring_lines)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_venv_match; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:installed; 6, identifier:requirements; 7, block; 7, 8; 7, 10; 7, 21; 7, 25; 7, 140; 7, 141; 8, expression_statement; 8, 9; 9, comment; 10, if_statement; 10, 11; 10, 13; 10, 14; 10, 15; 11, not_operator; 11, 12; 12, identifier:requirements; 13, comment; 14, comment; 15, block; 15, 16; 16, return_statement; 16, 17; 17, conditional_expression:if; 17, 18; 17, 19; 17, 20; 18, None; 19, identifier:installed; 20, list:[]; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:satisfying_deps; 24, list:[]; 25, for_statement; 25, 26; 25, 29; 25, 34; 26, pattern_list; 26, 27; 26, 28; 27, identifier:repo; 28, identifier:req_deps; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:requirements; 32, identifier:items; 33, argument_list; 34, block; 34, 35; 34, 41; 34, 49; 34, 97; 34, 123; 34, 124; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:useful_inst; 38, call; 38, 39; 38, 40; 39, identifier:set; 40, argument_list; 41, if_statement; 41, 42; 41, 45; 41, 46; 42, comparison_operator:not; 42, 43; 42, 44; 43, identifier:repo; 44, identifier:installed; 45, comment; 46, block; 46, 47; 47, return_statement; 47, 48; 48, None; 49, if_statement; 49, 50; 49, 53; 49, 71; 50, comparison_operator:==; 50, 51; 50, 52; 51, identifier:repo; 52, identifier:REPO_VCS; 53, block; 53, 54; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:inst_deps; 57, set_comprehension; 57, 58; 57, 62; 58, call; 58, 59; 58, 60; 59, identifier:VCSDependency; 60, argument_list; 60, 61; 61, identifier:url; 62, for_in_clause; 62, 63; 62, 64; 63, identifier:url; 64, call; 64, 65; 64, 70; 65, attribute; 65, 66; 65, 69; 66, subscript; 66, 67; 66, 68; 67, identifier:installed; 68, identifier:repo; 69, identifier:keys; 70, argument_list; 71, else_clause; 71, 72; 72, block; 72, 73; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:inst_deps; 76, set_comprehension; 76, 77; 76, 86; 77, call; 77, 78; 77, 79; 78, identifier:Distribution; 79, argument_list; 79, 80; 79, 83; 80, keyword_argument; 80, 81; 80, 82; 81, identifier:project_name; 82, identifier:dep; 83, keyword_argument; 83, 84; 83, 85; 84, identifier:version; 85, identifier:ver; 86, for_in_clause; 86, 87; 86, 90; 87, tuple_pattern; 87, 88; 87, 89; 88, identifier:dep; 89, identifier:ver; 90, call; 90, 91; 90, 96; 91, attribute; 91, 92; 91, 95; 92, subscript; 92, 93; 92, 94; 93, identifier:installed; 94, identifier:repo; 95, identifier:items; 96, argument_list; 97, for_statement; 97, 98; 97, 99; 97, 100; 98, identifier:req; 99, identifier:req_deps; 100, block; 100, 101; 101, for_statement; 101, 102; 101, 103; 101, 104; 101, 118; 102, identifier:inst; 103, identifier:inst_deps; 104, block; 104, 105; 105, if_statement; 105, 106; 105, 109; 106, comparison_operator:in; 106, 107; 106, 108; 107, identifier:inst; 108, identifier:req; 109, block; 109, 110; 109, 117; 110, expression_statement; 110, 111; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:useful_inst; 114, identifier:add; 115, argument_list; 115, 116; 116, identifier:inst; 117, break_statement; 118, else_clause; 118, 119; 118, 120; 119, comment; 120, block; 120, 121; 121, return_statement; 121, 122; 122, None; 123, comment; 124, if_statement; 124, 125; 124, 128; 124, 136; 125, comparison_operator:==; 125, 126; 125, 127; 126, identifier:useful_inst; 127, identifier:inst_deps; 128, block; 128, 129; 129, expression_statement; 129, 130; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:satisfying_deps; 133, identifier:extend; 134, argument_list; 134, 135; 135, identifier:inst_deps; 136, else_clause; 136, 137; 137, block; 137, 138; 138, return_statement; 138, 139; 139, None; 140, comment; 141, return_statement; 141, 142; 142, identifier:satisfying_deps | def _venv_match(self, installed, requirements):
"""Return True if what is installed satisfies the requirements.
This method has multiple exit-points, but only for False (because
if *anything* is not satisified, the venv is no good). Only after
all was checked, and it didn't exit, the venv is ok so return True.
"""
if not requirements:
# special case for no requirements, where we can't actually
# check anything: the venv is useful if nothing installed too
return None if installed else []
satisfying_deps = []
for repo, req_deps in requirements.items():
useful_inst = set()
if repo not in installed:
# the venv doesn't even have the repo
return None
if repo == REPO_VCS:
inst_deps = {VCSDependency(url) for url in installed[repo].keys()}
else:
inst_deps = {Distribution(project_name=dep, version=ver)
for (dep, ver) in installed[repo].items()}
for req in req_deps:
for inst in inst_deps:
if inst in req:
useful_inst.add(inst)
break
else:
# nothing installed satisfied that requirement
return None
# assure *all* that is installed is useful for the requirements
if useful_inst == inst_deps:
satisfying_deps.extend(inst_deps)
else:
return None
# it did it through!
return satisfying_deps |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 32; 2, function_name:encrypt; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 4, identifier:content; 5, default_parameter; 5, 6; 5, 7; 6, identifier:salt; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:key; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:private_key; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:dh; 16, None; 17, default_parameter; 17, 18; 17, 19; 18, identifier:auth_secret; 19, None; 20, default_parameter; 20, 21; 20, 22; 21, identifier:keyid; 22, None; 23, default_parameter; 23, 24; 23, 25; 24, identifier:keylabel; 25, string:"P-256"; 26, default_parameter; 26, 27; 26, 28; 27, identifier:rs; 28, integer:4096; 29, default_parameter; 29, 30; 29, 31; 30, identifier:version; 31, string:"aes128gcm"; 32, block; 32, 33; 32, 35; 32, 131; 32, 199; 32, 209; 32, 223; 32, 256; 32, 264; 32, 291; 32, 301; 32, 307; 32, 311; 32, 315; 32, 316; 32, 317; 32, 356; 32, 412; 33, expression_statement; 33, 34; 34, comment; 35, function_definition; 35, 36; 35, 37; 35, 43; 36, function_name:encrypt_record; 37, parameters; 37, 38; 37, 39; 37, 40; 37, 41; 37, 42; 38, identifier:key; 39, identifier:nonce; 40, identifier:counter; 41, identifier:buf; 42, identifier:last; 43, block; 43, 44; 43, 75; 43, 115; 43, 123; 43, 129; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:encryptor; 47, call; 47, 48; 47, 74; 48, attribute; 48, 49; 48, 73; 49, call; 49, 50; 49, 51; 50, identifier:Cipher; 51, argument_list; 51, 52; 51, 58; 51, 68; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:algorithms; 55, identifier:AES; 56, argument_list; 56, 57; 57, identifier:key; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:modes; 61, identifier:GCM; 62, argument_list; 62, 63; 63, call; 63, 64; 63, 65; 64, identifier:iv; 65, argument_list; 65, 66; 65, 67; 66, identifier:nonce; 67, identifier:counter; 68, keyword_argument; 68, 69; 68, 70; 69, identifier:backend; 70, call; 70, 71; 70, 72; 71, identifier:default_backend; 72, argument_list; 73, identifier:encryptor; 74, argument_list; 75, if_statement; 75, 76; 75, 79; 75, 95; 76, comparison_operator:==; 76, 77; 76, 78; 77, identifier:version; 78, string:'aes128gcm'; 79, block; 79, 80; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:data; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:encryptor; 86, identifier:update; 87, argument_list; 87, 88; 88, binary_operator:+; 88, 89; 88, 90; 89, identifier:buf; 90, parenthesized_expression; 90, 91; 91, conditional_expression:if; 91, 92; 91, 93; 91, 94; 92, string:b'\x02'; 93, identifier:last; 94, string:b'\x01'; 95, else_clause; 95, 96; 96, block; 96, 97; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:data; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:encryptor; 103, identifier:update; 104, argument_list; 104, 105; 105, binary_operator:+; 105, 106; 105, 114; 106, parenthesized_expression; 106, 107; 107, binary_operator:*; 107, 108; 107, 109; 108, string:b"\x00"; 109, subscript; 109, 110; 109, 113; 110, subscript; 110, 111; 110, 112; 111, identifier:versions; 112, identifier:version; 113, string:'pad'; 114, identifier:buf; 115, expression_statement; 115, 116; 116, augmented_assignment:+=; 116, 117; 116, 118; 117, identifier:data; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:encryptor; 121, identifier:finalize; 122, argument_list; 123, expression_statement; 123, 124; 124, augmented_assignment:+=; 124, 125; 124, 126; 125, identifier:data; 126, attribute; 126, 127; 126, 128; 127, identifier:encryptor; 128, identifier:tag; 129, return_statement; 129, 130; 130, identifier:data; 131, function_definition; 131, 132; 131, 133; 131, 138; 132, function_name:compose_aes128gcm; 133, parameters; 133, 134; 133, 135; 133, 136; 133, 137; 134, identifier:salt; 135, identifier:content; 136, identifier:rs; 137, identifier:keyid; 138, block; 138, 139; 138, 141; 138, 154; 138, 158; 138, 168; 138, 178; 138, 191; 138, 195; 139, expression_statement; 139, 140; 140, comment; 141, if_statement; 141, 142; 141, 148; 142, comparison_operator:>; 142, 143; 142, 147; 143, call; 143, 144; 143, 145; 144, identifier:len; 145, argument_list; 145, 146; 146, identifier:keyid; 147, integer:255; 148, block; 148, 149; 149, raise_statement; 149, 150; 150, call; 150, 151; 150, 152; 151, identifier:ECEException; 152, argument_list; 152, 153; 153, string:"keyid is too long"; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:header; 157, identifier:salt; 158, if_statement; 158, 159; 158, 162; 159, comparison_operator:>; 159, 160; 159, 161; 160, identifier:rs; 161, identifier:MAX_RECORD_SIZE; 162, block; 162, 163; 163, raise_statement; 163, 164; 164, call; 164, 165; 164, 166; 165, identifier:ECEException; 166, argument_list; 166, 167; 167, string:"Too much content"; 168, expression_statement; 168, 169; 169, augmented_assignment:+=; 169, 170; 169, 171; 170, identifier:header; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:struct; 174, identifier:pack; 175, argument_list; 175, 176; 175, 177; 176, string:"!L"; 177, identifier:rs; 178, expression_statement; 178, 179; 179, augmented_assignment:+=; 179, 180; 179, 181; 180, identifier:header; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:struct; 184, identifier:pack; 185, argument_list; 185, 186; 185, 187; 186, string:"!B"; 187, call; 187, 188; 187, 189; 188, identifier:len; 189, argument_list; 189, 190; 190, identifier:keyid; 191, expression_statement; 191, 192; 192, augmented_assignment:+=; 192, 193; 192, 194; 193, identifier:header; 194, identifier:keyid; 195, return_statement; 195, 196; 196, binary_operator:+; 196, 197; 196, 198; 197, identifier:header; 198, identifier:content; 199, if_statement; 199, 200; 199, 203; 200, comparison_operator:not; 200, 201; 200, 202; 201, identifier:version; 202, identifier:versions; 203, block; 203, 204; 204, raise_statement; 204, 205; 205, call; 205, 206; 205, 207; 206, identifier:ECEException; 207, argument_list; 207, 208; 208, string:u"Invalid version"; 209, if_statement; 209, 210; 209, 213; 210, comparison_operator:is; 210, 211; 210, 212; 211, identifier:salt; 212, None; 213, block; 213, 214; 214, expression_statement; 214, 215; 215, assignment; 215, 216; 215, 217; 216, identifier:salt; 217, call; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:os; 220, identifier:urandom; 221, argument_list; 221, 222; 222, integer:16; 223, expression_statement; 223, 224; 224, assignment; 224, 225; 224, 228; 225, tuple_pattern; 225, 226; 225, 227; 226, identifier:key_; 227, identifier:nonce_; 228, call; 228, 229; 228, 230; 229, identifier:derive_key; 230, argument_list; 230, 231; 230, 232; 230, 235; 230, 238; 230, 241; 230, 244; 230, 247; 230, 250; 230, 253; 231, string:"encrypt"; 232, keyword_argument; 232, 233; 232, 234; 233, identifier:version; 234, identifier:version; 235, keyword_argument; 235, 236; 235, 237; 236, identifier:salt; 237, identifier:salt; 238, keyword_argument; 238, 239; 238, 240; 239, identifier:key; 240, identifier:key; 241, keyword_argument; 241, 242; 241, 243; 242, identifier:private_key; 243, identifier:private_key; 244, keyword_argument; 244, 245; 244, 246; 245, identifier:dh; 246, identifier:dh; 247, keyword_argument; 247, 248; 247, 249; 248, identifier:auth_secret; 249, identifier:auth_secret; 250, keyword_argument; 250, 251; 250, 252; 251, identifier:keyid; 252, identifier:keyid; 253, keyword_argument; 253, 254; 253, 255; 254, identifier:keylabel; 255, identifier:keylabel; 256, expression_statement; 256, 257; 257, assignment; 257, 258; 257, 259; 258, identifier:overhead; 259, subscript; 259, 260; 259, 263; 260, subscript; 260, 261; 260, 262; 261, identifier:versions; 262, identifier:version; 263, string:'pad'; 264, if_statement; 264, 265; 264, 268; 264, 280; 265, comparison_operator:==; 265, 266; 265, 267; 266, identifier:version; 267, string:'aes128gcm'; 268, block; 268, 269; 268, 273; 269, expression_statement; 269, 270; 270, augmented_assignment:+=; 270, 271; 270, 272; 271, identifier:overhead; 272, integer:16; 273, expression_statement; 273, 274; 274, assignment; 274, 275; 274, 276; 275, identifier:end; 276, call; 276, 277; 276, 278; 277, identifier:len; 278, argument_list; 278, 279; 279, identifier:content; 280, else_clause; 280, 281; 281, block; 281, 282; 282, expression_statement; 282, 283; 283, assignment; 283, 284; 283, 285; 284, identifier:end; 285, binary_operator:+; 285, 286; 285, 290; 286, call; 286, 287; 286, 288; 287, identifier:len; 288, argument_list; 288, 289; 289, identifier:content; 290, integer:1; 291, if_statement; 291, 292; 291, 295; 292, comparison_operator:<=; 292, 293; 292, 294; 293, identifier:rs; 294, identifier:overhead; 295, block; 295, 296; 296, raise_statement; 296, 297; 297, call; 297, 298; 297, 299; 298, identifier:ECEException; 299, argument_list; 299, 300; 300, string:u"Record size too small"; 301, expression_statement; 301, 302; 302, assignment; 302, 303; 302, 304; 303, identifier:chunk_size; 304, binary_operator:-; 304, 305; 304, 306; 305, identifier:rs; 306, identifier:overhead; 307, expression_statement; 307, 308; 308, assignment; 308, 309; 308, 310; 309, identifier:result; 310, string:b""; 311, expression_statement; 311, 312; 312, assignment; 312, 313; 312, 314; 313, identifier:counter; 314, integer:0; 315, comment; 316, comment; 317, for_statement; 317, 318; 317, 319; 317, 328; 318, identifier:i; 319, call; 319, 320; 319, 321; 320, identifier:list; 321, argument_list; 321, 322; 322, call; 322, 323; 322, 324; 323, identifier:range; 324, argument_list; 324, 325; 324, 326; 324, 327; 325, integer:0; 326, identifier:end; 327, identifier:chunk_size; 328, block; 328, 329; 328, 352; 329, expression_statement; 329, 330; 330, augmented_assignment:+=; 330, 331; 330, 332; 331, identifier:result; 332, call; 332, 333; 332, 334; 333, identifier:encrypt_record; 334, argument_list; 334, 335; 334, 336; 334, 337; 334, 338; 334, 346; 335, identifier:key_; 336, identifier:nonce_; 337, identifier:counter; 338, subscript; 338, 339; 338, 340; 339, identifier:content; 340, slice; 340, 341; 340, 342; 340, 343; 341, identifier:i; 342, colon; 343, binary_operator:+; 343, 344; 343, 345; 344, identifier:i; 345, identifier:chunk_size; 346, comparison_operator:>=; 346, 347; 346, 351; 347, parenthesized_expression; 347, 348; 348, binary_operator:+; 348, 349; 348, 350; 349, identifier:i; 350, identifier:chunk_size; 351, identifier:end; 352, expression_statement; 352, 353; 353, augmented_assignment:+=; 353, 354; 353, 355; 354, identifier:counter; 355, integer:1; 356, if_statement; 356, 357; 356, 360; 357, comparison_operator:==; 357, 358; 357, 359; 358, identifier:version; 359, string:"aes128gcm"; 360, block; 360, 361; 360, 402; 361, if_statement; 361, 362; 361, 369; 361, 388; 362, boolean_operator:and; 362, 363; 362, 366; 363, comparison_operator:is; 363, 364; 363, 365; 364, identifier:keyid; 365, None; 366, comparison_operator:is; 366, 367; 366, 368; 367, identifier:private_key; 368, None; 369, block; 369, 370; 370, expression_statement; 370, 371; 371, assignment; 371, 372; 371, 373; 372, identifier:kid; 373, call; 373, 374; 373, 381; 374, attribute; 374, 375; 374, 380; 375, call; 375, 376; 375, 379; 376, attribute; 376, 377; 376, 378; 377, identifier:private_key; 378, identifier:public_key; 379, argument_list; 380, identifier:public_bytes; 381, argument_list; 381, 382; 381, 385; 382, attribute; 382, 383; 382, 384; 383, identifier:Encoding; 384, identifier:X962; 385, attribute; 385, 386; 385, 387; 386, identifier:PublicFormat; 387, identifier:UncompressedPoint; 388, else_clause; 388, 389; 389, block; 389, 390; 390, expression_statement; 390, 391; 391, assignment; 391, 392; 391, 393; 392, identifier:kid; 393, call; 393, 394; 393, 400; 394, attribute; 394, 395; 394, 399; 395, parenthesized_expression; 395, 396; 396, boolean_operator:or; 396, 397; 396, 398; 397, identifier:keyid; 398, string:''; 399, identifier:encode; 400, argument_list; 400, 401; 401, string:'utf-8'; 402, return_statement; 402, 403; 403, call; 403, 404; 403, 405; 404, identifier:compose_aes128gcm; 405, argument_list; 405, 406; 405, 407; 405, 408; 405, 409; 406, identifier:salt; 407, identifier:result; 408, identifier:rs; 409, keyword_argument; 409, 410; 409, 411; 410, identifier:keyid; 411, identifier:kid; 412, return_statement; 412, 413; 413, identifier:result | def encrypt(content, salt=None, key=None,
private_key=None, dh=None, auth_secret=None,
keyid=None, keylabel="P-256",
rs=4096, version="aes128gcm"):
"""
Encrypt a data block
:param content: block of data to encrypt
:type content: str
:param salt: Encryption salt
:type salt: str
:param key: Encryption key data
:type key: str
:param private_key: DH private key
:type key: object
:param keyid: Internal key identifier for private key info
:type keyid: str
:param dh: Remote Diffie Hellman sequence
:type dh: str
:param rs: Record size
:type rs: int
:param auth_secret: Authorization secret
:type auth_secret: str
:param version: ECE Method version
:type version: enumerate('aes128gcm', 'aesgcm', 'aesgcm128')
:return: Encrypted message content
:rtype str
"""
def encrypt_record(key, nonce, counter, buf, last):
encryptor = Cipher(
algorithms.AES(key),
modes.GCM(iv(nonce, counter)),
backend=default_backend()
).encryptor()
if version == 'aes128gcm':
data = encryptor.update(buf + (b'\x02' if last else b'\x01'))
else:
data = encryptor.update((b"\x00" * versions[version]['pad']) + buf)
data += encryptor.finalize()
data += encryptor.tag
return data
def compose_aes128gcm(salt, content, rs, keyid):
"""Compose the header and content of an aes128gcm encrypted
message body
:param salt: The sender's salt value
:type salt: str
:param content: The encrypted body of the message
:type content: str
:param rs: Override for the content length
:type rs: int
:param keyid: The keyid to use for this message
:type keyid: str
"""
if len(keyid) > 255:
raise ECEException("keyid is too long")
header = salt
if rs > MAX_RECORD_SIZE:
raise ECEException("Too much content")
header += struct.pack("!L", rs)
header += struct.pack("!B", len(keyid))
header += keyid
return header + content
if version not in versions:
raise ECEException(u"Invalid version")
if salt is None:
salt = os.urandom(16)
(key_, nonce_) = derive_key("encrypt", version=version,
salt=salt, key=key,
private_key=private_key, dh=dh,
auth_secret=auth_secret,
keyid=keyid, keylabel=keylabel)
overhead = versions[version]['pad']
if version == 'aes128gcm':
overhead += 16
end = len(content)
else:
end = len(content) + 1
if rs <= overhead:
raise ECEException(u"Record size too small")
chunk_size = rs - overhead
result = b""
counter = 0
# the extra one on the loop ensures that we produce a padding only
# record if the data length is an exact multiple of the chunk size
for i in list(range(0, end, chunk_size)):
result += encrypt_record(key_, nonce_, counter,
content[i:i + chunk_size],
(i + chunk_size) >= end)
counter += 1
if version == "aes128gcm":
if keyid is None and private_key is not None:
kid = private_key.public_key().public_bytes(
Encoding.X962,
PublicFormat.UncompressedPoint)
else:
kid = (keyid or '').encode('utf-8')
return compose_aes128gcm(salt, result, rs, keyid=kid)
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_format_ase2clusgeo; 3, parameters; 3, 4; 3, 5; 4, identifier:obj; 5, default_parameter; 5, 6; 5, 7; 6, identifier:all_atomtypes; 7, None; 8, block; 8, 9; 8, 11; 8, 12; 8, 19; 8, 44; 8, 56; 8, 60; 8, 64; 8, 111; 8, 115; 8, 122; 8, 124; 8, 137; 9, expression_statement; 9, 10; 10, comment; 11, comment; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:totalAN; 15, call; 15, 16; 15, 17; 16, identifier:len; 17, argument_list; 17, 18; 18, identifier:obj; 19, if_statement; 19, 20; 19, 23; 19, 31; 20, comparison_operator:is; 20, 21; 20, 22; 21, identifier:all_atomtypes; 22, None; 23, block; 23, 24; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:atomtype_set; 27, call; 27, 28; 27, 29; 28, identifier:set; 29, argument_list; 29, 30; 30, identifier:all_atomtypes; 31, else_clause; 31, 32; 32, block; 32, 33; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:atomtype_set; 36, call; 36, 37; 36, 38; 37, identifier:set; 38, argument_list; 38, 39; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:obj; 42, identifier:get_atomic_numbers; 43, argument_list; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:atomtype_lst; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:np; 50, identifier:sort; 51, argument_list; 51, 52; 52, call; 52, 53; 52, 54; 53, identifier:list; 54, argument_list; 54, 55; 55, identifier:atomtype_set; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:n_atoms_per_type_lst; 59, list:[]; 60, expression_statement; 60, 61; 61, assignment; 61, 62; 61, 63; 62, identifier:pos_lst; 63, list:[]; 64, for_statement; 64, 65; 64, 66; 64, 67; 65, identifier:atomtype; 66, identifier:atomtype_lst; 67, block; 67, 68; 67, 78; 67, 88; 67, 96; 67, 97; 67, 104; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:condition; 71, comparison_operator:==; 71, 72; 71, 77; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:obj; 75, identifier:get_atomic_numbers; 76, argument_list; 77, identifier:atomtype; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:pos_onetype; 81, subscript; 81, 82; 81, 87; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:obj; 85, identifier:get_positions; 86, argument_list; 87, identifier:condition; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:n_onetype; 91, subscript; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:pos_onetype; 94, identifier:shape; 95, integer:0; 96, comment; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:pos_lst; 101, identifier:append; 102, argument_list; 102, 103; 103, identifier:pos_onetype; 104, expression_statement; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:n_atoms_per_type_lst; 108, identifier:append; 109, argument_list; 109, 110; 110, identifier:n_onetype; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:typeNs; 114, identifier:n_atoms_per_type_lst; 115, expression_statement; 115, 116; 116, assignment; 116, 117; 116, 118; 117, identifier:Ntypes; 118, call; 118, 119; 118, 120; 119, identifier:len; 120, argument_list; 120, 121; 121, identifier:n_atoms_per_type_lst; 122, expression_statement; 122, 123; 123, identifier:atomtype_lst; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:Apos; 127, call; 127, 128; 127, 136; 128, attribute; 128, 129; 128, 135; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:np; 132, identifier:concatenate; 133, argument_list; 133, 134; 134, identifier:pos_lst; 135, identifier:ravel; 136, argument_list; 137, return_statement; 137, 138; 138, expression_list; 138, 139; 138, 140; 138, 141; 138, 142; 138, 143; 139, identifier:Apos; 140, identifier:typeNs; 141, identifier:Ntypes; 142, identifier:atomtype_lst; 143, identifier:totalAN | def _format_ase2clusgeo(obj, all_atomtypes=None):
""" Takes an ase Atoms object and returns numpy arrays and integers
which are read by the internal clusgeo. Apos is currently a flattened
out numpy array
Args:
obj():
all_atomtypes():
sort():
"""
#atoms metadata
totalAN = len(obj)
if all_atomtypes is not None:
atomtype_set = set(all_atomtypes)
else:
atomtype_set = set(obj.get_atomic_numbers())
atomtype_lst = np.sort(list(atomtype_set))
n_atoms_per_type_lst = []
pos_lst = []
for atomtype in atomtype_lst:
condition = obj.get_atomic_numbers() == atomtype
pos_onetype = obj.get_positions()[condition]
n_onetype = pos_onetype.shape[0]
# store data in lists
pos_lst.append(pos_onetype)
n_atoms_per_type_lst.append(n_onetype)
typeNs = n_atoms_per_type_lst
Ntypes = len(n_atoms_per_type_lst)
atomtype_lst
Apos = np.concatenate(pos_lst).ravel()
return Apos, typeNs, Ntypes, atomtype_lst, totalAN |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 22; 2, function_name:zmax; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 13; 3, 16; 3, 19; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:return_times; 7, False; 8, default_parameter; 8, 9; 8, 10; 9, identifier:func; 10, attribute; 10, 11; 10, 12; 11, identifier:np; 12, identifier:mean; 13, default_parameter; 13, 14; 13, 15; 14, identifier:interp_kwargs; 15, None; 16, default_parameter; 16, 17; 16, 18; 17, identifier:minimize_kwargs; 18, None; 19, default_parameter; 19, 20; 19, 21; 20, identifier:approximate; 21, False; 22, block; 22, 23; 22, 25; 22, 41; 22, 63; 22, 64; 22, 88; 22, 92; 22, 96; 22, 150; 23, expression_statement; 23, 24; 24, comment; 25, if_statement; 25, 26; 25, 31; 26, boolean_operator:and; 26, 27; 26, 28; 27, identifier:return_times; 28, comparison_operator:is; 28, 29; 28, 30; 29, identifier:func; 30, None; 31, block; 31, 32; 32, raise_statement; 32, 33; 33, call; 33, 34; 33, 35; 34, identifier:ValueError; 35, argument_list; 35, 36; 36, concatenated_string; 36, 37; 36, 38; 36, 39; 36, 40; 37, string:"Cannot return times if reducing "; 38, string:"using an input function. Pass `func=None` if "; 39, string:"you want to return all individual values "; 40, string:"and times."; 41, if_statement; 41, 42; 41, 45; 41, 57; 42, comparison_operator:is; 42, 43; 42, 44; 43, identifier:func; 44, None; 45, block; 45, 46; 45, 50; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:reduce; 49, False; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:func; 53, lambda; 53, 54; 53, 56; 54, lambda_parameters; 54, 55; 55, identifier:x; 56, identifier:x; 57, else_clause; 57, 58; 58, block; 58, 59; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:reduce; 62, True; 63, comment; 64, if_statement; 64, 65; 64, 77; 65, comparison_operator:<; 65, 66; 65, 72; 66, subscript; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:t; 70, unary_operator:-; 70, 71; 71, integer:1; 72, subscript; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:self; 75, identifier:t; 76, integer:0; 77, block; 77, 78; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:self; 81, subscript; 81, 82; 81, 83; 82, identifier:self; 83, slice; 83, 84; 83, 85; 83, 86; 84, colon; 85, colon; 86, unary_operator:-; 86, 87; 87, integer:1; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:vals; 91, list:[]; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:times; 95, list:[]; 96, for_statement; 96, 97; 96, 98; 96, 103; 97, identifier:orbit; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:orbit_gen; 102, argument_list; 103, block; 103, 104; 103, 133; 103, 143; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 109; 106, pattern_list; 106, 107; 106, 108; 107, identifier:v; 108, identifier:t; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:orbit; 112, identifier:_max_helper; 113, argument_list; 113, 114; 113, 124; 113, 127; 113, 130; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:np; 117, identifier:abs; 118, argument_list; 118, 119; 119, attribute; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:orbit; 122, identifier:cylindrical; 123, identifier:z; 124, keyword_argument; 124, 125; 124, 126; 125, identifier:interp_kwargs; 126, identifier:interp_kwargs; 127, keyword_argument; 127, 128; 127, 129; 128, identifier:minimize_kwargs; 129, identifier:minimize_kwargs; 130, keyword_argument; 130, 131; 130, 132; 131, identifier:approximate; 132, identifier:approximate; 133, expression_statement; 133, 134; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:vals; 137, identifier:append; 138, argument_list; 138, 139; 139, call; 139, 140; 139, 141; 140, identifier:func; 141, argument_list; 141, 142; 142, identifier:v; 143, expression_statement; 143, 144; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:times; 147, identifier:append; 148, argument_list; 148, 149; 149, identifier:t; 150, return_statement; 150, 151; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:self; 154, identifier:_max_return_helper; 155, argument_list; 155, 156; 155, 157; 155, 158; 155, 159; 156, identifier:vals; 157, identifier:times; 158, identifier:return_times; 159, identifier:reduce | def zmax(self, return_times=False, func=np.mean,
interp_kwargs=None, minimize_kwargs=None,
approximate=False):
"""
Estimate the maximum ``z`` height of the orbit by identifying local
maxima in the absolute value of the ``z`` position and interpolating
between timesteps near the maxima.
By default, this returns the mean of all local maxima. To get, e.g., the
largest ``z`` excursion, pass in ``func=np.max``. To get all ``z``
maxima, pass in ``func=None``.
Parameters
----------
func : func (optional)
A function to evaluate on all of the identified z maximum times.
return_times : bool (optional)
Also return the times of maximum.
interp_kwargs : dict (optional)
Keyword arguments to be passed to
:class:`scipy.interpolate.InterpolatedUnivariateSpline`.
minimize_kwargs : dict (optional)
Keyword arguments to be passed to :class:`scipy.optimize.minimize`.
approximate : bool (optional)
Compute approximate values by skipping interpolation.
Returns
-------
zs : float, :class:`~numpy.ndarray`
Either a single number or an array of maximum z heights.
times : :class:`~numpy.ndarray` (optional, see ``return_times``)
If ``return_times=True``, also returns an array of the apocenter
times.
"""
if return_times and func is not None:
raise ValueError("Cannot return times if reducing "
"using an input function. Pass `func=None` if "
"you want to return all individual values "
"and times.")
if func is None:
reduce = False
func = lambda x: x
else:
reduce = True
# time must increase
if self.t[-1] < self.t[0]:
self = self[::-1]
vals = []
times = []
for orbit in self.orbit_gen():
v, t = orbit._max_helper(np.abs(orbit.cylindrical.z),
interp_kwargs=interp_kwargs,
minimize_kwargs=minimize_kwargs,
approximate=approximate)
vals.append(func(v))
times.append(t)
return self._max_return_helper(vals, times, return_times, reduce) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:align_circulation_with_z; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:circulation; 7, None; 8, block; 8, 9; 8, 11; 8, 24; 8, 34; 8, 40; 8, 46; 8, 82; 8, 107; 8, 139; 8, 147; 8, 155; 8, 297; 9, expression_statement; 9, 10; 10, comment; 11, if_statement; 11, 12; 11, 15; 12, comparison_operator:is; 12, 13; 12, 14; 13, identifier:circulation; 14, None; 15, block; 15, 16; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:circulation; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:circulation; 23, argument_list; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:circulation; 27, call; 27, 28; 27, 29; 28, identifier:atleast_2d; 29, argument_list; 29, 30; 29, 31; 30, identifier:circulation; 31, keyword_argument; 31, 32; 31, 33; 32, identifier:insert_axis; 33, integer:1; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:cart; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:cartesian; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:pos; 43, attribute; 43, 44; 43, 45; 44, identifier:cart; 45, identifier:xyz; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:vel; 49, binary_operator:*; 49, 50; 49, 77; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:np; 53, identifier:vstack; 54, argument_list; 54, 55; 55, tuple; 55, 56; 55, 63; 55, 70; 56, subscript; 56, 57; 56, 62; 57, attribute; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:cart; 60, identifier:v_x; 61, identifier:value; 62, None; 63, subscript; 63, 64; 63, 69; 64, attribute; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:cart; 67, identifier:v_y; 68, identifier:value; 69, None; 70, subscript; 70, 71; 70, 76; 71, attribute; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:cart; 74, identifier:v_z; 75, identifier:value; 76, None; 77, attribute; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:cart; 80, identifier:v_x; 81, identifier:unit; 82, if_statement; 82, 83; 82, 88; 83, comparison_operator:<; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:pos; 86, identifier:ndim; 87, integer:3; 88, block; 88, 89; 88, 98; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 92; 91, identifier:pos; 92, subscript; 92, 93; 92, 94; 92, 95; 93, identifier:pos; 94, ellipsis:...; 95, attribute; 95, 96; 95, 97; 96, identifier:np; 97, identifier:newaxis; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:vel; 101, subscript; 101, 102; 101, 103; 101, 104; 102, identifier:vel; 103, ellipsis:...; 104, attribute; 104, 105; 104, 106; 105, identifier:np; 106, identifier:newaxis; 107, if_statement; 107, 108; 107, 130; 108, parenthesized_expression; 108, 109; 109, boolean_operator:or; 109, 110; 109, 119; 110, comparison_operator:!=; 110, 111; 110, 116; 111, subscript; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:circulation; 114, identifier:shape; 115, integer:0; 116, attribute; 116, 117; 116, 118; 117, identifier:self; 118, identifier:ndim; 119, comparison_operator:!=; 119, 120; 119, 125; 120, subscript; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:circulation; 123, identifier:shape; 124, integer:1; 125, subscript; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:pos; 128, identifier:shape; 129, integer:2; 130, block; 130, 131; 131, raise_statement; 131, 132; 132, call; 132, 133; 132, 134; 133, identifier:ValueError; 134, argument_list; 134, 135; 135, concatenated_string; 135, 136; 135, 137; 135, 138; 136, string:"Shape of 'circulation' array should match the "; 137, string:"shape of the position/velocity (minus the time "; 138, string:"axis)."; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:new_pos; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:pos; 145, identifier:copy; 146, argument_list; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:new_vel; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:vel; 153, identifier:copy; 154, argument_list; 155, for_statement; 155, 156; 155, 157; 155, 165; 156, identifier:n; 157, call; 157, 158; 157, 159; 158, identifier:range; 159, argument_list; 159, 160; 160, subscript; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:pos; 163, identifier:shape; 164, integer:2; 165, block; 165, 166; 165, 189; 165, 210; 165, 241; 165, 255; 165, 269; 165, 283; 166, if_statement; 166, 167; 166, 186; 166, 187; 167, boolean_operator:or; 167, 168; 167, 174; 168, comparison_operator:==; 168, 169; 168, 173; 169, subscript; 169, 170; 169, 171; 169, 172; 170, identifier:circulation; 171, integer:2; 172, identifier:n; 173, integer:1; 174, call; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:np; 177, identifier:all; 178, argument_list; 178, 179; 179, comparison_operator:==; 179, 180; 179, 185; 180, subscript; 180, 181; 180, 182; 180, 184; 181, identifier:circulation; 182, slice; 182, 183; 183, colon; 184, identifier:n; 185, integer:0; 186, comment; 187, block; 187, 188; 188, continue_statement; 189, if_statement; 189, 190; 189, 200; 190, comparison_operator:>; 190, 191; 190, 199; 191, call; 191, 192; 191, 193; 192, identifier:sum; 193, argument_list; 193, 194; 194, subscript; 194, 195; 194, 196; 194, 198; 195, identifier:circulation; 196, slice; 196, 197; 197, colon; 198, identifier:n; 199, integer:1; 200, block; 200, 201; 201, expression_statement; 201, 202; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:logger; 205, identifier:warning; 206, argument_list; 206, 207; 207, concatenated_string; 207, 208; 207, 209; 208, string:"Circulation about multiple axes - are you sure "; 209, string:"the orbit has been integrated for long enough?"; 210, if_statement; 210, 211; 210, 217; 210, 222; 210, 234; 211, comparison_operator:==; 211, 212; 211, 216; 212, subscript; 212, 213; 212, 214; 212, 215; 213, identifier:circulation; 214, integer:0; 215, identifier:n; 216, integer:1; 217, block; 217, 218; 218, expression_statement; 218, 219; 219, assignment; 219, 220; 219, 221; 220, identifier:circ; 221, integer:0; 222, elif_clause; 222, 223; 222, 229; 223, comparison_operator:==; 223, 224; 223, 228; 224, subscript; 224, 225; 224, 226; 224, 227; 225, identifier:circulation; 226, integer:1; 227, identifier:n; 228, integer:1; 229, block; 229, 230; 230, expression_statement; 230, 231; 231, assignment; 231, 232; 231, 233; 232, identifier:circ; 233, integer:1; 234, else_clause; 234, 235; 235, block; 235, 236; 236, raise_statement; 236, 237; 237, call; 237, 238; 237, 239; 238, identifier:RuntimeError; 239, argument_list; 239, 240; 240, string:"Should never get here..."; 241, expression_statement; 241, 242; 242, assignment; 242, 243; 242, 249; 243, subscript; 243, 244; 243, 245; 243, 246; 243, 248; 244, identifier:new_pos; 245, identifier:circ; 246, slice; 246, 247; 247, colon; 248, identifier:n; 249, subscript; 249, 250; 249, 251; 249, 252; 249, 254; 250, identifier:pos; 251, integer:2; 252, slice; 252, 253; 253, colon; 254, identifier:n; 255, expression_statement; 255, 256; 256, assignment; 256, 257; 256, 263; 257, subscript; 257, 258; 257, 259; 257, 260; 257, 262; 258, identifier:new_pos; 259, integer:2; 260, slice; 260, 261; 261, colon; 262, identifier:n; 263, subscript; 263, 264; 263, 265; 263, 266; 263, 268; 264, identifier:pos; 265, identifier:circ; 266, slice; 266, 267; 267, colon; 268, identifier:n; 269, expression_statement; 269, 270; 270, assignment; 270, 271; 270, 277; 271, subscript; 271, 272; 271, 273; 271, 274; 271, 276; 272, identifier:new_vel; 273, identifier:circ; 274, slice; 274, 275; 275, colon; 276, identifier:n; 277, subscript; 277, 278; 277, 279; 277, 280; 277, 282; 278, identifier:vel; 279, integer:2; 280, slice; 280, 281; 281, colon; 282, identifier:n; 283, expression_statement; 283, 284; 284, assignment; 284, 285; 284, 291; 285, subscript; 285, 286; 285, 287; 285, 288; 285, 290; 286, identifier:new_vel; 287, integer:2; 288, slice; 288, 289; 289, colon; 290, identifier:n; 291, subscript; 291, 292; 291, 293; 291, 294; 291, 296; 292, identifier:vel; 293, identifier:circ; 294, slice; 294, 295; 295, colon; 296, identifier:n; 297, return_statement; 297, 298; 298, call; 298, 299; 298, 302; 299, attribute; 299, 300; 299, 301; 300, identifier:self; 301, identifier:__class__; 302, argument_list; 302, 303; 302, 315; 302, 327; 302, 332; 303, keyword_argument; 303, 304; 303, 305; 304, identifier:pos; 305, call; 305, 306; 305, 309; 306, attribute; 306, 307; 306, 308; 307, identifier:new_pos; 308, identifier:reshape; 309, argument_list; 309, 310; 310, attribute; 310, 311; 310, 314; 311, attribute; 311, 312; 311, 313; 312, identifier:cart; 313, identifier:xyz; 314, identifier:shape; 315, keyword_argument; 315, 316; 315, 317; 316, identifier:vel; 317, call; 317, 318; 317, 321; 318, attribute; 318, 319; 318, 320; 319, identifier:new_vel; 320, identifier:reshape; 321, argument_list; 321, 322; 322, attribute; 322, 323; 322, 326; 323, attribute; 323, 324; 323, 325; 324, identifier:cart; 325, identifier:xyz; 326, identifier:shape; 327, keyword_argument; 327, 328; 327, 329; 328, identifier:t; 329, attribute; 329, 330; 329, 331; 330, identifier:self; 331, identifier:t; 332, keyword_argument; 332, 333; 332, 334; 333, identifier:hamiltonian; 334, attribute; 334, 335; 334, 336; 335, identifier:self; 336, identifier:hamiltonian | def align_circulation_with_z(self, circulation=None):
"""
If the input orbit is a tube orbit, this function aligns the circulation
axis with the z axis and returns a copy.
Parameters
----------
circulation : array_like (optional)
Array of bits that specify the axis about which the orbit
circulates. If not provided, will compute this using
:meth:`~gala.dynamics.Orbit.circulation`. See that method for more
information.
Returns
-------
orb : :class:`~gala.dynamics.Orbit`
A copy of the original orbit object with circulation aligned with
the z axis.
"""
if circulation is None:
circulation = self.circulation()
circulation = atleast_2d(circulation, insert_axis=1)
cart = self.cartesian
pos = cart.xyz
vel = np.vstack((cart.v_x.value[None],
cart.v_y.value[None],
cart.v_z.value[None])) * cart.v_x.unit
if pos.ndim < 3:
pos = pos[...,np.newaxis]
vel = vel[...,np.newaxis]
if (circulation.shape[0] != self.ndim or
circulation.shape[1] != pos.shape[2]):
raise ValueError("Shape of 'circulation' array should match the "
"shape of the position/velocity (minus the time "
"axis).")
new_pos = pos.copy()
new_vel = vel.copy()
for n in range(pos.shape[2]):
if circulation[2,n] == 1 or np.all(circulation[:,n] == 0):
# already circulating about z or box orbit
continue
if sum(circulation[:,n]) > 1:
logger.warning("Circulation about multiple axes - are you sure "
"the orbit has been integrated for long enough?")
if circulation[0,n] == 1:
circ = 0
elif circulation[1,n] == 1:
circ = 1
else:
raise RuntimeError("Should never get here...")
new_pos[circ,:,n] = pos[2,:,n]
new_pos[2,:,n] = pos[circ,:,n]
new_vel[circ,:,n] = vel[2,:,n]
new_vel[2,:,n] = vel[circ,:,n]
return self.__class__(pos=new_pos.reshape(cart.xyz.shape),
vel=new_vel.reshape(cart.xyz.shape),
t=self.t,
hamiltonian=self.hamiltonian) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 32; 2, function_name:fast_lyapunov_max; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 4, identifier:w0; 5, identifier:hamiltonian; 6, identifier:dt; 7, identifier:n_steps; 8, default_parameter; 8, 9; 8, 10; 9, identifier:d0; 10, float:1e-5; 11, default_parameter; 11, 12; 11, 13; 12, identifier:n_steps_per_pullback; 13, integer:10; 14, default_parameter; 14, 15; 14, 16; 15, identifier:noffset_orbits; 16, integer:2; 17, default_parameter; 17, 18; 17, 19; 18, identifier:t1; 19, float:0.; 20, default_parameter; 20, 21; 20, 22; 21, identifier:atol; 22, float:1E-10; 23, default_parameter; 23, 24; 23, 25; 24, identifier:rtol; 25, float:1E-10; 26, default_parameter; 26, 27; 26, 28; 27, identifier:nmax; 28, integer:0; 29, default_parameter; 29, 30; 29, 31; 30, identifier:return_orbit; 31, True; 32, block; 32, 33; 32, 35; 32, 44; 32, 45; 32, 66; 32, 79; 32, 126; 32, 142; 32, 154; 33, expression_statement; 33, 34; 34, comment; 35, import_from_statement; 35, 36; 35, 40; 35, 42; 36, relative_import; 36, 37; 36, 38; 37, import_prefix; 38, dotted_name; 38, 39; 39, identifier:lyapunov; 40, dotted_name; 40, 41; 41, identifier:dop853_lyapunov_max; 42, dotted_name; 42, 43; 43, identifier:dop853_lyapunov_max_dont_save; 44, comment; 45, if_statement; 45, 46; 45, 51; 46, call; 46, 47; 46, 48; 47, identifier:isinstance; 48, argument_list; 48, 49; 48, 50; 49, identifier:hamiltonian; 50, identifier:PotentialBase; 51, block; 51, 52; 51, 59; 52, import_from_statement; 52, 53; 52, 57; 53, relative_import; 53, 54; 53, 55; 54, import_prefix; 55, dotted_name; 55, 56; 56, identifier:potential; 57, dotted_name; 57, 58; 58, identifier:Hamiltonian; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:hamiltonian; 62, call; 62, 63; 62, 64; 63, identifier:Hamiltonian; 64, argument_list; 64, 65; 65, identifier:hamiltonian; 66, if_statement; 66, 67; 66, 71; 67, not_operator; 67, 68; 68, attribute; 68, 69; 68, 70; 69, identifier:hamiltonian; 70, identifier:c_enabled; 71, block; 71, 72; 72, raise_statement; 72, 73; 73, call; 73, 74; 73, 75; 74, identifier:TypeError; 75, argument_list; 75, 76; 76, concatenated_string; 76, 77; 76, 78; 77, string:"Input Hamiltonian must contain a C-implemented "; 78, string:"potential and frame."; 79, if_statement; 79, 80; 79, 86; 80, not_operator; 80, 81; 81, call; 81, 82; 81, 83; 82, identifier:isinstance; 83, argument_list; 83, 84; 83, 85; 84, identifier:w0; 85, identifier:PhaseSpacePosition; 86, block; 86, 87; 86, 96; 86, 106; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:w0; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:np; 93, identifier:asarray; 94, argument_list; 94, 95; 95, identifier:w0; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:ndim; 99, binary_operator://; 99, 100; 99, 105; 100, subscript; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:w0; 103, identifier:shape; 104, integer:0; 105, integer:2; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:w0; 109, call; 109, 110; 109, 111; 110, identifier:PhaseSpacePosition; 111, argument_list; 111, 112; 111, 119; 112, keyword_argument; 112, 113; 112, 114; 113, identifier:pos; 114, subscript; 114, 115; 114, 116; 115, identifier:w0; 116, slice; 116, 117; 116, 118; 117, colon; 118, identifier:ndim; 119, keyword_argument; 119, 120; 119, 121; 120, identifier:vel; 121, subscript; 121, 122; 121, 123; 122, identifier:w0; 123, slice; 123, 124; 123, 125; 124, identifier:ndim; 125, colon; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:_w0; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:np; 132, identifier:squeeze; 133, argument_list; 133, 134; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:w0; 137, identifier:w; 138, argument_list; 138, 139; 139, attribute; 139, 140; 139, 141; 140, identifier:hamiltonian; 141, identifier:units; 142, if_statement; 142, 143; 142, 148; 143, comparison_operator:>; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:_w0; 146, identifier:ndim; 147, integer:1; 148, block; 148, 149; 149, raise_statement; 149, 150; 150, call; 150, 151; 150, 152; 151, identifier:ValueError; 152, argument_list; 152, 153; 153, string:"Can only compute fast Lyapunov exponent for a single orbit."; 154, if_statement; 154, 155; 154, 156; 154, 241; 155, identifier:return_orbit; 156, block; 156, 157; 156, 179; 156, 190; 156, 211; 156, 235; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 163; 159, pattern_list; 159, 160; 159, 161; 159, 162; 160, identifier:t; 161, identifier:w; 162, identifier:l; 163, call; 163, 164; 163, 165; 164, identifier:dop853_lyapunov_max; 165, argument_list; 165, 166; 165, 167; 165, 168; 165, 169; 165, 172; 165, 173; 165, 174; 165, 175; 165, 176; 165, 177; 165, 178; 166, identifier:hamiltonian; 167, identifier:_w0; 168, identifier:dt; 169, binary_operator:+; 169, 170; 169, 171; 170, identifier:n_steps; 171, integer:1; 172, identifier:t1; 173, identifier:d0; 174, identifier:n_steps_per_pullback; 175, identifier:noffset_orbits; 176, identifier:atol; 177, identifier:rtol; 178, identifier:nmax; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 182; 181, identifier:w; 182, call; 182, 183; 182, 186; 183, attribute; 183, 184; 183, 185; 184, identifier:np; 185, identifier:rollaxis; 186, argument_list; 186, 187; 186, 188; 187, identifier:w; 188, unary_operator:-; 188, 189; 189, integer:1; 190, try_statement; 190, 191; 190, 200; 191, block; 191, 192; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 195; 194, identifier:tunit; 195, subscript; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:hamiltonian; 198, identifier:units; 199, string:'time'; 200, except_clause; 200, 201; 200, 204; 201, tuple; 201, 202; 201, 203; 202, identifier:TypeError; 203, identifier:AttributeError; 204, block; 204, 205; 205, expression_statement; 205, 206; 206, assignment; 206, 207; 206, 208; 207, identifier:tunit; 208, attribute; 208, 209; 208, 210; 209, identifier:u; 210, identifier:dimensionless_unscaled; 211, expression_statement; 211, 212; 212, assignment; 212, 213; 212, 214; 213, identifier:orbit; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:Orbit; 217, identifier:from_w; 218, argument_list; 218, 219; 218, 222; 218, 227; 218, 232; 219, keyword_argument; 219, 220; 219, 221; 220, identifier:w; 221, identifier:w; 222, keyword_argument; 222, 223; 222, 224; 223, identifier:units; 224, attribute; 224, 225; 224, 226; 225, identifier:hamiltonian; 226, identifier:units; 227, keyword_argument; 227, 228; 227, 229; 228, identifier:t; 229, binary_operator:*; 229, 230; 229, 231; 230, identifier:t; 231, identifier:tunit; 232, keyword_argument; 232, 233; 232, 234; 233, identifier:hamiltonian; 234, identifier:hamiltonian; 235, return_statement; 235, 236; 236, expression_list; 236, 237; 236, 240; 237, binary_operator:/; 237, 238; 237, 239; 238, identifier:l; 239, identifier:tunit; 240, identifier:orbit; 241, else_clause; 241, 242; 242, block; 242, 243; 242, 262; 242, 283; 243, expression_statement; 243, 244; 244, assignment; 244, 245; 244, 246; 245, identifier:l; 246, call; 246, 247; 246, 248; 247, identifier:dop853_lyapunov_max_dont_save; 248, argument_list; 248, 249; 248, 250; 248, 251; 248, 252; 248, 255; 248, 256; 248, 257; 248, 258; 248, 259; 248, 260; 248, 261; 249, identifier:hamiltonian; 250, identifier:_w0; 251, identifier:dt; 252, binary_operator:+; 252, 253; 252, 254; 253, identifier:n_steps; 254, integer:1; 255, identifier:t1; 256, identifier:d0; 257, identifier:n_steps_per_pullback; 258, identifier:noffset_orbits; 259, identifier:atol; 260, identifier:rtol; 261, identifier:nmax; 262, try_statement; 262, 263; 262, 272; 263, block; 263, 264; 264, expression_statement; 264, 265; 265, assignment; 265, 266; 265, 267; 266, identifier:tunit; 267, subscript; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, identifier:hamiltonian; 270, identifier:units; 271, string:'time'; 272, except_clause; 272, 273; 272, 276; 273, tuple; 273, 274; 273, 275; 274, identifier:TypeError; 275, identifier:AttributeError; 276, block; 276, 277; 277, expression_statement; 277, 278; 278, assignment; 278, 279; 278, 280; 279, identifier:tunit; 280, attribute; 280, 281; 280, 282; 281, identifier:u; 282, identifier:dimensionless_unscaled; 283, return_statement; 283, 284; 284, binary_operator:/; 284, 285; 284, 286; 285, identifier:l; 286, identifier:tunit | def fast_lyapunov_max(w0, hamiltonian, dt, n_steps, d0=1e-5,
n_steps_per_pullback=10, noffset_orbits=2, t1=0.,
atol=1E-10, rtol=1E-10, nmax=0, return_orbit=True):
"""
Compute the maximum Lyapunov exponent using a C-implemented estimator
that uses the DOPRI853 integrator.
Parameters
----------
w0 : `~gala.dynamics.PhaseSpacePosition`, array_like
Initial conditions.
hamiltonian : `~gala.potential.Hamiltonian`
dt : numeric
Timestep.
n_steps : int
Number of steps to run for.
d0 : numeric (optional)
The initial separation.
n_steps_per_pullback : int (optional)
Number of steps to run before re-normalizing the offset vectors.
noffset_orbits : int (optional)
Number of offset orbits to run.
t1 : numeric (optional)
Time of initial conditions. Assumed to be t=0.
return_orbit : bool (optional)
Store the full orbit for the parent and all offset orbits.
Returns
-------
LEs : :class:`~astropy.units.Quantity`
Lyapunov exponents calculated from each offset / deviation orbit.
orbit : `~gala.dynamics.Orbit` (optional)
"""
from .lyapunov import dop853_lyapunov_max, dop853_lyapunov_max_dont_save
# TODO: remove in v1.0
if isinstance(hamiltonian, PotentialBase):
from ..potential import Hamiltonian
hamiltonian = Hamiltonian(hamiltonian)
if not hamiltonian.c_enabled:
raise TypeError("Input Hamiltonian must contain a C-implemented "
"potential and frame.")
if not isinstance(w0, PhaseSpacePosition):
w0 = np.asarray(w0)
ndim = w0.shape[0]//2
w0 = PhaseSpacePosition(pos=w0[:ndim],
vel=w0[ndim:])
_w0 = np.squeeze(w0.w(hamiltonian.units))
if _w0.ndim > 1:
raise ValueError("Can only compute fast Lyapunov exponent for a single orbit.")
if return_orbit:
t,w,l = dop853_lyapunov_max(hamiltonian, _w0,
dt, n_steps+1, t1,
d0, n_steps_per_pullback, noffset_orbits,
atol, rtol, nmax)
w = np.rollaxis(w, -1)
try:
tunit = hamiltonian.units['time']
except (TypeError, AttributeError):
tunit = u.dimensionless_unscaled
orbit = Orbit.from_w(w=w, units=hamiltonian.units,
t=t*tunit, hamiltonian=hamiltonian)
return l/tunit, orbit
else:
l = dop853_lyapunov_max_dont_save(hamiltonian, _w0,
dt, n_steps+1, t1,
d0, n_steps_per_pullback, noffset_orbits,
atol, rtol, nmax)
try:
tunit = hamiltonian.units['time']
except (TypeError, AttributeError):
tunit = u.dimensionless_unscaled
return l/tunit |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:estimate_dt_n_steps; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 11; 3, 16; 4, identifier:w0; 5, identifier:hamiltonian; 6, identifier:n_periods; 7, identifier:n_steps_per_period; 8, default_parameter; 8, 9; 8, 10; 9, identifier:dE_threshold; 10, float:1E-9; 11, default_parameter; 11, 12; 11, 13; 12, identifier:func; 13, attribute; 13, 14; 13, 15; 14, identifier:np; 15, identifier:nanmax; 16, dictionary_splat_pattern; 16, 17; 17, identifier:integrate_kwargs; 18, block; 18, 19; 18, 21; 18, 52; 18, 53; 18, 66; 18, 78; 18, 95; 18, 96; 18, 104; 18, 220; 18, 221; 18, 228; 18, 241; 18, 254; 18, 263; 18, 277; 18, 291; 19, expression_statement; 19, 20; 20, comment; 21, if_statement; 21, 22; 21, 28; 22, not_operator; 22, 23; 23, call; 23, 24; 23, 25; 24, identifier:isinstance; 25, argument_list; 25, 26; 25, 27; 26, identifier:w0; 27, identifier:PhaseSpacePosition; 28, block; 28, 29; 28, 38; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:w0; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:np; 35, identifier:asarray; 36, argument_list; 36, 37; 37, identifier:w0; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:w0; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:PhaseSpacePosition; 44, identifier:from_w; 45, argument_list; 45, 46; 45, 47; 46, identifier:w0; 47, keyword_argument; 47, 48; 47, 49; 48, identifier:units; 49, attribute; 49, 50; 49, 51; 50, identifier:hamiltonian; 51, identifier:units; 52, comment; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:dt; 56, call; 56, 57; 56, 58; 57, identifier:_autodetermine_initial_dt; 58, argument_list; 58, 59; 58, 60; 58, 61; 58, 64; 59, identifier:w0; 60, identifier:hamiltonian; 61, keyword_argument; 61, 62; 61, 63; 62, identifier:dE_threshold; 63, identifier:dE_threshold; 64, dictionary_splat; 64, 65; 65, identifier:integrate_kwargs; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:n_steps; 69, call; 69, 70; 69, 71; 70, identifier:int; 71, argument_list; 71, 72; 72, call; 72, 73; 72, 74; 73, identifier:round; 74, argument_list; 74, 75; 75, binary_operator:/; 75, 76; 75, 77; 76, integer:10000; 77, identifier:dt; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:orbit; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:hamiltonian; 84, identifier:integrate_orbit; 85, argument_list; 85, 86; 85, 87; 85, 90; 85, 93; 86, identifier:w0; 87, keyword_argument; 87, 88; 87, 89; 88, identifier:dt; 89, identifier:dt; 90, keyword_argument; 90, 91; 90, 92; 91, identifier:n_steps; 92, identifier:n_steps; 93, dictionary_splat; 93, 94; 94, identifier:integrate_kwargs; 95, comment; 96, expression_statement; 96, 97; 97, assignment; 97, 98; 97, 99; 98, identifier:circ; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:orbit; 102, identifier:circulation; 103, argument_list; 104, if_statement; 104, 105; 104, 111; 104, 189; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:np; 108, identifier:any; 109, argument_list; 109, 110; 110, identifier:circ; 111, block; 111, 112; 111, 123; 111, 134; 111, 135; 111, 143; 111, 151; 111, 159; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:orbit; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:orbit; 118, identifier:align_circulation_with_z; 119, argument_list; 119, 120; 120, keyword_argument; 120, 121; 120, 122; 121, identifier:circulation; 122, identifier:circ; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:cyl; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:orbit; 129, identifier:represent_as; 130, argument_list; 130, 131; 131, attribute; 131, 132; 131, 133; 132, identifier:coord; 133, identifier:CylindricalRepresentation; 134, comment; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:R; 138, attribute; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:cyl; 141, identifier:rho; 142, identifier:value; 143, expression_statement; 143, 144; 144, assignment; 144, 145; 144, 146; 145, identifier:phi; 146, attribute; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:cyl; 149, identifier:phi; 150, identifier:value; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:z; 154, attribute; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:cyl; 157, identifier:z; 158, identifier:value; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:T; 162, binary_operator:*; 162, 163; 162, 184; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:np; 166, identifier:array; 167, argument_list; 167, 168; 168, list_comprehension; 168, 169; 168, 178; 169, attribute; 169, 170; 169, 177; 170, call; 170, 171; 170, 172; 171, identifier:peak_to_peak_period; 172, argument_list; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:orbit; 175, identifier:t; 176, identifier:f; 177, identifier:value; 178, for_in_clause; 178, 179; 178, 180; 179, identifier:f; 180, list:[R, phi, z]; 180, 181; 180, 182; 180, 183; 181, identifier:R; 182, identifier:phi; 183, identifier:z; 184, attribute; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:orbit; 187, identifier:t; 188, identifier:unit; 189, else_clause; 189, 190; 190, block; 190, 191; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:T; 194, binary_operator:*; 194, 195; 194, 215; 195, call; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:np; 198, identifier:array; 199, argument_list; 199, 200; 200, list_comprehension; 200, 201; 200, 210; 201, attribute; 201, 202; 201, 209; 202, call; 202, 203; 202, 204; 203, identifier:peak_to_peak_period; 204, argument_list; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:orbit; 207, identifier:t; 208, identifier:f; 209, identifier:value; 210, for_in_clause; 210, 211; 210, 212; 211, identifier:f; 212, attribute; 212, 213; 212, 214; 213, identifier:orbit; 214, identifier:pos; 215, attribute; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:orbit; 218, identifier:t; 219, identifier:unit; 220, comment; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 224; 223, identifier:T; 224, call; 224, 225; 224, 226; 225, identifier:func; 226, argument_list; 226, 227; 227, identifier:T; 228, if_statement; 228, 229; 228, 235; 229, call; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:np; 232, identifier:isnan; 233, argument_list; 233, 234; 234, identifier:T; 235, block; 235, 236; 236, raise_statement; 236, 237; 237, call; 237, 238; 237, 239; 238, identifier:RuntimeError; 239, argument_list; 239, 240; 240, string:"Failed to find period."; 241, expression_statement; 241, 242; 242, assignment; 242, 243; 242, 244; 243, identifier:T; 244, attribute; 244, 245; 244, 253; 245, call; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:T; 248, identifier:decompose; 249, argument_list; 249, 250; 250, attribute; 250, 251; 250, 252; 251, identifier:hamiltonian; 252, identifier:units; 253, identifier:value; 254, expression_statement; 254, 255; 255, assignment; 255, 256; 255, 257; 256, identifier:dt; 257, binary_operator:/; 257, 258; 257, 259; 258, identifier:T; 259, call; 259, 260; 259, 261; 260, identifier:float; 261, argument_list; 261, 262; 262, identifier:n_steps_per_period; 263, expression_statement; 263, 264; 264, assignment; 264, 265; 264, 266; 265, identifier:n_steps; 266, call; 266, 267; 266, 268; 267, identifier:int; 268, argument_list; 268, 269; 269, call; 269, 270; 269, 271; 270, identifier:round; 271, argument_list; 271, 272; 272, binary_operator:/; 272, 273; 272, 276; 273, binary_operator:*; 273, 274; 273, 275; 274, identifier:n_periods; 275, identifier:T; 276, identifier:dt; 277, if_statement; 277, 278; 277, 285; 278, boolean_operator:or; 278, 279; 278, 282; 279, comparison_operator:==; 279, 280; 279, 281; 280, identifier:dt; 281, float:0.; 282, comparison_operator:<; 282, 283; 282, 284; 283, identifier:dt; 284, float:1E-13; 285, block; 285, 286; 286, raise_statement; 286, 287; 287, call; 287, 288; 287, 289; 288, identifier:ValueError; 289, argument_list; 289, 290; 290, string:"Timestep is zero or very small!"; 291, return_statement; 291, 292; 292, expression_list; 292, 293; 292, 294; 293, identifier:dt; 294, identifier:n_steps | def estimate_dt_n_steps(w0, hamiltonian, n_periods, n_steps_per_period,
dE_threshold=1E-9, func=np.nanmax,
**integrate_kwargs):
"""
Estimate the timestep and number of steps to integrate an orbit for
given its initial conditions and a potential object.
Parameters
----------
w0 : `~gala.dynamics.PhaseSpacePosition`, array_like
Initial conditions.
potential : :class:`~gala.potential.PotentialBase`
The potential to integrate the orbit in.
n_periods : int
Number of (max) orbital periods to integrate for.
n_steps_per_period : int
Number of steps to take per (max) orbital period.
dE_threshold : numeric (optional)
Maximum fractional energy difference -- used to determine initial
timestep. Set to ``None`` to ignore this.
func : callable (optional)
Determines which period to use. By default, this takes the maximum
period using :func:`~numpy.nanmax`. Other options could be
:func:`~numpy.nanmin`, :func:`~numpy.nanmean`, :func:`~numpy.nanmedian`.
Returns
-------
dt : float
The timestep.
n_steps : int
The number of timesteps to integrate for.
"""
if not isinstance(w0, PhaseSpacePosition):
w0 = np.asarray(w0)
w0 = PhaseSpacePosition.from_w(w0, units=hamiltonian.units)
# integrate orbit
dt = _autodetermine_initial_dt(w0, hamiltonian, dE_threshold=dE_threshold,
**integrate_kwargs)
n_steps = int(round(10000 / dt))
orbit = hamiltonian.integrate_orbit(w0, dt=dt, n_steps=n_steps,
**integrate_kwargs)
# if loop, align circulation with Z and take R period
circ = orbit.circulation()
if np.any(circ):
orbit = orbit.align_circulation_with_z(circulation=circ)
cyl = orbit.represent_as(coord.CylindricalRepresentation)
# convert to cylindrical coordinates
R = cyl.rho.value
phi = cyl.phi.value
z = cyl.z.value
T = np.array([peak_to_peak_period(orbit.t, f).value
for f in [R, phi, z]])*orbit.t.unit
else:
T = np.array([peak_to_peak_period(orbit.t, f).value
for f in orbit.pos])*orbit.t.unit
# timestep from number of steps per period
T = func(T)
if np.isnan(T):
raise RuntimeError("Failed to find period.")
T = T.decompose(hamiltonian.units).value
dt = T / float(n_steps_per_period)
n_steps = int(round(n_periods * T / dt))
if dt == 0. or dt < 1E-13:
raise ValueError("Timestep is zero or very small!")
return dt, n_steps |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 27; 2, function_name:plot_projections; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 19; 3, 22; 3, 25; 4, identifier:x; 5, default_parameter; 5, 6; 5, 7; 6, identifier:relative_to; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:autolim; 10, True; 11, default_parameter; 11, 12; 11, 13; 12, identifier:axes; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:subplots_kwargs; 16, call; 16, 17; 16, 18; 17, identifier:dict; 18, argument_list; 19, default_parameter; 19, 20; 19, 21; 20, identifier:labels; 21, None; 22, default_parameter; 22, 23; 22, 24; 23, identifier:plot_function; 24, None; 25, dictionary_splat_pattern; 25, 26; 26, identifier:kwargs; 27, block; 27, 28; 27, 30; 27, 31; 27, 43; 27, 51; 27, 52; 27, 69; 27, 70; 27, 79; 27, 80; 27, 86; 27, 87; 27, 155; 27, 159; 27, 258; 27, 268; 28, expression_statement; 28, 29; 29, comment; 30, comment; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:x; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:np; 37, identifier:array; 38, argument_list; 38, 39; 38, 40; 39, identifier:x; 40, keyword_argument; 40, 41; 40, 42; 41, identifier:copy; 42, True; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:ndim; 46, subscript; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:x; 49, identifier:shape; 50, integer:0; 51, comment; 52, if_statement; 52, 53; 52, 56; 53, comparison_operator:is; 53, 54; 53, 55; 54, identifier:axes; 55, None; 56, block; 56, 57; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:axes; 60, call; 60, 61; 60, 62; 61, identifier:_get_axes; 62, argument_list; 62, 63; 62, 66; 63, keyword_argument; 63, 64; 63, 65; 64, identifier:dim; 65, identifier:ndim; 66, keyword_argument; 66, 67; 66, 68; 67, identifier:subplots_kwargs; 68, identifier:subplots_kwargs; 69, comment; 70, if_statement; 70, 71; 70, 74; 71, comparison_operator:is; 71, 72; 71, 73; 72, identifier:relative_to; 73, None; 74, block; 74, 75; 75, expression_statement; 75, 76; 76, augmented_assignment:-=; 76, 77; 76, 78; 77, identifier:x; 78, identifier:relative_to; 79, comment; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:plot_fn_name; 83, attribute; 83, 84; 83, 85; 84, identifier:plot_function; 85, identifier:__name__; 86, comment; 87, if_statement; 87, 88; 87, 89; 88, identifier:autolim; 89, block; 89, 90; 89, 94; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:lims; 93, list:[]; 94, for_statement; 94, 95; 94, 96; 94, 100; 95, identifier:i; 96, call; 96, 97; 96, 98; 97, identifier:range; 98, argument_list; 98, 99; 99, identifier:ndim; 100, block; 100, 101; 100, 123; 100, 129; 100, 138; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 106; 103, pattern_list; 103, 104; 103, 105; 104, identifier:max_; 105, identifier:min_; 106, expression_list; 106, 107; 106, 115; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:np; 110, identifier:max; 111, argument_list; 111, 112; 112, subscript; 112, 113; 112, 114; 113, identifier:x; 114, identifier:i; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:np; 118, identifier:min; 119, argument_list; 119, 120; 120, subscript; 120, 121; 120, 122; 121, identifier:x; 122, identifier:i; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:delta; 126, binary_operator:-; 126, 127; 126, 128; 127, identifier:max_; 128, identifier:min_; 129, if_statement; 129, 130; 129, 133; 130, comparison_operator:==; 130, 131; 130, 132; 131, identifier:delta; 132, float:0.; 133, block; 133, 134; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:delta; 137, float:1.; 138, expression_statement; 138, 139; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, identifier:lims; 142, identifier:append; 143, argument_list; 143, 144; 144, list:[min_ - delta*0.02, max_ + delta*0.02]; 144, 145; 144, 150; 145, binary_operator:-; 145, 146; 145, 147; 146, identifier:min_; 147, binary_operator:*; 147, 148; 147, 149; 148, identifier:delta; 149, float:0.02; 150, binary_operator:+; 150, 151; 150, 152; 151, identifier:max_; 152, binary_operator:*; 152, 153; 152, 154; 153, identifier:delta; 154, float:0.02; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:k; 158, integer:0; 159, for_statement; 159, 160; 159, 161; 159, 165; 160, identifier:i; 161, call; 161, 162; 161, 163; 162, identifier:range; 163, argument_list; 163, 164; 164, identifier:ndim; 165, block; 165, 166; 166, for_statement; 166, 167; 166, 168; 166, 172; 167, identifier:j; 168, call; 168, 169; 168, 170; 169, identifier:range; 170, argument_list; 170, 171; 171, identifier:ndim; 172, block; 172, 173; 172, 180; 172, 190; 172, 202; 172, 229; 172, 254; 173, if_statement; 173, 174; 173, 177; 174, comparison_operator:>=; 174, 175; 174, 176; 175, identifier:i; 176, identifier:j; 177, block; 177, 178; 177, 179; 178, continue_statement; 179, comment; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 183; 182, identifier:plot_func; 183, call; 183, 184; 183, 185; 184, identifier:getattr; 185, argument_list; 185, 186; 185, 189; 186, subscript; 186, 187; 186, 188; 187, identifier:axes; 188, identifier:k; 189, identifier:plot_fn_name; 190, expression_statement; 190, 191; 191, call; 191, 192; 191, 193; 192, identifier:plot_func; 193, argument_list; 193, 194; 193, 197; 193, 200; 194, subscript; 194, 195; 194, 196; 195, identifier:x; 196, identifier:i; 197, subscript; 197, 198; 197, 199; 198, identifier:x; 199, identifier:j; 200, dictionary_splat; 200, 201; 201, identifier:kwargs; 202, if_statement; 202, 203; 202, 206; 203, comparison_operator:is; 203, 204; 203, 205; 204, identifier:labels; 205, None; 206, block; 206, 207; 206, 218; 207, expression_statement; 207, 208; 208, call; 208, 209; 208, 214; 209, attribute; 209, 210; 209, 213; 210, subscript; 210, 211; 210, 212; 211, identifier:axes; 212, identifier:k; 213, identifier:set_xlabel; 214, argument_list; 214, 215; 215, subscript; 215, 216; 215, 217; 216, identifier:labels; 217, identifier:i; 218, expression_statement; 218, 219; 219, call; 219, 220; 219, 225; 220, attribute; 220, 221; 220, 224; 221, subscript; 221, 222; 221, 223; 222, identifier:axes; 223, identifier:k; 224, identifier:set_ylabel; 225, argument_list; 225, 226; 226, subscript; 226, 227; 226, 228; 227, identifier:labels; 228, identifier:j; 229, if_statement; 229, 230; 229, 231; 230, identifier:autolim; 231, block; 231, 232; 231, 243; 232, expression_statement; 232, 233; 233, call; 233, 234; 233, 239; 234, attribute; 234, 235; 234, 238; 235, subscript; 235, 236; 235, 237; 236, identifier:axes; 237, identifier:k; 238, identifier:set_xlim; 239, argument_list; 239, 240; 240, subscript; 240, 241; 240, 242; 241, identifier:lims; 242, identifier:i; 243, expression_statement; 243, 244; 244, call; 244, 245; 244, 250; 245, attribute; 245, 246; 245, 249; 246, subscript; 246, 247; 246, 248; 247, identifier:axes; 248, identifier:k; 249, identifier:set_ylim; 250, argument_list; 250, 251; 251, subscript; 251, 252; 251, 253; 252, identifier:lims; 253, identifier:j; 254, expression_statement; 254, 255; 255, augmented_assignment:+=; 255, 256; 255, 257; 256, identifier:k; 257, integer:1; 258, expression_statement; 258, 259; 259, call; 259, 260; 259, 267; 260, attribute; 260, 261; 260, 266; 261, attribute; 261, 262; 261, 265; 262, subscript; 262, 263; 262, 264; 263, identifier:axes; 264, integer:0; 265, identifier:figure; 266, identifier:tight_layout; 267, argument_list; 268, return_statement; 268, 269; 269, attribute; 269, 270; 269, 273; 270, subscript; 270, 271; 270, 272; 271, identifier:axes; 272, integer:0; 273, identifier:figure | def plot_projections(x, relative_to=None, autolim=True, axes=None,
subplots_kwargs=dict(), labels=None, plot_function=None,
**kwargs):
"""
Given N-dimensional quantity, ``x``, make a figure containing 2D projections
of all combinations of the axes.
Parameters
----------
x : array_like
Array of values. ``axis=0`` is assumed to be the dimensionality,
``axis=1`` is the time axis. See :ref:`shape-conventions` for more
information.
relative_to : bool (optional)
Plot the values relative to this value or values.
autolim : bool (optional)
Automatically set the plot limits to be something sensible.
axes : array_like (optional)
Array of matplotlib Axes objects.
subplots_kwargs : dict (optional)
Dictionary of kwargs passed to :func:`~matplotlib.pyplot.subplots`.
labels : iterable (optional)
List or iterable of axis labels as strings. They should correspond to
the dimensions of the input orbit.
plot_function : callable (optional)
The ``matplotlib`` plot function to use. By default, this is
:func:`~matplotlib.pyplot.scatter`, but can also be, e.g.,
:func:`~matplotlib.pyplot.plot`.
**kwargs
All other keyword arguments are passed to the ``plot_function``.
You can pass in any of the usual style kwargs like ``color=...``,
``marker=...``, etc.
Returns
-------
fig : `~matplotlib.Figure`
"""
# don't propagate changes back...
x = np.array(x, copy=True)
ndim = x.shape[0]
# get axes object from arguments
if axes is None:
axes = _get_axes(dim=ndim, subplots_kwargs=subplots_kwargs)
# if the quantities are relative
if relative_to is not None:
x -= relative_to
# name of the plotting function
plot_fn_name = plot_function.__name__
# automatically determine limits
if autolim:
lims = []
for i in range(ndim):
max_,min_ = np.max(x[i]), np.min(x[i])
delta = max_ - min_
if delta == 0.:
delta = 1.
lims.append([min_ - delta*0.02, max_ + delta*0.02])
k = 0
for i in range(ndim):
for j in range(ndim):
if i >= j:
continue # skip diagonal, upper triangle
plot_func = getattr(axes[k], plot_fn_name)
plot_func(x[i], x[j], **kwargs)
if labels is not None:
axes[k].set_xlabel(labels[i])
axes[k].set_ylabel(labels[j])
if autolim:
axes[k].set_xlim(lims[i])
axes[k].set_ylim(lims[j])
k += 1
axes[0].figure.tight_layout()
return axes[0].figure |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 29; 2, function_name:compute_coeffs; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 3, 27; 4, identifier:density_func; 5, identifier:nmax; 6, identifier:lmax; 7, identifier:M; 8, identifier:r_s; 9, default_parameter; 9, 10; 9, 11; 10, identifier:args; 11, tuple; 12, default_parameter; 12, 13; 12, 14; 13, identifier:skip_odd; 14, False; 15, default_parameter; 15, 16; 15, 17; 16, identifier:skip_even; 17, False; 18, default_parameter; 18, 19; 18, 20; 19, identifier:skip_m; 20, False; 21, default_parameter; 21, 22; 21, 23; 22, identifier:S_only; 23, False; 24, default_parameter; 24, 25; 24, 26; 25, identifier:progress; 26, False; 27, dictionary_splat_pattern; 27, 28; 28, identifier:nquad_opts; 29, block; 29, 30; 29, 32; 29, 38; 29, 51; 29, 55; 29, 59; 29, 68; 29, 75; 29, 93; 29, 111; 29, 129; 29, 147; 29, 155; 29, 163; 29, 184; 29, 185; 29, 189; 29, 236; 29, 277; 29, 361; 30, expression_statement; 30, 31; 31, comment; 32, import_from_statement; 32, 33; 32, 36; 33, dotted_name; 33, 34; 33, 35; 34, identifier:gala; 35, identifier:_cconfig; 36, dotted_name; 36, 37; 37, identifier:GSL_ENABLED; 38, if_statement; 38, 39; 38, 41; 39, not_operator; 39, 40; 40, identifier:GSL_ENABLED; 41, block; 41, 42; 42, raise_statement; 42, 43; 43, call; 43, 44; 43, 45; 44, identifier:ValueError; 45, argument_list; 45, 46; 46, concatenated_string; 46, 47; 46, 48; 46, 49; 46, 50; 47, string:"Gala was compiled without GSL and so this function "; 48, string:"will not work. See the gala documentation for more "; 49, string:"information about installing and using GSL with "; 50, string:"gala: http://gala.adrian.pw/en/latest/install.html"; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:lmin; 54, integer:0; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:lstride; 58, integer:1; 59, if_statement; 59, 60; 59, 63; 60, boolean_operator:or; 60, 61; 60, 62; 61, identifier:skip_odd; 62, identifier:skip_even; 63, block; 63, 64; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:lstride; 67, integer:2; 68, if_statement; 68, 69; 68, 70; 69, identifier:skip_even; 70, block; 70, 71; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:lmin; 74, integer:1; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:Snlm; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:np; 81, identifier:zeros; 82, argument_list; 82, 83; 83, tuple; 83, 84; 83, 87; 83, 90; 84, binary_operator:+; 84, 85; 84, 86; 85, identifier:nmax; 86, integer:1; 87, binary_operator:+; 87, 88; 87, 89; 88, identifier:lmax; 89, integer:1; 90, binary_operator:+; 90, 91; 90, 92; 91, identifier:lmax; 92, integer:1; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:Snlm_e; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:np; 99, identifier:zeros; 100, argument_list; 100, 101; 101, tuple; 101, 102; 101, 105; 101, 108; 102, binary_operator:+; 102, 103; 102, 104; 103, identifier:nmax; 104, integer:1; 105, binary_operator:+; 105, 106; 105, 107; 106, identifier:lmax; 107, integer:1; 108, binary_operator:+; 108, 109; 108, 110; 109, identifier:lmax; 110, integer:1; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:Tnlm; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:np; 117, identifier:zeros; 118, argument_list; 118, 119; 119, tuple; 119, 120; 119, 123; 119, 126; 120, binary_operator:+; 120, 121; 120, 122; 121, identifier:nmax; 122, integer:1; 123, binary_operator:+; 123, 124; 123, 125; 124, identifier:lmax; 125, integer:1; 126, binary_operator:+; 126, 127; 126, 128; 127, identifier:lmax; 128, integer:1; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:Tnlm_e; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:np; 135, identifier:zeros; 136, argument_list; 136, 137; 137, tuple; 137, 138; 137, 141; 137, 144; 138, binary_operator:+; 138, 139; 138, 140; 139, identifier:nmax; 140, integer:1; 141, binary_operator:+; 141, 142; 141, 143; 142, identifier:lmax; 143, integer:1; 144, binary_operator:+; 144, 145; 144, 146; 145, identifier:lmax; 146, integer:1; 147, expression_statement; 147, 148; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:nquad_opts; 151, identifier:setdefault; 152, argument_list; 152, 153; 152, 154; 153, string:'limit'; 154, integer:256; 155, expression_statement; 155, 156; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:nquad_opts; 159, identifier:setdefault; 160, argument_list; 160, 161; 160, 162; 161, string:'epsrel'; 162, float:1E-10; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:limits; 166, list:[[0, 2*np.pi], # phi
[-1, 1.], # X (cos(theta))
[-1, 1.]]; 166, 167; 166, 174; 166, 175; 166, 179; 166, 180; 167, list:[0, 2*np.pi]; 167, 168; 167, 169; 168, integer:0; 169, binary_operator:*; 169, 170; 169, 171; 170, integer:2; 171, attribute; 171, 172; 171, 173; 172, identifier:np; 173, identifier:pi; 174, comment; 175, list:[-1, 1.]; 175, 176; 175, 178; 176, unary_operator:-; 176, 177; 177, integer:1; 178, float:1.; 179, comment; 180, list:[-1, 1.]; 180, 181; 180, 183; 181, unary_operator:-; 181, 182; 182, integer:1; 183, float:1.; 184, comment; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:nlms; 188, list:[]; 189, for_statement; 189, 190; 189, 191; 189, 197; 190, identifier:n; 191, call; 191, 192; 191, 193; 192, identifier:range; 193, argument_list; 193, 194; 194, binary_operator:+; 194, 195; 194, 196; 195, identifier:nmax; 196, integer:1; 197, block; 197, 198; 198, for_statement; 198, 199; 198, 200; 198, 208; 199, identifier:l; 200, call; 200, 201; 200, 202; 201, identifier:range; 202, argument_list; 202, 203; 202, 204; 202, 207; 203, identifier:lmin; 204, binary_operator:+; 204, 205; 204, 206; 205, identifier:lmax; 206, integer:1; 207, identifier:lstride; 208, block; 208, 209; 209, for_statement; 209, 210; 209, 211; 209, 217; 210, identifier:m; 211, call; 211, 212; 211, 213; 212, identifier:range; 213, argument_list; 213, 214; 214, binary_operator:+; 214, 215; 214, 216; 215, identifier:l; 216, integer:1; 217, block; 217, 218; 217, 226; 218, if_statement; 218, 219; 218, 224; 219, boolean_operator:and; 219, 220; 219, 221; 220, identifier:skip_m; 221, comparison_operator:>; 221, 222; 221, 223; 222, identifier:m; 223, integer:0; 224, block; 224, 225; 225, continue_statement; 226, expression_statement; 226, 227; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:nlms; 230, identifier:append; 231, argument_list; 231, 232; 232, tuple; 232, 233; 232, 234; 232, 235; 233, identifier:n; 234, identifier:l; 235, identifier:m; 236, if_statement; 236, 237; 236, 238; 236, 268; 237, identifier:progress; 238, block; 238, 239; 238, 264; 239, try_statement; 239, 240; 239, 246; 240, block; 240, 241; 241, import_from_statement; 241, 242; 241, 244; 242, dotted_name; 242, 243; 243, identifier:tqdm; 244, dotted_name; 244, 245; 245, identifier:tqdm; 246, except_clause; 246, 247; 246, 251; 247, as_pattern; 247, 248; 247, 249; 248, identifier:ImportError; 249, as_pattern_target; 249, 250; 250, identifier:e; 251, block; 251, 252; 252, raise_statement; 252, 253; 253, call; 253, 254; 253, 255; 254, identifier:ImportError; 255, argument_list; 255, 256; 256, binary_operator:+; 256, 257; 256, 260; 257, concatenated_string; 257, 258; 257, 259; 258, string:'tqdm is not installed - you can install it '; 259, string:'with `pip install tqdm`.\n'; 260, call; 260, 261; 260, 262; 261, identifier:str; 262, argument_list; 262, 263; 263, identifier:e; 264, expression_statement; 264, 265; 265, assignment; 265, 266; 265, 267; 266, identifier:iterfunc; 267, identifier:tqdm; 268, else_clause; 268, 269; 269, block; 269, 270; 270, expression_statement; 270, 271; 271, assignment; 271, 272; 271, 273; 272, identifier:iterfunc; 273, lambda; 273, 274; 273, 276; 274, lambda_parameters; 274, 275; 275, identifier:x; 276, identifier:x; 277, for_statement; 277, 278; 277, 282; 277, 286; 278, pattern_list; 278, 279; 278, 280; 278, 281; 279, identifier:n; 280, identifier:l; 281, identifier:m; 282, call; 282, 283; 282, 284; 283, identifier:iterfunc; 284, argument_list; 284, 285; 285, identifier:nlms; 286, block; 286, 287; 286, 322; 287, expression_statement; 287, 288; 288, assignment; 288, 289; 288, 300; 289, pattern_list; 289, 290; 289, 295; 290, subscript; 290, 291; 290, 292; 290, 293; 290, 294; 291, identifier:Snlm; 292, identifier:n; 293, identifier:l; 294, identifier:m; 295, subscript; 295, 296; 295, 297; 295, 298; 295, 299; 296, identifier:Snlm_e; 297, identifier:n; 298, identifier:l; 299, identifier:m; 300, call; 300, 301; 300, 304; 301, attribute; 301, 302; 301, 303; 302, identifier:si; 303, identifier:nquad; 304, argument_list; 304, 305; 304, 306; 304, 309; 304, 319; 305, identifier:Snlm_integrand; 306, keyword_argument; 306, 307; 306, 308; 307, identifier:ranges; 308, identifier:limits; 309, keyword_argument; 309, 310; 309, 311; 310, identifier:args; 311, tuple; 311, 312; 311, 313; 311, 314; 311, 315; 311, 316; 311, 317; 311, 318; 312, identifier:density_func; 313, identifier:n; 314, identifier:l; 315, identifier:m; 316, identifier:M; 317, identifier:r_s; 318, identifier:args; 319, keyword_argument; 319, 320; 319, 321; 320, identifier:opts; 321, identifier:nquad_opts; 322, if_statement; 322, 323; 322, 325; 323, not_operator; 323, 324; 324, identifier:S_only; 325, block; 325, 326; 326, expression_statement; 326, 327; 327, assignment; 327, 328; 327, 339; 328, pattern_list; 328, 329; 328, 334; 329, subscript; 329, 330; 329, 331; 329, 332; 329, 333; 330, identifier:Tnlm; 331, identifier:n; 332, identifier:l; 333, identifier:m; 334, subscript; 334, 335; 334, 336; 334, 337; 334, 338; 335, identifier:Tnlm_e; 336, identifier:n; 337, identifier:l; 338, identifier:m; 339, call; 339, 340; 339, 343; 340, attribute; 340, 341; 340, 342; 341, identifier:si; 342, identifier:nquad; 343, argument_list; 343, 344; 343, 345; 343, 348; 343, 358; 344, identifier:Tnlm_integrand; 345, keyword_argument; 345, 346; 345, 347; 346, identifier:ranges; 347, identifier:limits; 348, keyword_argument; 348, 349; 348, 350; 349, identifier:args; 350, tuple; 350, 351; 350, 352; 350, 353; 350, 354; 350, 355; 350, 356; 350, 357; 351, identifier:density_func; 352, identifier:n; 353, identifier:l; 354, identifier:m; 355, identifier:M; 356, identifier:r_s; 357, identifier:args; 358, keyword_argument; 358, 359; 358, 360; 359, identifier:opts; 360, identifier:nquad_opts; 361, return_statement; 361, 362; 362, expression_list; 362, 363; 362, 366; 363, tuple; 363, 364; 363, 365; 364, identifier:Snlm; 365, identifier:Snlm_e; 366, tuple; 366, 367; 366, 368; 367, identifier:Tnlm; 368, identifier:Tnlm_e | def compute_coeffs(density_func, nmax, lmax, M, r_s, args=(),
skip_odd=False, skip_even=False, skip_m=False,
S_only=False, progress=False, **nquad_opts):
"""
Compute the expansion coefficients for representing the input density function using a basis
function expansion.
Computing the coefficients involves computing triple integrals which are computationally
expensive. For an example of how to parallelize the computation of the coefficients, see
``examples/parallel_compute_Anlm.py``.
Parameters
----------
density_func : function, callable
A function or callable object that evaluates the density at a given position. The call
format must be of the form: ``density_func(x, y, z, M, r_s, args)`` where ``x,y,z`` are
cartesian coordinates, ``M`` is a scale mass, ``r_s`` a scale radius, and ``args`` is an
iterable containing any other arguments needed by the density function.
nmax : int
Maximum value of ``n`` for the radial expansion.
lmax : int
Maximum value of ``l`` for the spherical harmonics.
M : numeric
Scale mass.
r_s : numeric
Scale radius.
args : iterable (optional)
A list or iterable of any other arguments needed by the density
function.
skip_odd : bool (optional)
Skip the odd terms in the angular portion of the expansion. For example, only
take :math:`l=0,2,4,...`
skip_even : bool (optional)
Skip the even terms in the angular portion of the expansion. For example, only
take :math:`l=1,3,5,...`
skip_m : bool (optional)
Ignore terms with :math:`m > 0`.
S_only : bool (optional)
Only compute the S coefficients.
progress : bool (optional)
If ``tqdm`` is installed, display a progress bar.
**nquad_opts
Any additional keyword arguments are passed through to
`~scipy.integrate.nquad` as options, `opts`.
Returns
-------
Snlm : float, `~numpy.ndarray`
The value of the cosine expansion coefficient.
Snlm_err : , `~numpy.ndarray`
An estimate of the uncertainty in the coefficient value (from `~scipy.integrate.nquad`).
Tnlm : , `~numpy.ndarray`
The value of the sine expansion coefficient.
Tnlm_err : , `~numpy.ndarray`
An estimate of the uncertainty in the coefficient value. (from `~scipy.integrate.nquad`).
"""
from gala._cconfig import GSL_ENABLED
if not GSL_ENABLED:
raise ValueError("Gala was compiled without GSL and so this function "
"will not work. See the gala documentation for more "
"information about installing and using GSL with "
"gala: http://gala.adrian.pw/en/latest/install.html")
lmin = 0
lstride = 1
if skip_odd or skip_even:
lstride = 2
if skip_even:
lmin = 1
Snlm = np.zeros((nmax+1, lmax+1, lmax+1))
Snlm_e = np.zeros((nmax+1, lmax+1, lmax+1))
Tnlm = np.zeros((nmax+1, lmax+1, lmax+1))
Tnlm_e = np.zeros((nmax+1, lmax+1, lmax+1))
nquad_opts.setdefault('limit', 256)
nquad_opts.setdefault('epsrel', 1E-10)
limits = [[0, 2*np.pi], # phi
[-1, 1.], # X (cos(theta))
[-1, 1.]] # xsi
nlms = []
for n in range(nmax+1):
for l in range(lmin, lmax+1, lstride):
for m in range(l+1):
if skip_m and m > 0:
continue
nlms.append((n, l, m))
if progress:
try:
from tqdm import tqdm
except ImportError as e:
raise ImportError('tqdm is not installed - you can install it '
'with `pip install tqdm`.\n' + str(e))
iterfunc = tqdm
else:
iterfunc = lambda x: x
for n, l, m in iterfunc(nlms):
Snlm[n, l, m], Snlm_e[n, l, m] = si.nquad(
Snlm_integrand, ranges=limits,
args=(density_func, n, l, m, M, r_s, args),
opts=nquad_opts)
if not S_only:
Tnlm[n, l, m], Tnlm_e[n, l, m] = si.nquad(
Tnlm_integrand, ranges=limits,
args=(density_func, n, l, m, M, r_s, args),
opts=nquad_opts)
return (Snlm, Snlm_e), (Tnlm, Tnlm_e) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 21; 2, function_name:compute_coeffs_discrete; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 12; 3, 15; 3, 18; 4, identifier:xyz; 5, identifier:mass; 6, identifier:nmax; 7, identifier:lmax; 8, identifier:r_s; 9, default_parameter; 9, 10; 9, 11; 10, identifier:skip_odd; 11, False; 12, default_parameter; 12, 13; 12, 14; 13, identifier:skip_even; 14, False; 15, default_parameter; 15, 16; 15, 17; 16, identifier:skip_m; 17, False; 18, default_parameter; 18, 19; 18, 20; 19, identifier:compute_var; 20, False; 21, block; 21, 22; 21, 24; 21, 28; 21, 32; 21, 41; 21, 48; 21, 66; 21, 84; 21, 123; 21, 124; 21, 138; 21, 152; 21, 172; 21, 178; 21, 196; 21, 206; 21, 293; 22, expression_statement; 22, 23; 23, comment; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:lmin; 27, integer:0; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:lstride; 31, integer:1; 32, if_statement; 32, 33; 32, 36; 33, boolean_operator:or; 33, 34; 33, 35; 34, identifier:skip_odd; 35, identifier:skip_even; 36, block; 36, 37; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:lstride; 40, integer:2; 41, if_statement; 41, 42; 41, 43; 42, identifier:skip_even; 43, block; 43, 44; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:lmin; 47, integer:1; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:Snlm; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:np; 54, identifier:zeros; 55, argument_list; 55, 56; 56, tuple; 56, 57; 56, 60; 56, 63; 57, binary_operator:+; 57, 58; 57, 59; 58, identifier:nmax; 59, integer:1; 60, binary_operator:+; 60, 61; 60, 62; 61, identifier:lmax; 62, integer:1; 63, binary_operator:+; 63, 64; 63, 65; 64, identifier:lmax; 65, integer:1; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:Tnlm; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:np; 72, identifier:zeros; 73, argument_list; 73, 74; 74, tuple; 74, 75; 74, 78; 74, 81; 75, binary_operator:+; 75, 76; 75, 77; 76, identifier:nmax; 77, integer:1; 78, binary_operator:+; 78, 79; 78, 80; 79, identifier:lmax; 80, integer:1; 81, binary_operator:+; 81, 82; 81, 83; 82, identifier:lmax; 83, integer:1; 84, if_statement; 84, 85; 84, 86; 85, identifier:compute_var; 86, block; 86, 87; 86, 105; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:Snlm_var; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:np; 93, identifier:zeros; 94, argument_list; 94, 95; 95, tuple; 95, 96; 95, 99; 95, 102; 96, binary_operator:+; 96, 97; 96, 98; 97, identifier:nmax; 98, integer:1; 99, binary_operator:+; 99, 100; 99, 101; 100, identifier:lmax; 101, integer:1; 102, binary_operator:+; 102, 103; 102, 104; 103, identifier:lmax; 104, integer:1; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:Tnlm_var; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:np; 111, identifier:zeros; 112, argument_list; 112, 113; 113, tuple; 113, 114; 113, 117; 113, 120; 114, binary_operator:+; 114, 115; 114, 116; 115, identifier:nmax; 116, integer:1; 117, binary_operator:+; 117, 118; 117, 119; 118, identifier:lmax; 119, integer:1; 120, binary_operator:+; 120, 121; 120, 122; 121, identifier:lmax; 122, integer:1; 123, comment; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:xyz; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:np; 130, identifier:ascontiguousarray; 131, argument_list; 131, 132; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:np; 135, identifier:atleast_2d; 136, argument_list; 136, 137; 137, identifier:xyz; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:mass; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:np; 144, identifier:ascontiguousarray; 145, argument_list; 145, 146; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:np; 149, identifier:atleast_1d; 150, argument_list; 150, 151; 151, identifier:mass; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:r; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:np; 158, identifier:sqrt; 159, argument_list; 159, 160; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:np; 163, identifier:sum; 164, argument_list; 164, 165; 164, 168; 165, binary_operator:**; 165, 166; 165, 167; 166, identifier:xyz; 167, integer:2; 168, keyword_argument; 168, 169; 168, 170; 169, identifier:axis; 170, unary_operator:-; 170, 171; 171, integer:1; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:s; 175, binary_operator:/; 175, 176; 175, 177; 176, identifier:r; 177, identifier:r_s; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:phi; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:np; 184, identifier:arctan2; 185, argument_list; 185, 186; 185, 191; 186, subscript; 186, 187; 186, 188; 186, 190; 187, identifier:xyz; 188, slice; 188, 189; 189, colon; 190, integer:1; 191, subscript; 191, 192; 191, 193; 191, 195; 192, identifier:xyz; 193, slice; 193, 194; 194, colon; 195, integer:0; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 199; 198, identifier:X; 199, binary_operator:/; 199, 200; 199, 205; 200, subscript; 200, 201; 200, 202; 200, 204; 201, identifier:xyz; 202, slice; 202, 203; 203, colon; 204, integer:2; 205, identifier:r; 206, for_statement; 206, 207; 206, 208; 206, 214; 207, identifier:n; 208, call; 208, 209; 208, 210; 209, identifier:range; 210, argument_list; 210, 211; 211, binary_operator:+; 211, 212; 211, 213; 212, identifier:nmax; 213, integer:1; 214, block; 214, 215; 215, for_statement; 215, 216; 215, 217; 215, 225; 216, identifier:l; 217, call; 217, 218; 217, 219; 218, identifier:range; 219, argument_list; 219, 220; 219, 221; 219, 224; 220, identifier:lmin; 221, binary_operator:+; 221, 222; 221, 223; 222, identifier:lmax; 223, integer:1; 224, identifier:lstride; 225, block; 225, 226; 226, for_statement; 226, 227; 226, 228; 226, 234; 227, identifier:m; 228, call; 228, 229; 228, 230; 229, identifier:range; 230, argument_list; 230, 231; 231, binary_operator:+; 231, 232; 231, 233; 232, identifier:l; 233, integer:1; 234, block; 234, 235; 234, 243; 234, 244; 234, 267; 235, if_statement; 235, 236; 235, 241; 236, boolean_operator:and; 236, 237; 236, 238; 237, identifier:skip_m; 238, comparison_operator:>; 238, 239; 238, 240; 239, identifier:m; 240, integer:0; 241, block; 241, 242; 242, continue_statement; 243, comment; 244, expression_statement; 244, 245; 245, assignment; 245, 246; 245, 257; 246, pattern_list; 246, 247; 246, 252; 247, subscript; 247, 248; 247, 249; 247, 250; 247, 251; 248, identifier:Snlm; 249, identifier:n; 250, identifier:l; 251, identifier:m; 252, subscript; 252, 253; 252, 254; 252, 255; 252, 256; 253, identifier:Tnlm; 254, identifier:n; 255, identifier:l; 256, identifier:m; 257, call; 257, 258; 257, 259; 258, identifier:STnlm_discrete; 259, argument_list; 259, 260; 259, 261; 259, 262; 259, 263; 259, 264; 259, 265; 259, 266; 260, identifier:s; 261, identifier:phi; 262, identifier:X; 263, identifier:mass; 264, identifier:n; 265, identifier:l; 266, identifier:m; 267, if_statement; 267, 268; 267, 269; 268, identifier:compute_var; 269, block; 269, 270; 270, expression_statement; 270, 271; 271, assignment; 271, 272; 271, 283; 272, pattern_list; 272, 273; 272, 278; 273, subscript; 273, 274; 273, 275; 273, 276; 273, 277; 274, identifier:Snlm_var; 275, identifier:n; 276, identifier:l; 277, identifier:m; 278, subscript; 278, 279; 278, 280; 278, 281; 278, 282; 279, identifier:Tnlm_var; 280, identifier:n; 281, identifier:l; 282, identifier:m; 283, call; 283, 284; 283, 285; 284, identifier:STnlm_var_discrete; 285, argument_list; 285, 286; 285, 287; 285, 288; 285, 289; 285, 290; 285, 291; 285, 292; 286, identifier:s; 287, identifier:phi; 288, identifier:X; 289, identifier:mass; 290, identifier:n; 291, identifier:l; 292, identifier:m; 293, if_statement; 293, 294; 293, 295; 293, 304; 294, identifier:compute_var; 295, block; 295, 296; 296, return_statement; 296, 297; 297, expression_list; 297, 298; 297, 301; 298, tuple; 298, 299; 298, 300; 299, identifier:Snlm; 300, identifier:Snlm_var; 301, tuple; 301, 302; 301, 303; 302, identifier:Tnlm; 303, identifier:Tnlm_var; 304, else_clause; 304, 305; 305, block; 305, 306; 306, return_statement; 306, 307; 307, expression_list; 307, 308; 307, 309; 308, identifier:Snlm; 309, identifier:Tnlm | def compute_coeffs_discrete(xyz, mass, nmax, lmax, r_s,
skip_odd=False, skip_even=False, skip_m=False,
compute_var=False):
"""
Compute the expansion coefficients for representing the density distribution of input points
as a basis function expansion. The points, ``xyz``, are assumed to be samples from the
density distribution.
Computing the coefficients involves computing triple integrals which are computationally
expensive. For an example of how to parallelize the computation of the coefficients, see
``examples/parallel_compute_Anlm.py``.
Parameters
----------
xyz : array_like
Samples from the density distribution. Should have shape ``(n_samples,3)``.
mass : array_like
Mass of each sample. Should have shape ``(n_samples,)``.
nmax : int
Maximum value of ``n`` for the radial expansion.
lmax : int
Maximum value of ``l`` for the spherical harmonics.
r_s : numeric
Scale radius.
skip_odd : bool (optional)
Skip the odd terms in the angular portion of the expansion. For example, only
take :math:`l=0,2,4,...`
skip_even : bool (optional)
Skip the even terms in the angular portion of the expansion. For example, only
take :math:`l=1,3,5,...`
skip_m : bool (optional)
Ignore terms with :math:`m > 0`.
compute_var : bool (optional)
Also compute the variances of the coefficients. This does not compute the full covariance
matrix of the coefficients, just the individual variances.
TODO: separate function to compute full covariance matrix?
Returns
-------
Snlm : float
The value of the cosine expansion coefficient.
Tnlm : float
The value of the sine expansion coefficient.
"""
lmin = 0
lstride = 1
if skip_odd or skip_even:
lstride = 2
if skip_even:
lmin = 1
Snlm = np.zeros((nmax+1, lmax+1, lmax+1))
Tnlm = np.zeros((nmax+1, lmax+1, lmax+1))
if compute_var:
Snlm_var = np.zeros((nmax+1, lmax+1, lmax+1))
Tnlm_var = np.zeros((nmax+1, lmax+1, lmax+1))
# positions and masses of point masses
xyz = np.ascontiguousarray(np.atleast_2d(xyz))
mass = np.ascontiguousarray(np.atleast_1d(mass))
r = np.sqrt(np.sum(xyz**2, axis=-1))
s = r / r_s
phi = np.arctan2(xyz[:,1], xyz[:,0])
X = xyz[:,2] / r
for n in range(nmax+1):
for l in range(lmin, lmax+1, lstride):
for m in range(l+1):
if skip_m and m > 0: continue
# logger.debug("Computing coefficients (n,l,m)=({},{},{})".format(n,l,m))
Snlm[n,l,m], Tnlm[n,l,m] = STnlm_discrete(s, phi, X, mass, n, l, m)
if compute_var:
Snlm_var[n,l,m], Tnlm_var[n,l,m] = STnlm_var_discrete(s, phi, X, mass, n, l, m)
if compute_var:
return (Snlm,Snlm_var), (Tnlm,Tnlm_var)
else:
return Snlm, Tnlm |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:to_coord_frame; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:self; 5, identifier:frame; 6, default_parameter; 6, 7; 6, 8; 7, identifier:galactocentric_frame; 8, None; 9, dictionary_splat_pattern; 9, 10; 10, identifier:kwargs; 11, block; 11, 12; 11, 14; 11, 28; 11, 41; 11, 64; 11, 77; 11, 90; 11, 130; 11, 131; 11, 149; 11, 158; 12, expression_statement; 12, 13; 13, comment; 14, if_statement; 14, 15; 14, 20; 15, comparison_operator:!=; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:ndim; 19, integer:3; 20, block; 20, 21; 21, raise_statement; 21, 22; 22, call; 22, 23; 22, 24; 23, identifier:ValueError; 24, argument_list; 24, 25; 25, concatenated_string; 25, 26; 25, 27; 26, string:"Can only change representation for "; 27, string:"ndim=3 instances."; 28, if_statement; 28, 29; 28, 32; 29, comparison_operator:is; 29, 30; 29, 31; 30, identifier:galactocentric_frame; 31, None; 32, block; 32, 33; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:galactocentric_frame; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:coord; 39, identifier:Galactocentric; 40, argument_list; 41, if_statement; 41, 42; 41, 49; 42, boolean_operator:or; 42, 43; 42, 46; 43, comparison_operator:in; 43, 44; 43, 45; 44, string:'vcirc'; 45, identifier:kwargs; 46, comparison_operator:in; 46, 47; 46, 48; 47, string:'vlsr'; 48, identifier:kwargs; 49, block; 49, 50; 49, 53; 50, import_statement; 50, 51; 51, dotted_name; 51, 52; 52, identifier:warnings; 53, expression_statement; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:warnings; 57, identifier:warn; 58, argument_list; 58, 59; 58, 63; 59, concatenated_string; 59, 60; 59, 61; 59, 62; 60, string:"Instead of passing in 'vcirc' and 'vlsr', specify "; 61, string:"these parameters to the input Galactocentric frame "; 62, string:"using the `galcen_v_sun` argument."; 63, identifier:DeprecationWarning; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:pos_keys; 67, call; 67, 68; 67, 69; 68, identifier:list; 69, argument_list; 69, 70; 70, call; 70, 71; 70, 76; 71, attribute; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:self; 74, identifier:pos_components; 75, identifier:keys; 76, argument_list; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:vel_keys; 80, call; 80, 81; 80, 82; 81, identifier:list; 82, argument_list; 82, 83; 83, call; 83, 84; 83, 89; 84, attribute; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:self; 87, identifier:vel_components; 88, identifier:keys; 89, argument_list; 90, if_statement; 90, 91; 90, 119; 91, parenthesized_expression; 91, 92; 92, boolean_operator:or; 92, 93; 92, 106; 93, comparison_operator:==; 93, 94; 93, 103; 94, attribute; 94, 95; 94, 102; 95, call; 95, 96; 95, 97; 96, identifier:getattr; 97, argument_list; 97, 98; 97, 99; 98, identifier:self; 99, subscript; 99, 100; 99, 101; 100, identifier:pos_keys; 101, integer:0; 102, identifier:unit; 103, attribute; 103, 104; 103, 105; 104, identifier:u; 105, identifier:one; 106, comparison_operator:==; 106, 107; 106, 116; 107, attribute; 107, 108; 107, 115; 108, call; 108, 109; 108, 110; 109, identifier:getattr; 110, argument_list; 110, 111; 110, 112; 111, identifier:self; 112, subscript; 112, 113; 112, 114; 113, identifier:vel_keys; 114, integer:0; 115, identifier:unit; 116, attribute; 116, 117; 116, 118; 117, identifier:u; 118, identifier:one; 119, block; 119, 120; 120, raise_statement; 120, 121; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:u; 124, identifier:UnitConversionError; 125, argument_list; 125, 126; 126, concatenated_string; 126, 127; 126, 128; 126, 129; 127, string:"Position and velocity must have "; 128, string:"dimensioned units to convert to a "; 129, string:"coordinate frame."; 130, comment; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:gc_c; 134, call; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:galactocentric_frame; 137, identifier:realize_frame; 138, argument_list; 138, 139; 139, call; 139, 140; 139, 145; 140, attribute; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:self; 143, identifier:pos; 144, identifier:with_differentials; 145, argument_list; 145, 146; 146, attribute; 146, 147; 146, 148; 147, identifier:self; 148, identifier:vel; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 152; 151, identifier:c; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:gc_c; 155, identifier:transform_to; 156, argument_list; 156, 157; 157, identifier:frame; 158, return_statement; 158, 159; 159, identifier:c | def to_coord_frame(self, frame, galactocentric_frame=None, **kwargs):
"""
Transform the orbit from Galactocentric, cartesian coordinates to
Heliocentric coordinates in the specified Astropy coordinate frame.
Parameters
----------
frame : :class:`~astropy.coordinates.BaseCoordinateFrame`
The class or frame instance specifying the desired output frame.
For example, :class:`~astropy.coordinates.ICRS`.
galactocentric_frame : :class:`~astropy.coordinates.Galactocentric`
This is the assumed frame that the position and velocity of this
object are in. The ``Galactocentric`` instand should have parameters
specifying the position and motion of the sun in the Galactocentric
frame, but no data.
Returns
-------
c : :class:`~astropy.coordinates.BaseCoordinateFrame`
An instantiated coordinate frame containing the positions and
velocities from this object transformed to the specified coordinate
frame.
"""
if self.ndim != 3:
raise ValueError("Can only change representation for "
"ndim=3 instances.")
if galactocentric_frame is None:
galactocentric_frame = coord.Galactocentric()
if 'vcirc' in kwargs or 'vlsr' in kwargs:
import warnings
warnings.warn("Instead of passing in 'vcirc' and 'vlsr', specify "
"these parameters to the input Galactocentric frame "
"using the `galcen_v_sun` argument.",
DeprecationWarning)
pos_keys = list(self.pos_components.keys())
vel_keys = list(self.vel_components.keys())
if (getattr(self, pos_keys[0]).unit == u.one or
getattr(self, vel_keys[0]).unit == u.one):
raise u.UnitConversionError("Position and velocity must have "
"dimensioned units to convert to a "
"coordinate frame.")
# first we need to turn the position into a Galactocentric instance
gc_c = galactocentric_frame.realize_frame(
self.pos.with_differentials(self.vel))
c = gc_c.transform_to(frame)
return c |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_plot_prepare; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:components; 6, identifier:units; 7, block; 7, 8; 7, 10; 7, 11; 7, 24; 7, 31; 7, 32; 7, 69; 7, 73; 7, 77; 7, 235; 8, expression_statement; 8, 9; 9, comment; 10, comment; 11, if_statement; 11, 12; 11, 15; 12, comparison_operator:is; 12, 13; 12, 14; 13, identifier:components; 14, None; 15, block; 15, 16; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:components; 19, attribute; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:pos; 23, identifier:components; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 27; 26, identifier:n_comps; 27, call; 27, 28; 27, 29; 28, identifier:len; 29, argument_list; 29, 30; 30, identifier:components; 31, comment; 32, if_statement; 32, 33; 32, 36; 33, comparison_operator:is; 33, 34; 33, 35; 34, identifier:units; 35, None; 36, block; 36, 37; 37, if_statement; 37, 38; 37, 45; 37, 54; 38, call; 38, 39; 38, 40; 39, identifier:isinstance; 40, argument_list; 40, 41; 40, 42; 41, identifier:units; 42, attribute; 42, 43; 42, 44; 43, identifier:u; 44, identifier:UnitBase; 45, block; 45, 46; 45, 53; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:units; 49, binary_operator:*; 49, 50; 49, 52; 50, list:[units]; 50, 51; 51, identifier:units; 52, identifier:n_comps; 53, comment; 54, elif_clause; 54, 55; 54, 61; 55, comparison_operator:!=; 55, 56; 55, 60; 56, call; 56, 57; 56, 58; 57, identifier:len; 58, argument_list; 58, 59; 59, identifier:units; 60, identifier:n_comps; 61, block; 61, 62; 62, raise_statement; 62, 63; 63, call; 63, 64; 63, 65; 64, identifier:ValueError; 65, argument_list; 65, 66; 66, concatenated_string; 66, 67; 66, 68; 67, string:'You must specify a unit for each axis, or a '; 68, string:'single unit for all axes.'; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:labels; 72, list:[]; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:x; 76, list:[]; 77, for_statement; 77, 78; 77, 81; 77, 85; 78, pattern_list; 78, 79; 78, 80; 79, identifier:i; 80, identifier:name; 81, call; 81, 82; 81, 83; 82, identifier:enumerate; 83, argument_list; 83, 84; 84, identifier:components; 85, block; 85, 86; 85, 94; 85, 124; 85, 159; 85, 160; 85, 186; 85, 200; 85, 212; 85, 226; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:val; 89, call; 89, 90; 89, 91; 90, identifier:getattr; 91, argument_list; 91, 92; 91, 93; 92, identifier:self; 93, identifier:name; 94, if_statement; 94, 95; 94, 98; 94, 116; 95, comparison_operator:is; 95, 96; 95, 97; 96, identifier:units; 97, None; 98, block; 98, 99; 98, 110; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:val; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:val; 105, identifier:to; 106, argument_list; 106, 107; 107, subscript; 107, 108; 107, 109; 108, identifier:units; 109, identifier:i; 110, expression_statement; 110, 111; 111, assignment; 111, 112; 111, 113; 112, identifier:unit; 113, subscript; 113, 114; 113, 115; 114, identifier:units; 115, identifier:i; 116, else_clause; 116, 117; 117, block; 117, 118; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:unit; 121, attribute; 121, 122; 121, 123; 122, identifier:val; 123, identifier:unit; 124, if_statement; 124, 125; 124, 132; 124, 153; 125, comparison_operator:!=; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:val; 128, identifier:unit; 129, attribute; 129, 130; 129, 131; 130, identifier:u; 131, identifier:one; 132, block; 132, 133; 132, 144; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:uu; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:unit; 139, identifier:to_string; 140, argument_list; 140, 141; 141, keyword_argument; 141, 142; 141, 143; 142, identifier:format; 143, string:'latex_inline'; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:unit_str; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, string:' [{}]'; 150, identifier:format; 151, argument_list; 151, 152; 152, identifier:uu; 153, else_clause; 153, 154; 154, block; 154, 155; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:unit_str; 158, string:''; 159, comment; 160, if_statement; 160, 161; 160, 167; 160, 180; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:name; 164, identifier:startswith; 165, argument_list; 165, 166; 166, string:'d_'; 167, block; 167, 168; 167, 172; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:dot; 171, True; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:name; 175, subscript; 175, 176; 175, 177; 176, identifier:name; 177, slice; 177, 178; 177, 179; 178, integer:2; 179, colon; 180, else_clause; 180, 181; 181, block; 181, 182; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 185; 184, identifier:dot; 185, False; 186, if_statement; 186, 187; 186, 190; 187, comparison_operator:in; 187, 188; 187, 189; 188, identifier:name; 189, identifier:_greek_letters; 190, block; 190, 191; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:name; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, string:r"\{}"; 197, identifier:format; 198, argument_list; 198, 199; 199, identifier:name; 200, if_statement; 200, 201; 200, 202; 201, identifier:dot; 202, block; 202, 203; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 206; 205, identifier:name; 206, call; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, string:"\dot{{{}}}"; 209, identifier:format; 210, argument_list; 210, 211; 211, identifier:name; 212, expression_statement; 212, 213; 213, call; 213, 214; 213, 217; 214, attribute; 214, 215; 214, 216; 215, identifier:labels; 216, identifier:append; 217, argument_list; 217, 218; 218, binary_operator:+; 218, 219; 218, 225; 219, call; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, string:'${}$'; 222, identifier:format; 223, argument_list; 223, 224; 224, identifier:name; 225, identifier:unit_str; 226, expression_statement; 226, 227; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, identifier:x; 230, identifier:append; 231, argument_list; 231, 232; 232, attribute; 232, 233; 232, 234; 233, identifier:val; 234, identifier:value; 235, return_statement; 235, 236; 236, expression_list; 236, 237; 236, 238; 237, identifier:x; 238, identifier:labels | def _plot_prepare(self, components, units):
"""
Prepare the ``PhaseSpacePosition`` or subclass for passing to a plotting
routine to plot all projections of the object.
"""
# components to plot
if components is None:
components = self.pos.components
n_comps = len(components)
# if units not specified, get units from the components
if units is not None:
if isinstance(units, u.UnitBase):
units = [units]*n_comps # global unit
elif len(units) != n_comps:
raise ValueError('You must specify a unit for each axis, or a '
'single unit for all axes.')
labels = []
x = []
for i,name in enumerate(components):
val = getattr(self, name)
if units is not None:
val = val.to(units[i])
unit = units[i]
else:
unit = val.unit
if val.unit != u.one:
uu = unit.to_string(format='latex_inline')
unit_str = ' [{}]'.format(uu)
else:
unit_str = ''
# Figure out how to fancy display the component name
if name.startswith('d_'):
dot = True
name = name[2:]
else:
dot = False
if name in _greek_letters:
name = r"\{}".format(name)
if dot:
name = "\dot{{{}}}".format(name)
labels.append('${}$'.format(name) + unit_str)
x.append(val.value)
return x, labels |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:recommend; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:client_data; 6, identifier:limit; 7, default_parameter; 7, 8; 7, 9; 8, identifier:extra_data; 9, dictionary; 10, block; 10, 11; 10, 13; 10, 23; 10, 24; 10, 25; 10, 34; 10, 47; 10, 60; 10, 61; 10, 62; 10, 63; 10, 64; 10, 70; 10, 175; 10, 203; 10, 224; 10, 241; 10, 252; 11, expression_statement; 11, 12; 12, comment; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:preinstalled_addon_ids; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:client_data; 19, identifier:get; 20, argument_list; 20, 21; 20, 22; 21, string:"installed_addons"; 22, list:[]; 23, comment; 24, comment; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:extended_limit; 28, binary_operator:+; 28, 29; 28, 30; 29, identifier:limit; 30, call; 30, 31; 30, 32; 31, identifier:len; 32, argument_list; 32, 33; 33, identifier:preinstalled_addon_ids; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:ensemble_suggestions; 37, call; 37, 38; 37, 43; 38, attribute; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:_ensemble_recommender; 42, identifier:recommend; 43, argument_list; 43, 44; 43, 45; 43, 46; 44, identifier:client_data; 45, identifier:extended_limit; 46, identifier:extra_data; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:curated_suggestions; 50, call; 50, 51; 50, 56; 51, attribute; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:self; 54, identifier:_curated_recommender; 55, identifier:recommend; 56, argument_list; 56, 57; 56, 58; 56, 59; 57, identifier:client_data; 58, identifier:extended_limit; 59, identifier:extra_data; 60, comment; 61, comment; 62, comment; 63, comment; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:merged_results; 67, call; 67, 68; 67, 69; 68, identifier:set; 69, argument_list; 70, while_statement; 70, 71; 70, 92; 71, parenthesized_expression; 71, 72; 72, boolean_operator:and; 72, 73; 72, 86; 73, boolean_operator:and; 73, 74; 73, 80; 74, comparison_operator:<; 74, 75; 74, 79; 75, call; 75, 76; 75, 77; 76, identifier:len; 77, argument_list; 77, 78; 78, identifier:merged_results; 79, identifier:limit; 80, comparison_operator:>; 80, 81; 80, 85; 81, call; 81, 82; 81, 83; 82, identifier:len; 83, argument_list; 83, 84; 84, identifier:ensemble_suggestions; 85, integer:0; 86, comparison_operator:>; 86, 87; 86, 91; 87, call; 87, 88; 87, 89; 88, identifier:len; 89, argument_list; 89, 90; 90, identifier:curated_suggestions; 91, integer:0; 92, block; 92, 93; 92, 101; 92, 121; 92, 122; 92, 147; 92, 155; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:r1; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:ensemble_suggestions; 99, identifier:pop; 100, argument_list; 101, if_statement; 101, 102; 101, 113; 102, comparison_operator:not; 102, 103; 102, 106; 103, subscript; 103, 104; 103, 105; 104, identifier:r1; 105, integer:0; 106, list_comprehension; 106, 107; 106, 110; 107, subscript; 107, 108; 107, 109; 108, identifier:temp; 109, integer:0; 110, for_in_clause; 110, 111; 110, 112; 111, identifier:temp; 112, identifier:merged_results; 113, block; 113, 114; 114, expression_statement; 114, 115; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:merged_results; 118, identifier:add; 119, argument_list; 119, 120; 120, identifier:r1; 121, comment; 122, if_statement; 122, 123; 122, 145; 123, not_operator; 123, 124; 124, parenthesized_expression; 124, 125; 125, boolean_operator:and; 125, 126; 125, 139; 126, boolean_operator:and; 126, 127; 126, 133; 127, comparison_operator:<; 127, 128; 127, 132; 128, call; 128, 129; 128, 130; 129, identifier:len; 130, argument_list; 130, 131; 131, identifier:merged_results; 132, identifier:limit; 133, comparison_operator:>; 133, 134; 133, 138; 134, call; 134, 135; 134, 136; 135, identifier:len; 136, argument_list; 136, 137; 137, identifier:ensemble_suggestions; 138, integer:0; 139, comparison_operator:>; 139, 140; 139, 144; 140, call; 140, 141; 140, 142; 141, identifier:len; 142, argument_list; 142, 143; 143, identifier:curated_suggestions; 144, integer:0; 145, block; 145, 146; 146, break_statement; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:r2; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:curated_suggestions; 153, identifier:pop; 154, argument_list; 155, if_statement; 155, 156; 155, 167; 156, comparison_operator:not; 156, 157; 156, 160; 157, subscript; 157, 158; 157, 159; 158, identifier:r2; 159, integer:0; 160, list_comprehension; 160, 161; 160, 164; 161, subscript; 161, 162; 161, 163; 162, identifier:temp; 163, integer:0; 164, for_in_clause; 164, 165; 164, 166; 165, identifier:temp; 166, identifier:merged_results; 167, block; 167, 168; 168, expression_statement; 168, 169; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:merged_results; 172, identifier:add; 173, argument_list; 173, 174; 174, identifier:r2; 175, if_statement; 175, 176; 175, 182; 176, comparison_operator:<; 176, 177; 176, 181; 177, call; 177, 178; 177, 179; 178, identifier:len; 179, argument_list; 179, 180; 180, identifier:merged_results; 181, identifier:limit; 182, block; 182, 183; 182, 192; 182, 201; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 186; 185, identifier:msg; 186, parenthesized_expression; 186, 187; 187, binary_operator:%; 187, 188; 187, 189; 188, string:"Defaulting to empty results. Insufficient recommendations found for client: %s"; 189, subscript; 189, 190; 189, 191; 190, identifier:client_data; 191, string:"client_id"; 192, expression_statement; 192, 193; 193, call; 193, 194; 193, 199; 194, attribute; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:self; 197, identifier:logger; 198, identifier:info; 199, argument_list; 199, 200; 200, identifier:msg; 201, return_statement; 201, 202; 202, list:[]; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 206; 205, identifier:sorted_results; 206, call; 206, 207; 206, 208; 207, identifier:sorted; 208, argument_list; 208, 209; 208, 213; 208, 221; 209, call; 209, 210; 209, 211; 210, identifier:list; 211, argument_list; 211, 212; 212, identifier:merged_results; 213, keyword_argument; 213, 214; 213, 215; 214, identifier:key; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:op; 218, identifier:itemgetter; 219, argument_list; 219, 220; 220, integer:1; 221, keyword_argument; 221, 222; 221, 223; 222, identifier:reverse; 223, True; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 227; 226, identifier:log_data; 227, tuple; 227, 228; 227, 231; 228, subscript; 228, 229; 228, 230; 229, identifier:client_data; 230, string:"client_id"; 231, call; 231, 232; 231, 233; 232, identifier:str; 233, argument_list; 233, 234; 234, list_comprehension; 234, 235; 234, 238; 235, subscript; 235, 236; 235, 237; 236, identifier:r; 237, integer:0; 238, for_in_clause; 238, 239; 238, 240; 239, identifier:r; 240, identifier:sorted_results; 241, expression_statement; 241, 242; 242, call; 242, 243; 242, 248; 243, attribute; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:self; 246, identifier:logger; 247, identifier:info; 248, argument_list; 248, 249; 249, binary_operator:%; 249, 250; 249, 251; 250, string:"Hybrid recommendations client_id: [%s], guids: [%s]"; 251, identifier:log_data; 252, return_statement; 252, 253; 253, identifier:sorted_results | def recommend(self, client_data, limit, extra_data={}):
"""
Hybrid recommendations simply select half recommendations from
the ensemble recommender, and half from the curated one.
Duplicate recommendations are accomodated by rank ordering
by weight.
"""
preinstalled_addon_ids = client_data.get("installed_addons", [])
# Compute an extended limit by adding the length of
# the list of any preinstalled addons.
extended_limit = limit + len(preinstalled_addon_ids)
ensemble_suggestions = self._ensemble_recommender.recommend(
client_data, extended_limit, extra_data
)
curated_suggestions = self._curated_recommender.recommend(
client_data, extended_limit, extra_data
)
# Generate a set of results from each of the composite
# recommenders. We select one item from each recommender
# sequentially so that we do not bias one recommender over the
# other.
merged_results = set()
while (
len(merged_results) < limit
and len(ensemble_suggestions) > 0
and len(curated_suggestions) > 0
):
r1 = ensemble_suggestions.pop()
if r1[0] not in [temp[0] for temp in merged_results]:
merged_results.add(r1)
# Terminate early if we have an odd number for the limit
if not (
len(merged_results) < limit
and len(ensemble_suggestions) > 0
and len(curated_suggestions) > 0
):
break
r2 = curated_suggestions.pop()
if r2[0] not in [temp[0] for temp in merged_results]:
merged_results.add(r2)
if len(merged_results) < limit:
msg = (
"Defaulting to empty results. Insufficient recommendations found for client: %s"
% client_data["client_id"]
)
self.logger.info(msg)
return []
sorted_results = sorted(
list(merged_results), key=op.itemgetter(1), reverse=True
)
log_data = (client_data["client_id"], str([r[0] for r in sorted_results]))
self.logger.info(
"Hybrid recommendations client_id: [%s], guids: [%s]" % log_data
)
return sorted_results |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:_recommend; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:client_data; 6, identifier:limit; 7, default_parameter; 7, 8; 7, 9; 8, identifier:extra_data; 9, dictionary; 10, block; 10, 11; 10, 13; 10, 22; 10, 32; 10, 33; 10, 34; 10, 43; 10, 47; 10, 57; 10, 124; 10, 125; 10, 139; 10, 140; 10, 141; 10, 156; 10, 160; 10, 192; 10, 193; 10, 208; 10, 224; 10, 232; 10, 253; 10, 264; 11, expression_statement; 11, 12; 12, comment; 13, expression_statement; 13, 14; 14, call; 14, 15; 14, 20; 15, attribute; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:logger; 19, identifier:info; 20, argument_list; 20, 21; 21, string:"Ensemble recommend invoked"; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:preinstalled_addon_ids; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:client_data; 28, identifier:get; 29, argument_list; 29, 30; 29, 31; 30, string:"installed_addons"; 31, list:[]; 32, comment; 33, comment; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:extended_limit; 37, binary_operator:+; 37, 38; 37, 39; 38, identifier:limit; 39, call; 39, 40; 39, 41; 40, identifier:len; 41, argument_list; 41, 42; 42, identifier:preinstalled_addon_ids; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:flattened_results; 46, list:[]; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:ensemble_weights; 50, call; 50, 51; 50, 56; 51, attribute; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:self; 54, identifier:_weight_cache; 55, identifier:getWeights; 56, argument_list; 57, for_statement; 57, 58; 57, 59; 57, 62; 58, identifier:rkey; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:RECOMMENDER_KEYS; 62, block; 62, 63; 62, 71; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:recommender; 66, subscript; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:_recommender_map; 70, identifier:rkey; 71, if_statement; 71, 72; 71, 78; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:recommender; 75, identifier:can_recommend; 76, argument_list; 76, 77; 77, identifier:client_data; 78, block; 78, 79; 78, 90; 78, 94; 78, 117; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:raw_results; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:recommender; 85, identifier:recommend; 86, argument_list; 86, 87; 86, 88; 86, 89; 87, identifier:client_data; 88, identifier:extended_limit; 89, identifier:extra_data; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:reweighted_results; 93, list:[]; 94, for_statement; 94, 95; 94, 98; 94, 99; 95, pattern_list; 95, 96; 95, 97; 96, identifier:guid; 97, identifier:weight; 98, identifier:raw_results; 99, block; 99, 100; 99, 110; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:item; 103, tuple; 103, 104; 103, 105; 104, identifier:guid; 105, binary_operator:*; 105, 106; 105, 107; 106, identifier:weight; 107, subscript; 107, 108; 107, 109; 108, identifier:ensemble_weights; 109, identifier:rkey; 110, expression_statement; 110, 111; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:reweighted_results; 114, identifier:append; 115, argument_list; 115, 116; 116, identifier:item; 117, expression_statement; 117, 118; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:flattened_results; 121, identifier:extend; 122, argument_list; 122, 123; 123, identifier:reweighted_results; 124, comment; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:flattened_results; 129, identifier:sort; 130, argument_list; 130, 131; 131, keyword_argument; 131, 132; 131, 133; 132, identifier:key; 133, lambda; 133, 134; 133, 136; 134, lambda_parameters; 134, 135; 135, identifier:item; 136, subscript; 136, 137; 136, 138; 137, identifier:item; 138, integer:0; 139, comment; 140, comment; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:guid_grouper; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:itertools; 147, identifier:groupby; 148, argument_list; 148, 149; 148, 150; 149, identifier:flattened_results; 150, lambda; 150, 151; 150, 153; 151, lambda_parameters; 151, 152; 152, identifier:item; 153, subscript; 153, 154; 153, 155; 154, identifier:item; 155, integer:0; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 159; 158, identifier:ensemble_suggestions; 159, list:[]; 160, for_statement; 160, 161; 160, 164; 160, 165; 161, tuple_pattern; 161, 162; 161, 163; 162, identifier:guid; 163, identifier:guid_group; 164, identifier:guid_grouper; 165, block; 165, 166; 165, 179; 165, 185; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 169; 168, identifier:weight_sum; 169, call; 169, 170; 169, 171; 170, identifier:sum; 171, argument_list; 171, 172; 172, list_comprehension; 172, 173; 172, 174; 173, identifier:v; 174, for_in_clause; 174, 175; 174, 178; 175, tuple_pattern; 175, 176; 175, 177; 176, identifier:g; 177, identifier:v; 178, identifier:guid_group; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 182; 181, identifier:item; 182, tuple; 182, 183; 182, 184; 183, identifier:guid; 184, identifier:weight_sum; 185, expression_statement; 185, 186; 186, call; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:ensemble_suggestions; 189, identifier:append; 190, argument_list; 190, 191; 191, identifier:item; 192, comment; 193, expression_statement; 193, 194; 194, call; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:ensemble_suggestions; 197, identifier:sort; 198, argument_list; 198, 199; 199, keyword_argument; 199, 200; 199, 201; 200, identifier:key; 201, lambda; 201, 202; 201, 204; 202, lambda_parameters; 202, 203; 203, identifier:x; 204, unary_operator:-; 204, 205; 205, subscript; 205, 206; 205, 207; 206, identifier:x; 207, integer:1; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 211; 210, identifier:filtered_ensemble_suggestions; 211, list_comprehension; 211, 212; 211, 215; 211, 220; 212, tuple; 212, 213; 212, 214; 213, identifier:guid; 214, identifier:weight; 215, for_in_clause; 215, 216; 215, 219; 216, tuple_pattern; 216, 217; 216, 218; 217, identifier:guid; 218, identifier:weight; 219, identifier:ensemble_suggestions; 220, if_clause; 220, 221; 221, comparison_operator:not; 221, 222; 221, 223; 222, identifier:guid; 223, identifier:preinstalled_addon_ids; 224, expression_statement; 224, 225; 225, assignment; 225, 226; 225, 227; 226, identifier:results; 227, subscript; 227, 228; 227, 229; 228, identifier:filtered_ensemble_suggestions; 229, slice; 229, 230; 229, 231; 230, colon; 231, identifier:limit; 232, expression_statement; 232, 233; 233, assignment; 233, 234; 233, 235; 234, identifier:log_data; 235, tuple; 235, 236; 235, 239; 235, 243; 236, subscript; 236, 237; 236, 238; 237, identifier:client_data; 238, string:"client_id"; 239, call; 239, 240; 239, 241; 240, identifier:str; 241, argument_list; 241, 242; 242, identifier:ensemble_weights; 243, call; 243, 244; 243, 245; 244, identifier:str; 245, argument_list; 245, 246; 246, list_comprehension; 246, 247; 246, 250; 247, subscript; 247, 248; 247, 249; 248, identifier:r; 249, integer:0; 250, for_in_clause; 250, 251; 250, 252; 251, identifier:r; 252, identifier:results; 253, expression_statement; 253, 254; 254, call; 254, 255; 254, 260; 255, attribute; 255, 256; 255, 259; 256, attribute; 256, 257; 256, 258; 257, identifier:self; 258, identifier:logger; 259, identifier:info; 260, argument_list; 260, 261; 261, binary_operator:%; 261, 262; 261, 263; 262, string:"client_id: [%s], ensemble_weight: [%s], guids: [%s]"; 263, identifier:log_data; 264, return_statement; 264, 265; 265, identifier:results | def _recommend(self, client_data, limit, extra_data={}):
"""
Ensemble recommendations are aggregated from individual
recommenders. The ensemble recommender applies a weight to
the recommendation outputs of each recommender to reorder the
recommendations to be a better fit.
The intuitive understanding is that the total space of
recommended addons across all recommenders will include the
'true' addons that should be recommended better than any
individual recommender. The ensemble method simply needs to
weight each recommender appropriate so that the ordering is
correct.
"""
self.logger.info("Ensemble recommend invoked")
preinstalled_addon_ids = client_data.get("installed_addons", [])
# Compute an extended limit by adding the length of
# the list of any preinstalled addons.
extended_limit = limit + len(preinstalled_addon_ids)
flattened_results = []
ensemble_weights = self._weight_cache.getWeights()
for rkey in self.RECOMMENDER_KEYS:
recommender = self._recommender_map[rkey]
if recommender.can_recommend(client_data):
raw_results = recommender.recommend(
client_data, extended_limit, extra_data
)
reweighted_results = []
for guid, weight in raw_results:
item = (guid, weight * ensemble_weights[rkey])
reweighted_results.append(item)
flattened_results.extend(reweighted_results)
# Sort the results by the GUID
flattened_results.sort(key=lambda item: item[0])
# group by the guid, sum up the weights for recurring GUID
# suggestions across all recommenders
guid_grouper = itertools.groupby(flattened_results, lambda item: item[0])
ensemble_suggestions = []
for (guid, guid_group) in guid_grouper:
weight_sum = sum([v for (g, v) in guid_group])
item = (guid, weight_sum)
ensemble_suggestions.append(item)
# Sort in reverse order (greatest weight to least)
ensemble_suggestions.sort(key=lambda x: -x[1])
filtered_ensemble_suggestions = [
(guid, weight)
for (guid, weight) in ensemble_suggestions
if guid not in preinstalled_addon_ids
]
results = filtered_ensemble_suggestions[:limit]
log_data = (
client_data["client_id"],
str(ensemble_weights),
str([r[0] for r in results]),
)
self.logger.info(
"client_id: [%s], ensemble_weight: [%s], guids: [%s]" % log_data
)
return results |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_build_features_caches; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 20; 5, 32; 5, 45; 5, 54; 5, 55; 5, 73; 5, 103; 5, 104; 5, 125; 5, 164; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:_donors_pool; 11, subscript; 11, 12; 11, 19; 12, call; 12, 13; 12, 18; 13, attribute; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:_donors_pool; 17, identifier:get; 18, argument_list; 19, integer:0; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:_lr_curves; 23, subscript; 23, 24; 23, 31; 24, call; 24, 25; 24, 30; 25, attribute; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:_lr_curves; 29, identifier:get; 30, argument_list; 31, integer:0; 32, if_statement; 32, 33; 32, 40; 32, 41; 32, 42; 33, boolean_operator:or; 33, 34; 33, 37; 34, comparison_operator:is; 34, 35; 34, 36; 35, identifier:_donors_pool; 36, None; 37, comparison_operator:is; 37, 38; 37, 39; 38, identifier:_lr_curves; 39, None; 40, comment; 41, comment; 42, block; 42, 43; 43, return_statement; 43, 44; 44, None; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:num_donors; 50, call; 50, 51; 50, 52; 51, identifier:len; 52, argument_list; 52, 53; 53, identifier:_donors_pool; 54, comment; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:continuous_features; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:np; 63, identifier:zeros; 64, argument_list; 64, 65; 65, tuple; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:num_donors; 69, call; 69, 70; 69, 71; 70, identifier:len; 71, argument_list; 71, 72; 72, identifier:CONTINUOUS_FEATURES; 73, for_statement; 73, 74; 73, 77; 73, 81; 74, pattern_list; 74, 75; 74, 76; 75, identifier:idx; 76, identifier:d; 77, call; 77, 78; 77, 79; 78, identifier:enumerate; 79, argument_list; 79, 80; 80, identifier:_donors_pool; 81, block; 81, 82; 81, 95; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:features; 85, list_comprehension; 85, 86; 85, 92; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:d; 89, identifier:get; 90, argument_list; 90, 91; 91, identifier:specified_key; 92, for_in_clause; 92, 93; 92, 94; 93, identifier:specified_key; 94, identifier:CONTINUOUS_FEATURES; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 102; 97, subscript; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:self; 100, identifier:continuous_features; 101, identifier:idx; 102, identifier:features; 103, comment; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:self; 108, identifier:categorical_features; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:np; 112, identifier:zeros; 113, argument_list; 113, 114; 113, 122; 114, tuple; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:self; 117, identifier:num_donors; 118, call; 118, 119; 118, 120; 119, identifier:len; 120, argument_list; 120, 121; 121, identifier:CATEGORICAL_FEATURES; 122, keyword_argument; 122, 123; 122, 124; 123, identifier:dtype; 124, string:"object"; 125, for_statement; 125, 126; 125, 129; 125, 133; 126, pattern_list; 126, 127; 126, 128; 127, identifier:idx; 128, identifier:d; 129, call; 129, 130; 129, 131; 130, identifier:enumerate; 131, argument_list; 131, 132; 132, identifier:_donors_pool; 133, block; 133, 134; 133, 147; 134, expression_statement; 134, 135; 135, assignment; 135, 136; 135, 137; 136, identifier:features; 137, list_comprehension; 137, 138; 137, 144; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:d; 141, identifier:get; 142, argument_list; 142, 143; 143, identifier:specified_key; 144, for_in_clause; 144, 145; 144, 146; 145, identifier:specified_key; 146, identifier:CATEGORICAL_FEATURES; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 154; 149, subscript; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:self; 152, identifier:categorical_features; 153, identifier:idx; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:np; 157, identifier:array; 158, argument_list; 158, 159; 158, 161; 159, list:[features]; 159, 160; 160, identifier:features; 161, keyword_argument; 161, 162; 161, 163; 162, identifier:dtype; 163, string:"object"; 164, expression_statement; 164, 165; 165, call; 165, 166; 165, 171; 166, attribute; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:self; 169, identifier:logger; 170, identifier:info; 171, argument_list; 171, 172; 172, string:"Reconstructed matrices for similarity recommender" | def _build_features_caches(self):
"""This function build two feature cache matrices.
That's the self.categorical_features and
self.continuous_features attributes.
One matrix is for the continuous features and the other is for
the categorical features. This is needed to speed up the similarity
recommendation process."""
_donors_pool = self._donors_pool.get()[0]
_lr_curves = self._lr_curves.get()[0]
if _donors_pool is None or _lr_curves is None:
# We need to have both donors_pool and lr_curves defined
# to reconstruct the matrices
return None
self.num_donors = len(_donors_pool)
# Build a numpy matrix cache for the continuous features.
self.continuous_features = np.zeros((self.num_donors, len(CONTINUOUS_FEATURES)))
for idx, d in enumerate(_donors_pool):
features = [d.get(specified_key) for specified_key in CONTINUOUS_FEATURES]
self.continuous_features[idx] = features
# Build the cache for categorical features.
self.categorical_features = np.zeros(
(self.num_donors, len(CATEGORICAL_FEATURES)), dtype="object"
)
for idx, d in enumerate(_donors_pool):
features = [d.get(specified_key) for specified_key in CATEGORICAL_FEATURES]
self.categorical_features[idx] = np.array([features], dtype="object")
self.logger.info("Reconstructed matrices for similarity recommender") |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:pdos_select; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:atoms; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:spin; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:l; 13, None; 14, default_parameter; 14, 15; 14, 16; 15, identifier:m; 16, None; 17, block; 17, 18; 17, 20; 17, 51; 17, 73; 17, 87; 17, 141; 17, 153; 17, 309; 18, expression_statement; 18, 19; 19, comment; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:valid_m_values; 23, dictionary; 23, 24; 23, 27; 23, 33; 23, 41; 24, pair; 24, 25; 24, 26; 25, string:'s'; 26, list:[]; 27, pair; 27, 28; 27, 29; 28, string:'p'; 29, list:[ 'x', 'y', 'z' ]; 29, 30; 29, 31; 29, 32; 30, string:'x'; 31, string:'y'; 32, string:'z'; 33, pair; 33, 34; 33, 35; 34, string:'d'; 35, list:[ 'xy', 'yz', 'z2-r2', 'xz', 'x2-y2' ]; 35, 36; 35, 37; 35, 38; 35, 39; 35, 40; 36, string:'xy'; 37, string:'yz'; 38, string:'z2-r2'; 39, string:'xz'; 40, string:'x2-y2'; 41, pair; 41, 42; 41, 43; 42, string:'f'; 43, list:[ 'y(3x2-y2)', 'xyz', 'yz2', 'z3', 'xz2', 'z(x2-y2)', 'x(x2-3y2)' ]; 43, 44; 43, 45; 43, 46; 43, 47; 43, 48; 43, 49; 43, 50; 44, string:'y(3x2-y2)'; 45, string:'xyz'; 46, string:'yz2'; 47, string:'z3'; 48, string:'xz2'; 49, string:'z(x2-y2)'; 50, string:'x(x2-3y2)'; 51, if_statement; 51, 52; 51, 54; 51, 67; 52, not_operator; 52, 53; 53, identifier:atoms; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:atom_idx; 58, call; 58, 59; 58, 60; 59, identifier:list; 60, argument_list; 60, 61; 61, call; 61, 62; 61, 63; 62, identifier:range; 63, argument_list; 63, 64; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:number_of_atoms; 67, else_clause; 67, 68; 68, block; 68, 69; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:atom_idx; 72, identifier:atoms; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:to_return; 76, subscript; 76, 77; 76, 80; 76, 81; 76, 83; 76, 85; 77, attribute; 77, 78; 77, 79; 78, identifier:self; 79, identifier:pdos; 80, identifier:atom_idx; 81, slice; 81, 82; 82, colon; 83, slice; 83, 84; 84, colon; 85, slice; 85, 86; 86, colon; 87, if_statement; 87, 88; 87, 90; 87, 103; 87, 113; 87, 123; 87, 134; 88, not_operator; 88, 89; 89, identifier:spin; 90, block; 90, 91; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:spin_idx; 94, call; 94, 95; 94, 96; 95, identifier:list; 96, argument_list; 96, 97; 97, call; 97, 98; 97, 99; 98, identifier:range; 99, argument_list; 99, 100; 100, attribute; 100, 101; 100, 102; 101, identifier:self; 102, identifier:ispin; 103, elif_clause; 103, 104; 103, 107; 104, comparison_operator:is; 104, 105; 104, 106; 105, identifier:spin; 106, string:'up'; 107, block; 107, 108; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:spin_idx; 111, list:[0]; 111, 112; 112, integer:0; 113, elif_clause; 113, 114; 113, 117; 114, comparison_operator:is; 114, 115; 114, 116; 115, identifier:spin; 116, string:'down'; 117, block; 117, 118; 118, expression_statement; 118, 119; 119, assignment; 119, 120; 119, 121; 120, identifier:spin_idx; 121, list:[1]; 121, 122; 122, integer:1; 123, elif_clause; 123, 124; 123, 127; 124, comparison_operator:is; 124, 125; 124, 126; 125, identifier:spin; 126, string:'both'; 127, block; 127, 128; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:spin_idx; 131, list:[0,1]; 131, 132; 131, 133; 132, integer:0; 133, integer:1; 134, else_clause; 134, 135; 135, block; 135, 136; 136, raise_statement; 136, 137; 137, call; 137, 138; 137, 139; 138, identifier:ValueError; 139, argument_list; 139, 140; 140, string:"valid spin values are 'up', 'down', and 'both'. The default is 'both'"; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:to_return; 144, subscript; 144, 145; 144, 146; 144, 148; 144, 150; 144, 152; 145, identifier:to_return; 146, slice; 146, 147; 147, colon; 148, slice; 148, 149; 149, colon; 150, slice; 150, 151; 151, colon; 152, identifier:spin_idx; 153, if_statement; 153, 154; 153, 156; 153, 169; 153, 179; 153, 219; 153, 261; 153, 305; 154, not_operator; 154, 155; 155, identifier:l; 156, block; 156, 157; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:channel_idx; 160, call; 160, 161; 160, 162; 161, identifier:list; 162, argument_list; 162, 163; 163, call; 163, 164; 163, 165; 164, identifier:range; 165, argument_list; 165, 166; 166, attribute; 166, 167; 166, 168; 167, identifier:self; 168, identifier:number_of_channels; 169, elif_clause; 169, 170; 169, 173; 170, comparison_operator:==; 170, 171; 170, 172; 171, identifier:l; 172, string:'s'; 173, block; 173, 174; 174, expression_statement; 174, 175; 175, assignment; 175, 176; 175, 177; 176, identifier:channel_idx; 177, list:[ 0 ]; 177, 178; 178, integer:0; 179, elif_clause; 179, 180; 179, 183; 180, comparison_operator:==; 180, 181; 180, 182; 181, identifier:l; 182, string:'p'; 183, block; 183, 184; 184, if_statement; 184, 185; 184, 187; 184, 195; 185, not_operator; 185, 186; 186, identifier:m; 187, block; 187, 188; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 191; 190, identifier:channel_idx; 191, list:[ 1, 2, 3 ]; 191, 192; 191, 193; 191, 194; 192, integer:1; 193, integer:2; 194, integer:3; 195, else_clause; 195, 196; 195, 197; 196, comment; 197, block; 197, 198; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:channel_idx; 201, list_comprehension; 201, 202; 201, 205; 201, 215; 202, binary_operator:+; 202, 203; 202, 204; 203, identifier:i; 204, integer:1; 205, for_in_clause; 205, 206; 205, 209; 206, pattern_list; 206, 207; 206, 208; 207, identifier:i; 208, identifier:v; 209, call; 209, 210; 209, 211; 210, identifier:enumerate; 211, argument_list; 211, 212; 212, subscript; 212, 213; 212, 214; 213, identifier:valid_m_values; 214, string:'p'; 215, if_clause; 215, 216; 216, comparison_operator:in; 216, 217; 216, 218; 217, identifier:v; 218, identifier:m; 219, elif_clause; 219, 220; 219, 223; 220, comparison_operator:==; 220, 221; 220, 222; 221, identifier:l; 222, string:'d'; 223, block; 223, 224; 224, if_statement; 224, 225; 224, 227; 224, 237; 225, not_operator; 225, 226; 226, identifier:m; 227, block; 227, 228; 228, expression_statement; 228, 229; 229, assignment; 229, 230; 229, 231; 230, identifier:channel_idx; 231, list:[ 4, 5, 6, 7, 8 ]; 231, 232; 231, 233; 231, 234; 231, 235; 231, 236; 232, integer:4; 233, integer:5; 234, integer:6; 235, integer:7; 236, integer:8; 237, else_clause; 237, 238; 237, 239; 238, comment; 239, block; 239, 240; 240, expression_statement; 240, 241; 241, assignment; 241, 242; 241, 243; 242, identifier:channel_idx; 243, list_comprehension; 243, 244; 243, 247; 243, 257; 244, binary_operator:+; 244, 245; 244, 246; 245, identifier:i; 246, integer:4; 247, for_in_clause; 247, 248; 247, 251; 248, pattern_list; 248, 249; 248, 250; 249, identifier:i; 250, identifier:v; 251, call; 251, 252; 251, 253; 252, identifier:enumerate; 253, argument_list; 253, 254; 254, subscript; 254, 255; 254, 256; 255, identifier:valid_m_values; 256, string:'d'; 257, if_clause; 257, 258; 258, comparison_operator:in; 258, 259; 258, 260; 259, identifier:v; 260, identifier:m; 261, elif_clause; 261, 262; 261, 265; 262, comparison_operator:==; 262, 263; 262, 264; 263, identifier:l; 264, string:'f'; 265, block; 265, 266; 266, if_statement; 266, 267; 266, 269; 266, 281; 267, not_operator; 267, 268; 268, identifier:m; 269, block; 269, 270; 270, expression_statement; 270, 271; 271, assignment; 271, 272; 271, 273; 272, identifier:channel_idx; 273, list:[ 9, 10, 11, 12, 13, 14, 15 ]; 273, 274; 273, 275; 273, 276; 273, 277; 273, 278; 273, 279; 273, 280; 274, integer:9; 275, integer:10; 276, integer:11; 277, integer:12; 278, integer:13; 279, integer:14; 280, integer:15; 281, else_clause; 281, 282; 281, 283; 282, comment; 283, block; 283, 284; 284, expression_statement; 284, 285; 285, assignment; 285, 286; 285, 287; 286, identifier:channel_idx; 287, list_comprehension; 287, 288; 287, 291; 287, 301; 288, binary_operator:+; 288, 289; 288, 290; 289, identifier:i; 290, integer:9; 291, for_in_clause; 291, 292; 291, 295; 292, pattern_list; 292, 293; 292, 294; 293, identifier:i; 294, identifier:v; 295, call; 295, 296; 295, 297; 296, identifier:enumerate; 297, argument_list; 297, 298; 298, subscript; 298, 299; 298, 300; 299, identifier:valid_m_values; 300, string:'f'; 301, if_clause; 301, 302; 302, comparison_operator:in; 302, 303; 302, 304; 303, identifier:v; 304, identifier:m; 305, else_clause; 305, 306; 306, block; 306, 307; 307, raise_statement; 307, 308; 308, identifier:ValueError; 309, return_statement; 309, 310; 310, subscript; 310, 311; 310, 312; 310, 314; 310, 316; 310, 317; 311, identifier:to_return; 312, slice; 312, 313; 313, colon; 314, slice; 314, 315; 315, colon; 316, identifier:channel_idx; 317, slice; 317, 318; 318, colon | def pdos_select( self, atoms=None, spin=None, l=None, m=None ):
"""
Returns a subset of the projected density of states array.
Args:
atoms (int or list(int)): Atom numbers to include in the selection. Atom numbers count from 1.
Default is to select all atoms.
spin (str): Select up or down, or both spin channels to include in the selection.
Accepted options are 'up', 'down', and 'both'. Default is to select both spins.
l (str): Select one angular momentum to include in the selectrion.
Accepted options are 's', 'p', 'd', and 'f'. Default is to include all l-values.
Setting `l` and not setting `m` will return all projections for that angular momentum value.
m (list(str)): Select one or more m-values. Requires `l` to be set.
The accepted values depend on the value of `l`:
`l='s'`: Only one projection. Not set.
`l='p'`: One or more of [ 'x', 'y', 'z' ]
`l='d'`: One or more of [ 'xy', 'yz', 'z2-r2', 'xz', 'x2-y2' ]
`l='f'`: One or more of [ 'y(3x2-y2)', 'xyz', 'yz2', 'z3', 'xz2', 'z(x2-y2)', 'x(x2-3y2)' ]
Returns:
np.array: A 4-dimensional numpy array containing the selected pdos values.
The array dimensions are [ atom_no, energy_value, lm-projection, spin ]
"""
valid_m_values = { 's': [],
'p': [ 'x', 'y', 'z' ],
'd': [ 'xy', 'yz', 'z2-r2', 'xz', 'x2-y2' ],
'f': [ 'y(3x2-y2)', 'xyz', 'yz2', 'z3', 'xz2', 'z(x2-y2)', 'x(x2-3y2)' ] }
if not atoms:
atom_idx = list(range( self.number_of_atoms ))
else:
atom_idx = atoms
to_return = self.pdos[ atom_idx, :, :, : ]
if not spin:
spin_idx = list(range( self.ispin ))
elif spin is 'up':
spin_idx = [0]
elif spin is 'down':
spin_idx = [1]
elif spin is 'both':
spin_idx = [0,1]
else:
raise ValueError( "valid spin values are 'up', 'down', and 'both'. The default is 'both'" )
to_return = to_return[ :, :, :, spin_idx ]
if not l:
channel_idx = list(range( self.number_of_channels ))
elif l == 's':
channel_idx = [ 0 ]
elif l == 'p':
if not m:
channel_idx = [ 1, 2, 3 ]
else: # TODO this looks like it should be i+1
channel_idx = [ i+1 for i, v in enumerate( valid_m_values['p'] ) if v in m ]
elif l == 'd':
if not m:
channel_idx = [ 4, 5, 6, 7, 8 ]
else: # TODO this looks like it should be i+4
channel_idx = [ i+4 for i, v in enumerate( valid_m_values['d'] ) if v in m ]
elif l == 'f':
if not m:
channel_idx = [ 9, 10, 11, 12, 13, 14, 15 ]
else: # TODO this looks like it should be i+9
channel_idx = [ i+9 for i, v in enumerate( valid_m_values['f'] ) if v in m ]
else:
raise ValueError
return to_return[ :, :, channel_idx, : ] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_describe; 3, parameters; 3, 4; 3, 5; 4, identifier:node; 5, identifier:parent; 6, block; 6, 7; 6, 9; 6, 16; 6, 26; 6, 215; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 15; 11, pattern_list; 11, 12; 11, 13; 11, 14; 12, identifier:name; 13, identifier:logger; 14, identifier:children; 15, identifier:node; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:is_placeholder; 19, call; 19, 20; 19, 21; 20, identifier:isinstance; 21, argument_list; 21, 22; 21, 23; 22, identifier:logger; 23, attribute; 23, 24; 23, 25; 24, identifier:logging; 25, identifier:PlaceHolder; 26, if_statement; 26, 27; 26, 28; 26, 34; 27, identifier:is_placeholder; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, yield; 30, 31; 31, binary_operator:%; 31, 32; 31, 33; 32, string:'<--[%s]'; 33, identifier:name; 34, else_clause; 34, 35; 35, block; 35, 36; 35, 50; 35, 73; 35, 80; 35, 108; 35, 145; 35, 154; 35, 162; 35, 163; 35, 164; 35, 165; 35, 182; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:parent_is_correct; 39, boolean_operator:or; 39, 40; 39, 44; 40, parenthesized_expression; 40, 41; 41, comparison_operator:is; 41, 42; 41, 43; 42, identifier:parent; 43, None; 44, parenthesized_expression; 44, 45; 45, comparison_operator:is; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:logger; 48, identifier:parent; 49, identifier:parent; 50, if_statement; 50, 51; 50, 55; 50, 60; 50, 67; 51, not_operator; 51, 52; 52, attribute; 52, 53; 52, 54; 53, identifier:logger; 54, identifier:propagate; 55, block; 55, 56; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:arrow; 59, string:' '; 60, elif_clause; 60, 61; 60, 62; 61, identifier:parent_is_correct; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:arrow; 66, string:'<--'; 67, else_clause; 67, 68; 68, block; 68, 69; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:arrow; 72, string:' !-'; 73, expression_statement; 73, 74; 74, yield; 74, 75; 75, binary_operator:%; 75, 76; 75, 77; 76, string:'%s"%s"'; 77, tuple; 77, 78; 77, 79; 78, identifier:arrow; 79, identifier:name; 80, if_statement; 80, 81; 80, 83; 81, not_operator; 81, 82; 82, identifier:parent_is_correct; 83, block; 83, 84; 84, if_statement; 84, 85; 84, 90; 84, 95; 85, comparison_operator:is; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:logger; 88, identifier:parent; 89, None; 90, block; 90, 91; 91, expression_statement; 91, 92; 92, yield; 92, 93; 93, parenthesized_expression; 93, 94; 94, string:' Broken .parent is None, so messages stop here'; 95, else_clause; 95, 96; 96, block; 96, 97; 97, expression_statement; 97, 98; 98, yield; 98, 99; 99, parenthesized_expression; 99, 100; 100, binary_operator:%; 100, 101; 100, 102; 101, string:' Broken .parent redirects messages to %r instead'; 102, tuple; 102, 103; 103, attribute; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:logger; 106, identifier:parent; 107, identifier:name; 108, if_statement; 108, 109; 108, 116; 108, 131; 109, comparison_operator:==; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:logger; 112, identifier:level; 113, attribute; 113, 114; 113, 115; 114, identifier:logging; 115, identifier:NOTSET; 116, block; 116, 117; 117, expression_statement; 117, 118; 118, yield; 118, 119; 119, binary_operator:+; 119, 120; 119, 121; 120, string:' Level NOTSET so inherits level '; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:logging; 124, identifier:getLevelName; 125, argument_list; 125, 126; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:logger; 129, identifier:getEffectiveLevel; 130, argument_list; 131, else_clause; 131, 132; 132, block; 132, 133; 133, expression_statement; 133, 134; 134, yield; 134, 135; 135, binary_operator:+; 135, 136; 135, 137; 136, string:' Level '; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:logging; 140, identifier:getLevelName; 141, argument_list; 141, 142; 142, attribute; 142, 143; 142, 144; 143, identifier:logger; 144, identifier:level; 145, if_statement; 145, 146; 145, 150; 146, not_operator; 146, 147; 147, attribute; 147, 148; 147, 149; 148, identifier:logger; 149, identifier:propagate; 150, block; 150, 151; 151, expression_statement; 151, 152; 152, yield; 152, 153; 153, string:' Propagate OFF'; 154, if_statement; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:logger; 157, identifier:disabled; 158, block; 158, 159; 159, expression_statement; 159, 160; 160, yield; 160, 161; 161, string:' Disabled'; 162, comment; 163, comment; 164, comment; 165, for_statement; 165, 166; 165, 167; 165, 173; 166, identifier:f; 167, call; 167, 168; 167, 169; 168, identifier:getattr; 169, argument_list; 169, 170; 169, 171; 169, 172; 170, identifier:logger; 171, string:'filters'; 172, tuple; 173, block; 173, 174; 174, expression_statement; 174, 175; 175, yield; 175, 176; 176, binary_operator:%; 176, 177; 176, 178; 177, string:' Filter %s'; 178, call; 178, 179; 178, 180; 179, identifier:describe_filter; 180, argument_list; 180, 181; 181, identifier:f; 182, for_statement; 182, 183; 182, 184; 182, 190; 183, identifier:h; 184, call; 184, 185; 184, 186; 185, identifier:getattr; 186, argument_list; 186, 187; 186, 188; 186, 189; 187, identifier:logger; 188, string:'handlers'; 189, tuple; 190, block; 190, 191; 190, 198; 190, 206; 191, expression_statement; 191, 192; 192, assignment; 192, 193; 192, 194; 193, identifier:g; 194, call; 194, 195; 194, 196; 195, identifier:describe_handler; 196, argument_list; 196, 197; 197, identifier:h; 198, expression_statement; 198, 199; 199, yield; 199, 200; 200, binary_operator:%; 200, 201; 200, 202; 201, string:' Handler %s'; 202, call; 202, 203; 202, 204; 203, identifier:next; 204, argument_list; 204, 205; 205, identifier:g; 206, for_statement; 206, 207; 206, 208; 206, 209; 207, identifier:line; 208, identifier:g; 209, block; 209, 210; 210, expression_statement; 210, 211; 211, yield; 211, 212; 212, binary_operator:+; 212, 213; 212, 214; 213, string:' '; 214, identifier:line; 215, if_statement; 215, 216; 215, 217; 216, identifier:children; 217, block; 217, 218; 217, 226; 217, 233; 218, if_statement; 218, 219; 218, 221; 219, not_operator; 219, 220; 220, identifier:is_placeholder; 221, block; 221, 222; 222, expression_statement; 222, 223; 223, assignment; 223, 224; 223, 225; 224, identifier:parent; 225, identifier:logger; 226, expression_statement; 226, 227; 227, assignment; 227, 228; 227, 229; 228, identifier:last_child; 229, subscript; 229, 230; 229, 231; 230, identifier:children; 231, unary_operator:-; 231, 232; 232, integer:1; 233, for_statement; 233, 234; 233, 235; 233, 236; 234, identifier:child; 235, identifier:children; 236, block; 236, 237; 236, 245; 236, 248; 236, 256; 236, 271; 237, expression_statement; 237, 238; 238, assignment; 238, 239; 238, 240; 239, identifier:g; 240, call; 240, 241; 240, 242; 241, identifier:_describe; 242, argument_list; 242, 243; 242, 244; 243, identifier:child; 244, identifier:parent; 245, expression_statement; 245, 246; 246, yield; 246, 247; 247, string:' |'; 248, expression_statement; 248, 249; 249, yield; 249, 250; 250, binary_operator:+; 250, 251; 250, 252; 251, string:' o'; 252, call; 252, 253; 252, 254; 253, identifier:next; 254, argument_list; 254, 255; 255, identifier:g; 256, if_statement; 256, 257; 256, 260; 256, 265; 257, comparison_operator:is; 257, 258; 257, 259; 258, identifier:child; 259, identifier:last_child; 260, block; 260, 261; 261, expression_statement; 261, 262; 262, assignment; 262, 263; 262, 264; 263, identifier:prefix; 264, string:' '; 265, else_clause; 265, 266; 266, block; 266, 267; 267, expression_statement; 267, 268; 268, assignment; 268, 269; 268, 270; 269, identifier:prefix; 270, string:' |'; 271, for_statement; 271, 272; 271, 273; 271, 274; 272, identifier:line; 273, identifier:g; 274, block; 274, 275; 275, expression_statement; 275, 276; 276, yield; 276, 277; 277, binary_operator:+; 277, 278; 277, 279; 278, identifier:prefix; 279, identifier:line | def _describe(node, parent):
"""Generate lines describing the given `node` tuple.
This is the recursive back-end that powers ``describe()``. With its
extra ``parent`` parameter, this routine remembers the nearest
non-placeholder ancestor so that it can compare it against the
actual value of the ``.parent`` attribute of each node.
"""
name, logger, children = node
is_placeholder = isinstance(logger, logging.PlaceHolder)
if is_placeholder:
yield '<--[%s]' % name
else:
parent_is_correct = (parent is None) or (logger.parent is parent)
if not logger.propagate:
arrow = ' '
elif parent_is_correct:
arrow = '<--'
else:
arrow = ' !-'
yield '%s"%s"' % (arrow, name)
if not parent_is_correct:
if logger.parent is None:
yield (' Broken .parent is None, so messages stop here')
else:
yield (' Broken .parent redirects messages to %r instead'
% (logger.parent.name,))
if logger.level == logging.NOTSET:
yield ' Level NOTSET so inherits level ' + logging.getLevelName(
logger.getEffectiveLevel())
else:
yield ' Level ' + logging.getLevelName(logger.level)
if not logger.propagate:
yield ' Propagate OFF'
if logger.disabled:
yield ' Disabled'
# In case someone has defined a custom logger that lacks a
# `filters` or `handlers` attribute, we call getattr() and
# provide an empty sequence as a fallback.
for f in getattr(logger, 'filters', ()):
yield ' Filter %s' % describe_filter(f)
for h in getattr(logger, 'handlers', ()):
g = describe_handler(h)
yield ' Handler %s' % next(g)
for line in g:
yield ' ' + line
if children:
if not is_placeholder:
parent = logger
last_child = children[-1]
for child in children:
g = _describe(child, parent)
yield ' |'
yield ' o' + next(g)
if child is last_child:
prefix = ' '
else:
prefix = ' |'
for line in g:
yield prefix + line |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:resample; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 23; 5, 24; 5, 30; 5, 36; 5, 37; 5, 38; 5, 65; 5, 66; 5, 87; 5, 88; 5, 89; 5, 90; 5, 91; 5, 92; 5, 104; 5, 112; 5, 120; 5, 121; 5, 146; 5, 147; 5, 148; 5, 176; 5, 177; 5, 199; 5, 200; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:just_resampled; 12, block; 12, 13; 13, expression_statement; 13, 14; 14, call; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:warnings; 17, identifier:warn; 18, argument_list; 18, 19; 18, 22; 19, concatenated_string; 19, 20; 19, 21; 20, string:"Resampling without additional data; this may not perform as "; 21, string:"desired."; 22, identifier:ResamplerWarning; 23, comment; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:_just_resampled; 29, True; 30, expression_statement; 30, 31; 31, augmented_assignment:+=; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:_resample_count; 35, integer:1; 36, comment; 37, comment; 38, if_statement; 38, 39; 38, 44; 39, comparison_operator:is; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:_resampling_divergences; 43, None; 44, block; 44, 45; 44, 55; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:old_locs; 48, call; 48, 49; 48, 54; 49, attribute; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:particle_locations; 53, identifier:copy; 54, argument_list; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:old_weights; 58, call; 58, 59; 58, 64; 59, attribute; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:particle_weights; 63, identifier:copy; 64, argument_list; 65, comment; 66, if_statement; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:_debug_resampling; 70, block; 70, 71; 70, 79; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:old_mean; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:est_mean; 78, argument_list; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:old_cov; 82, call; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:self; 85, identifier:est_covariance_mtx; 86, argument_list; 87, comment; 88, comment; 89, comment; 90, comment; 91, comment; 92, expression_statement; 92, 93; 93, assignment; 93, 94; 93, 95; 94, identifier:new_distribution; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:resampler; 99, argument_list; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:self; 102, identifier:model; 103, identifier:self; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:self; 108, identifier:particle_weights; 109, attribute; 109, 110; 109, 111; 110, identifier:new_distribution; 111, identifier:particle_weights; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:self; 116, identifier:particle_locations; 117, attribute; 117, 118; 117, 119; 118, identifier:new_distribution; 119, identifier:particle_locations; 120, comment; 121, if_statement; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:self; 124, identifier:_canonicalize; 125, block; 125, 126; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 136; 128, subscript; 128, 129; 128, 132; 128, 134; 129, attribute; 129, 130; 129, 131; 130, identifier:self; 131, identifier:particle_locations; 132, slice; 132, 133; 133, colon; 134, slice; 134, 135; 135, colon; 136, call; 136, 137; 136, 142; 137, attribute; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:self; 140, identifier:model; 141, identifier:canonicalize; 142, argument_list; 142, 143; 143, attribute; 143, 144; 143, 145; 144, identifier:self; 145, identifier:particle_locations; 146, comment; 147, comment; 148, try_statement; 148, 149; 148, 158; 149, block; 149, 150; 150, expression_statement; 150, 151; 151, call; 151, 152; 151, 157; 152, attribute; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:self; 155, identifier:model; 156, identifier:clear_cache; 157, argument_list; 158, except_clause; 158, 159; 158, 163; 159, as_pattern; 159, 160; 159, 161; 160, identifier:Exception; 161, as_pattern_target; 161, 162; 162, identifier:e; 163, block; 163, 164; 164, expression_statement; 164, 165; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:warnings; 168, identifier:warn; 169, argument_list; 169, 170; 170, call; 170, 171; 170, 174; 171, attribute; 171, 172; 171, 173; 172, string:"Exception raised when clearing model cache: {}. Ignoring."; 173, identifier:format; 174, argument_list; 174, 175; 175, identifier:e; 176, comment; 177, if_statement; 177, 178; 177, 183; 178, comparison_operator:is; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:self; 181, identifier:_resampling_divergences; 182, None; 183, block; 183, 184; 184, expression_statement; 184, 185; 185, call; 185, 186; 185, 191; 186, attribute; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:self; 189, identifier:_resampling_divergences; 190, identifier:append; 191, argument_list; 191, 192; 192, call; 192, 193; 192, 196; 193, attribute; 193, 194; 193, 195; 194, identifier:self; 195, identifier:_kl_divergence; 196, argument_list; 196, 197; 196, 198; 197, identifier:old_locs; 198, identifier:old_weights; 199, comment; 200, if_statement; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:self; 203, identifier:_debug_resampling; 204, block; 204, 205; 204, 213; 204, 221; 205, expression_statement; 205, 206; 206, assignment; 206, 207; 206, 208; 207, identifier:new_mean; 208, call; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:self; 211, identifier:est_mean; 212, argument_list; 213, expression_statement; 213, 214; 214, assignment; 214, 215; 214, 216; 215, identifier:new_cov; 216, call; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:self; 219, identifier:est_covariance_mtx; 220, argument_list; 221, expression_statement; 221, 222; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:logger; 225, identifier:debug; 226, argument_list; 226, 227; 227, call; 227, 228; 227, 231; 228, attribute; 228, 229; 228, 230; 229, string:"Resampling changed mean by {}. Norm change in cov: {}."; 230, identifier:format; 231, argument_list; 231, 232; 231, 235; 232, binary_operator:-; 232, 233; 232, 234; 233, identifier:old_mean; 234, identifier:new_mean; 235, call; 235, 236; 235, 241; 236, attribute; 236, 237; 236, 240; 237, attribute; 237, 238; 237, 239; 238, identifier:np; 239, identifier:linalg; 240, identifier:norm; 241, argument_list; 241, 242; 242, binary_operator:-; 242, 243; 242, 244; 243, identifier:new_cov; 244, identifier:old_cov | def resample(self):
"""
Forces the updater to perform a resampling step immediately.
"""
if self.just_resampled:
warnings.warn(
"Resampling without additional data; this may not perform as "
"desired.",
ResamplerWarning
)
# Record that we have performed a resampling step.
self._just_resampled = True
self._resample_count += 1
# If we're tracking divergences, make a copy of the weights and
# locations.
if self._resampling_divergences is not None:
old_locs = self.particle_locations.copy()
old_weights = self.particle_weights.copy()
# Record the previous mean, cov if needed.
if self._debug_resampling:
old_mean = self.est_mean()
old_cov = self.est_covariance_mtx()
# Find the new particle locations according to the chosen resampling
# algorithm.
# We pass the model so that the resampler can check for validity of
# newly placed particles.
# FIXME This feels fishy. If we update particles elsewwhere
new_distribution = self.resampler(self.model, self)
self.particle_weights = new_distribution.particle_weights
self.particle_locations = new_distribution.particle_locations
# Possibly canonicalize, if we've been asked to do so.
if self._canonicalize:
self.particle_locations[:, :] = self.model.canonicalize(self.particle_locations)
# Instruct the model to clear its cache, demoting any errors to
# warnings.
try:
self.model.clear_cache()
except Exception as e:
warnings.warn("Exception raised when clearing model cache: {}. Ignoring.".format(e))
# Possibly track the new divergence.
if self._resampling_divergences is not None:
self._resampling_divergences.append(
self._kl_divergence(old_locs, old_weights)
)
# Report current and previous mean, cov.
if self._debug_resampling:
new_mean = self.est_mean()
new_cov = self.est_covariance_mtx()
logger.debug("Resampling changed mean by {}. Norm change in cov: {}.".format(
old_mean - new_mean,
np.linalg.norm(new_cov - old_cov)
)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:expected_information_gain; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:expparams; 6, block; 6, 7; 6, 9; 6, 10; 6, 11; 6, 12; 6, 13; 6, 19; 6, 65; 6, 66; 6, 86; 6, 87; 6, 88; 6, 89; 6, 113; 6, 137; 6, 173; 6, 187; 6, 209; 6, 210; 6, 211; 6, 212; 6, 213; 6, 236; 6, 237; 7, expression_statement; 7, 8; 8, comment; 9, comment; 10, comment; 11, comment; 12, comment; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:n_eps; 16, attribute; 16, 17; 16, 18; 17, identifier:expparams; 18, identifier:size; 19, if_statement; 19, 20; 19, 30; 20, boolean_operator:and; 20, 21; 20, 24; 21, comparison_operator:>; 21, 22; 21, 23; 22, identifier:n_eps; 23, integer:1; 24, not_operator; 24, 25; 25, attribute; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:model; 29, identifier:is_n_outcomes_constant; 30, block; 30, 31; 30, 40; 30, 63; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:risk; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:np; 37, identifier:empty; 38, argument_list; 38, 39; 39, identifier:n_eps; 40, for_statement; 40, 41; 40, 42; 40, 46; 41, identifier:idx; 42, call; 42, 43; 42, 44; 43, identifier:range; 44, argument_list; 44, 45; 45, identifier:n_eps; 46, block; 46, 47; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 52; 49, subscript; 49, 50; 49, 51; 50, identifier:risk; 51, identifier:idx; 52, call; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:expected_information_gain; 56, argument_list; 56, 57; 57, subscript; 57, 58; 57, 59; 57, 60; 58, identifier:expparams; 59, identifier:idx; 60, attribute; 60, 61; 60, 62; 61, identifier:np; 62, identifier:newaxis; 63, return_statement; 63, 64; 64, identifier:risk; 65, comment; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:os; 69, attribute; 69, 70; 69, 85; 70, subscript; 70, 71; 70, 84; 71, call; 71, 72; 71, 77; 72, attribute; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:self; 75, identifier:model; 76, identifier:domain; 77, argument_list; 77, 78; 78, subscript; 78, 79; 78, 80; 78, 81; 79, identifier:expparams; 80, integer:0; 81, attribute; 81, 82; 81, 83; 82, identifier:np; 83, identifier:newaxis; 84, integer:0; 85, identifier:values; 86, comment; 87, comment; 88, comment; 89, expression_statement; 89, 90; 90, assignment; 90, 91; 90, 95; 91, pattern_list; 91, 92; 91, 93; 91, 94; 92, identifier:w_hyp; 93, identifier:L; 94, identifier:N; 95, call; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:hypothetical_update; 99, argument_list; 99, 100; 99, 106; 99, 107; 99, 110; 100, subscript; 100, 101; 100, 102; 101, identifier:os; 102, slice; 102, 103; 102, 104; 103, colon; 104, unary_operator:-; 104, 105; 105, integer:1; 106, identifier:expparams; 107, keyword_argument; 107, 108; 107, 109; 108, identifier:return_normalization; 109, True; 110, keyword_argument; 110, 111; 110, 112; 111, identifier:return_likelihood; 112, True; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:w_hyp_last_outcome; 116, binary_operator:*; 116, 117; 116, 128; 117, parenthesized_expression; 117, 118; 118, binary_operator:-; 118, 119; 118, 120; 119, integer:1; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:L; 123, identifier:sum; 124, argument_list; 124, 125; 125, keyword_argument; 125, 126; 125, 127; 126, identifier:axis; 127, integer:0; 128, subscript; 128, 129; 128, 132; 128, 135; 129, attribute; 129, 130; 129, 131; 130, identifier:self; 131, identifier:particle_weights; 132, attribute; 132, 133; 132, 134; 133, identifier:np; 134, identifier:newaxis; 135, slice; 135, 136; 136, colon; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 140; 139, identifier:N; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:np; 143, identifier:concatenate; 144, argument_list; 144, 145; 144, 170; 145, list:[N[:,:,0], np.sum(w_hyp_last_outcome[np.newaxis,:,:], axis=2)]; 145, 146; 145, 153; 146, subscript; 146, 147; 146, 148; 146, 150; 146, 152; 147, identifier:N; 148, slice; 148, 149; 149, colon; 150, slice; 150, 151; 151, colon; 152, integer:0; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:np; 156, identifier:sum; 157, argument_list; 157, 158; 157, 167; 158, subscript; 158, 159; 158, 160; 158, 163; 158, 165; 159, identifier:w_hyp_last_outcome; 160, attribute; 160, 161; 160, 162; 161, identifier:np; 162, identifier:newaxis; 163, slice; 163, 164; 164, colon; 165, slice; 165, 166; 166, colon; 167, keyword_argument; 167, 168; 167, 169; 168, identifier:axis; 169, integer:2; 170, keyword_argument; 170, 171; 170, 172; 171, identifier:axis; 172, integer:0; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 176; 175, identifier:w_hyp_last_outcome; 176, binary_operator:/; 176, 177; 176, 178; 177, identifier:w_hyp_last_outcome; 178, subscript; 178, 179; 178, 180; 178, 182; 178, 184; 179, identifier:N; 180, unary_operator:-; 180, 181; 181, integer:1; 182, slice; 182, 183; 183, colon; 184, attribute; 184, 185; 184, 186; 185, identifier:np; 186, identifier:newaxis; 187, expression_statement; 187, 188; 188, assignment; 188, 189; 188, 190; 189, identifier:w_hyp; 190, call; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:np; 193, identifier:concatenate; 194, argument_list; 194, 195; 194, 206; 195, list:[w_hyp, w_hyp_last_outcome[np.newaxis,:,:]]; 195, 196; 195, 197; 196, identifier:w_hyp; 197, subscript; 197, 198; 197, 199; 197, 202; 197, 204; 198, identifier:w_hyp_last_outcome; 199, attribute; 199, 200; 199, 201; 200, identifier:np; 201, identifier:newaxis; 202, slice; 202, 203; 203, colon; 204, slice; 204, 205; 205, colon; 206, keyword_argument; 206, 207; 206, 208; 207, identifier:axis; 208, integer:0; 209, comment; 210, comment; 211, comment; 212, comment; 213, expression_statement; 213, 214; 214, assignment; 214, 215; 214, 216; 215, identifier:KLD; 216, call; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:np; 219, identifier:sum; 220, argument_list; 220, 221; 220, 233; 221, binary_operator:*; 221, 222; 221, 223; 222, identifier:w_hyp; 223, call; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:np; 226, identifier:log; 227, argument_list; 227, 228; 228, binary_operator:/; 228, 229; 228, 230; 229, identifier:w_hyp; 230, attribute; 230, 231; 230, 232; 231, identifier:self; 232, identifier:particle_weights; 233, keyword_argument; 233, 234; 233, 235; 234, identifier:axis; 235, integer:2; 236, comment; 237, return_statement; 237, 238; 238, call; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:np; 241, identifier:sum; 242, argument_list; 242, 243; 242, 246; 243, binary_operator:*; 243, 244; 243, 245; 244, identifier:N; 245, identifier:KLD; 246, keyword_argument; 246, 247; 246, 248; 247, identifier:axis; 248, integer:0 | def expected_information_gain(self, expparams):
r"""
Calculates the expected information gain for each hypothetical experiment.
:param expparams: The experiments at which to compute expected
information gain.
:type expparams: :class:`~numpy.ndarray` of dtype given by the current
model's :attr:`~qinfer.abstract_model.Simulatable.expparams_dtype` property,
and of shape ``(n,)``
:return float: The expected information gain for each
hypothetical experiment in ``expparams``.
"""
# This is a special case of the KL divergence estimator (see below),
# in which the other distribution is guaranteed to share support.
# for models whose outcome number changes with experiment, we
# take the easy way out and for-loop over experiments
n_eps = expparams.size
if n_eps > 1 and not self.model.is_n_outcomes_constant:
risk = np.empty(n_eps)
for idx in range(n_eps):
risk[idx] = self.expected_information_gain(expparams[idx, np.newaxis])
return risk
# number of outcomes for the first experiment
os = self.model.domain(expparams[0,np.newaxis])[0].values
# compute the hypothetical weights, likelihoods and normalizations for
# every possible outcome and expparam
# the likelihood over outcomes should sum to 1, so don't compute for last outcome
w_hyp, L, N = self.hypothetical_update(
os[:-1],
expparams,
return_normalization=True,
return_likelihood=True
)
w_hyp_last_outcome = (1 - L.sum(axis=0)) * self.particle_weights[np.newaxis, :]
N = np.concatenate([N[:,:,0], np.sum(w_hyp_last_outcome[np.newaxis,:,:], axis=2)], axis=0)
w_hyp_last_outcome = w_hyp_last_outcome / N[-1,:,np.newaxis]
w_hyp = np.concatenate([w_hyp, w_hyp_last_outcome[np.newaxis,:,:]], axis=0)
# w_hyp.shape == (n_out, n_eps, n_particles)
# N.shape == (n_out, n_eps)
# compute the Kullback-Liebler divergence for every experiment and possible outcome
# KLD.shape == (n_out, n_eps)
KLD = np.sum(w_hyp * np.log(w_hyp / self.particle_weights), axis=2)
# return the expected KLD (ie expected info gain) for every experiment
return np.sum(N * KLD, axis=0) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:iter_actions; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 9; 5, 10; 5, 14; 5, 15; 5, 16; 5, 33; 5, 42; 5, 43; 5, 47; 5, 61; 5, 207; 5, 208; 5, 222; 6, expression_statement; 6, 7; 7, comment; 8, comment; 9, comment; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:ns; 13, string:'{urn:schemas-upnp-org:service-1-0}'; 14, comment; 15, comment; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:scpd_body; 19, attribute; 19, 20; 19, 32; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:requests; 23, identifier:get; 24, argument_list; 24, 25; 25, binary_operator:+; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:base_url; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:scpd_url; 32, identifier:content; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:tree; 36, call; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:XML; 39, identifier:fromstring; 40, argument_list; 40, 41; 41, identifier:scpd_body; 42, comment; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:vartypes; 46, dictionary; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:srvStateTables; 50, call; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:tree; 53, identifier:findall; 54, argument_list; 54, 55; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, string:'{}serviceStateTable'; 58, identifier:format; 59, argument_list; 59, 60; 60, identifier:ns; 61, for_statement; 61, 62; 61, 63; 61, 64; 62, identifier:srvStateTable; 63, identifier:srvStateTables; 64, block; 64, 65; 64, 79; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:statevars; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:srvStateTable; 71, identifier:findall; 72, argument_list; 72, 73; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, string:'{}stateVariable'; 76, identifier:format; 77, argument_list; 77, 78; 78, identifier:ns; 79, for_statement; 79, 80; 79, 81; 79, 82; 80, identifier:state; 81, identifier:statevars; 82, block; 82, 83; 82, 97; 82, 111; 82, 125; 82, 139; 82, 148; 82, 160; 82, 174; 82, 183; 82, 195; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:name; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:state; 89, identifier:findtext; 90, argument_list; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, string:'{}name'; 94, identifier:format; 95, argument_list; 95, 96; 96, identifier:ns; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:datatype; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:state; 103, identifier:findtext; 104, argument_list; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, string:'{}dataType'; 108, identifier:format; 109, argument_list; 109, 110; 110, identifier:ns; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:default; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:state; 117, identifier:findtext; 118, argument_list; 118, 119; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, string:'{}defaultValue'; 122, identifier:format; 123, argument_list; 123, 124; 124, identifier:ns; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:value_list_elt; 128, call; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:state; 131, identifier:find; 132, argument_list; 132, 133; 133, call; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, string:'{}allowedValueList'; 136, identifier:format; 137, argument_list; 137, 138; 138, identifier:ns; 139, if_statement; 139, 140; 139, 143; 140, comparison_operator:is; 140, 141; 140, 142; 141, identifier:value_list_elt; 142, None; 143, block; 143, 144; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:value_list_elt; 147, tuple; 148, expression_statement; 148, 149; 149, assignment; 149, 150; 149, 151; 150, identifier:value_list; 151, boolean_operator:or; 151, 152; 151, 159; 152, list_comprehension; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:item; 155, identifier:text; 156, for_in_clause; 156, 157; 156, 158; 157, identifier:item; 158, identifier:value_list_elt; 159, None; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:value_range_elt; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:state; 166, identifier:find; 167, argument_list; 167, 168; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, string:'{}allowedValueRange'; 171, identifier:format; 172, argument_list; 172, 173; 173, identifier:ns; 174, if_statement; 174, 175; 174, 178; 175, comparison_operator:is; 175, 176; 175, 177; 176, identifier:value_range_elt; 177, None; 178, block; 178, 179; 179, expression_statement; 179, 180; 180, assignment; 180, 181; 180, 182; 181, identifier:value_range_elt; 182, tuple; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 186; 185, identifier:value_range; 186, boolean_operator:or; 186, 187; 186, 194; 187, list_comprehension; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:item; 190, identifier:text; 191, for_in_clause; 191, 192; 191, 193; 192, identifier:item; 193, identifier:value_range_elt; 194, None; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 200; 197, subscript; 197, 198; 197, 199; 198, identifier:vartypes; 199, identifier:name; 200, call; 200, 201; 200, 202; 201, identifier:Vartype; 202, argument_list; 202, 203; 202, 204; 202, 205; 202, 206; 203, identifier:datatype; 204, identifier:default; 205, identifier:value_list; 206, identifier:value_range; 207, comment; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 211; 210, identifier:actionLists; 211, call; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:tree; 214, identifier:findall; 215, argument_list; 215, 216; 216, call; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, string:'{}actionList'; 219, identifier:format; 220, argument_list; 220, 221; 221, identifier:ns; 222, for_statement; 222, 223; 222, 224; 222, 225; 223, identifier:actionList; 224, identifier:actionLists; 225, block; 225, 226; 225, 240; 226, expression_statement; 226, 227; 227, assignment; 227, 228; 227, 229; 228, identifier:actions; 229, call; 229, 230; 229, 233; 230, attribute; 230, 231; 230, 232; 231, identifier:actionList; 232, identifier:findall; 233, argument_list; 233, 234; 234, call; 234, 235; 234, 238; 235, attribute; 235, 236; 235, 237; 236, string:'{}action'; 237, identifier:format; 238, argument_list; 238, 239; 239, identifier:ns; 240, for_statement; 240, 241; 240, 242; 240, 243; 241, identifier:i; 242, identifier:actions; 243, block; 243, 244; 243, 258; 243, 272; 244, expression_statement; 244, 245; 245, assignment; 245, 246; 245, 247; 246, identifier:action_name; 247, call; 247, 248; 247, 251; 248, attribute; 248, 249; 248, 250; 249, identifier:i; 250, identifier:findtext; 251, argument_list; 251, 252; 252, call; 252, 253; 252, 256; 253, attribute; 253, 254; 253, 255; 254, string:'{}name'; 255, identifier:format; 256, argument_list; 256, 257; 257, identifier:ns; 258, expression_statement; 258, 259; 259, assignment; 259, 260; 259, 261; 260, identifier:argLists; 261, call; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:i; 264, identifier:findall; 265, argument_list; 265, 266; 266, call; 266, 267; 266, 270; 267, attribute; 267, 268; 267, 269; 268, string:'{}argumentList'; 269, identifier:format; 270, argument_list; 270, 271; 271, identifier:ns; 272, for_statement; 272, 273; 272, 274; 272, 275; 273, identifier:argList; 274, identifier:argLists; 275, block; 275, 276; 275, 290; 275, 294; 275, 298; 275, 379; 276, expression_statement; 276, 277; 277, assignment; 277, 278; 277, 279; 278, identifier:args_iter; 279, call; 279, 280; 279, 283; 280, attribute; 280, 281; 280, 282; 281, identifier:argList; 282, identifier:findall; 283, argument_list; 283, 284; 284, call; 284, 285; 284, 288; 285, attribute; 285, 286; 285, 287; 286, string:'{}argument'; 287, identifier:format; 288, argument_list; 288, 289; 289, identifier:ns; 290, expression_statement; 290, 291; 291, assignment; 291, 292; 291, 293; 292, identifier:in_args; 293, list:[]; 294, expression_statement; 294, 295; 295, assignment; 295, 296; 295, 297; 296, identifier:out_args; 297, list:[]; 298, for_statement; 298, 299; 298, 300; 298, 301; 299, identifier:arg; 300, identifier:args_iter; 301, block; 301, 302; 301, 316; 301, 330; 301, 344; 301, 350; 302, expression_statement; 302, 303; 303, assignment; 303, 304; 303, 305; 304, identifier:arg_name; 305, call; 305, 306; 305, 309; 306, attribute; 306, 307; 306, 308; 307, identifier:arg; 308, identifier:findtext; 309, argument_list; 309, 310; 310, call; 310, 311; 310, 314; 311, attribute; 311, 312; 311, 313; 312, string:'{}name'; 313, identifier:format; 314, argument_list; 314, 315; 315, identifier:ns; 316, expression_statement; 316, 317; 317, assignment; 317, 318; 317, 319; 318, identifier:direction; 319, call; 319, 320; 319, 323; 320, attribute; 320, 321; 320, 322; 321, identifier:arg; 322, identifier:findtext; 323, argument_list; 323, 324; 324, call; 324, 325; 324, 328; 325, attribute; 325, 326; 325, 327; 326, string:'{}direction'; 327, identifier:format; 328, argument_list; 328, 329; 329, identifier:ns; 330, expression_statement; 330, 331; 331, assignment; 331, 332; 331, 333; 332, identifier:related_variable; 333, call; 333, 334; 333, 337; 334, attribute; 334, 335; 334, 336; 335, identifier:arg; 336, identifier:findtext; 337, argument_list; 337, 338; 338, call; 338, 339; 338, 342; 339, attribute; 339, 340; 339, 341; 340, string:'{}relatedStateVariable'; 341, identifier:format; 342, argument_list; 342, 343; 343, identifier:ns; 344, expression_statement; 344, 345; 345, assignment; 345, 346; 345, 347; 346, identifier:vartype; 347, subscript; 347, 348; 347, 349; 348, identifier:vartypes; 349, identifier:related_variable; 350, if_statement; 350, 351; 350, 354; 350, 366; 351, comparison_operator:==; 351, 352; 351, 353; 352, identifier:direction; 353, string:"in"; 354, block; 354, 355; 355, expression_statement; 355, 356; 356, call; 356, 357; 356, 360; 357, attribute; 357, 358; 357, 359; 358, identifier:in_args; 359, identifier:append; 360, argument_list; 360, 361; 361, call; 361, 362; 361, 363; 362, identifier:Argument; 363, argument_list; 363, 364; 363, 365; 364, identifier:arg_name; 365, identifier:vartype; 366, else_clause; 366, 367; 367, block; 367, 368; 368, expression_statement; 368, 369; 369, call; 369, 370; 369, 373; 370, attribute; 370, 371; 370, 372; 371, identifier:out_args; 372, identifier:append; 373, argument_list; 373, 374; 374, call; 374, 375; 374, 376; 375, identifier:Argument; 376, argument_list; 376, 377; 376, 378; 377, identifier:arg_name; 378, identifier:vartype; 379, expression_statement; 379, 380; 380, yield; 380, 381; 381, call; 381, 382; 381, 383; 382, identifier:Action; 383, argument_list; 383, 384; 383, 385; 383, 386; 384, identifier:action_name; 385, identifier:in_args; 386, identifier:out_args | def iter_actions(self):
"""Yield the service's actions with their arguments.
Yields:
`Action`: the next action.
Each action is an Action namedtuple, consisting of action_name
(a string), in_args (a list of Argument namedtuples consisting of name
and argtype), and out_args (ditto), eg::
Action(
name='SetFormat',
in_args=[
Argument(name='DesiredTimeFormat', vartype=<Vartype>),
Argument(name='DesiredDateFormat', vartype=<Vartype>)],
out_args=[]
)
"""
# pylint: disable=too-many-locals
# pylint: disable=invalid-name
ns = '{urn:schemas-upnp-org:service-1-0}'
# get the scpd body as bytes, and feed directly to elementtree
# which likes to receive bytes
scpd_body = requests.get(self.base_url + self.scpd_url).content
tree = XML.fromstring(scpd_body)
# parse the state variables to get the relevant variable types
vartypes = {}
srvStateTables = tree.findall('{}serviceStateTable'.format(ns))
for srvStateTable in srvStateTables:
statevars = srvStateTable.findall('{}stateVariable'.format(ns))
for state in statevars:
name = state.findtext('{}name'.format(ns))
datatype = state.findtext('{}dataType'.format(ns))
default = state.findtext('{}defaultValue'.format(ns))
value_list_elt = state.find('{}allowedValueList'.format(ns))
if value_list_elt is None:
value_list_elt = ()
value_list = [item.text for item in value_list_elt] or None
value_range_elt = state.find('{}allowedValueRange'.format(ns))
if value_range_elt is None:
value_range_elt = ()
value_range = [item.text for item in value_range_elt] or None
vartypes[name] = Vartype(datatype, default, value_list,
value_range)
# find all the actions
actionLists = tree.findall('{}actionList'.format(ns))
for actionList in actionLists:
actions = actionList.findall('{}action'.format(ns))
for i in actions:
action_name = i.findtext('{}name'.format(ns))
argLists = i.findall('{}argumentList'.format(ns))
for argList in argLists:
args_iter = argList.findall('{}argument'.format(ns))
in_args = []
out_args = []
for arg in args_iter:
arg_name = arg.findtext('{}name'.format(ns))
direction = arg.findtext('{}direction'.format(ns))
related_variable = arg.findtext(
'{}relatedStateVariable'.format(ns))
vartype = vartypes[related_variable]
if direction == "in":
in_args.append(Argument(arg_name, vartype))
else:
out_args.append(Argument(arg_name, vartype))
yield Action(action_name, in_args, out_args) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:parse_event_xml; 3, parameters; 3, 4; 4, identifier:xml_event; 5, block; 5, 6; 5, 8; 5, 12; 5, 21; 5, 22; 5, 23; 5, 32; 5, 309; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:result; 11, dictionary; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:tree; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:XML; 18, identifier:fromstring; 19, argument_list; 19, 20; 20, identifier:xml_event; 21, comment; 22, comment; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:properties; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:tree; 29, identifier:findall; 30, argument_list; 30, 31; 31, string:'{urn:schemas-upnp-org:event-1-0}property'; 32, for_statement; 32, 33; 32, 34; 32, 35; 32, 36; 33, identifier:prop; 34, identifier:properties; 35, comment; 36, block; 36, 37; 37, for_statement; 37, 38; 37, 39; 37, 40; 37, 41; 37, 42; 37, 43; 37, 44; 38, identifier:variable; 39, identifier:prop; 40, comment; 41, comment; 42, comment; 43, comment; 44, block; 44, 45; 45, if_statement; 45, 46; 45, 51; 45, 294; 46, comparison_operator:==; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:variable; 49, identifier:tag; 50, string:"LastChange"; 51, block; 51, 52; 51, 68; 51, 69; 51, 70; 51, 71; 51, 72; 51, 73; 51, 74; 51, 83; 51, 97; 51, 111; 51, 112; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:last_change_tree; 55, call; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:XML; 58, identifier:fromstring; 59, argument_list; 59, 60; 60, call; 60, 61; 60, 66; 61, attribute; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:variable; 64, identifier:text; 65, identifier:encode; 66, argument_list; 66, 67; 67, string:'utf-8'; 68, comment; 69, comment; 70, comment; 71, comment; 72, comment; 73, comment; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:instance; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:last_change_tree; 80, identifier:find; 81, argument_list; 81, 82; 82, string:"{urn:schemas-upnp-org:metadata-1-0/AVT/}InstanceID"; 83, if_statement; 83, 84; 83, 87; 84, comparison_operator:is; 84, 85; 84, 86; 85, identifier:instance; 86, None; 87, block; 87, 88; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:instance; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:last_change_tree; 94, identifier:find; 95, argument_list; 95, 96; 96, string:"{urn:schemas-upnp-org:metadata-1-0/RCS/}InstanceID"; 97, if_statement; 97, 98; 97, 101; 98, comparison_operator:is; 98, 99; 98, 100; 99, identifier:instance; 100, None; 101, block; 101, 102; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 105; 104, identifier:instance; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:last_change_tree; 108, identifier:find; 109, argument_list; 109, 110; 110, string:"{urn:schemas-sonos-com:metadata-1-0/Queue/}QueueID"; 111, comment; 112, for_statement; 112, 113; 112, 114; 112, 115; 113, identifier:last_change_var; 114, identifier:instance; 115, block; 115, 116; 115, 122; 115, 123; 115, 143; 115, 144; 115, 151; 115, 152; 115, 153; 115, 154; 115, 155; 115, 156; 115, 157; 115, 158; 115, 167; 115, 178; 115, 179; 115, 180; 115, 248; 115, 257; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:tag; 119, attribute; 119, 120; 119, 121; 120, identifier:last_change_var; 121, identifier:tag; 122, comment; 123, if_statement; 123, 124; 123, 130; 124, call; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:tag; 127, identifier:startswith; 128, argument_list; 128, 129; 129, string:'{'; 130, block; 130, 131; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:tag; 134, subscript; 134, 135; 134, 142; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:tag; 138, identifier:split; 139, argument_list; 139, 140; 139, 141; 140, string:'}'; 141, integer:1; 142, integer:1; 143, comment; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:tag; 147, call; 147, 148; 147, 149; 148, identifier:camel_to_underscore; 149, argument_list; 149, 150; 150, identifier:tag; 151, comment; 152, comment; 153, comment; 154, comment; 155, comment; 156, comment; 157, comment; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 161; 160, identifier:value; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:last_change_var; 164, identifier:get; 165, argument_list; 165, 166; 166, string:'val'; 167, if_statement; 167, 168; 167, 171; 168, comparison_operator:is; 168, 169; 168, 170; 169, identifier:value; 170, None; 171, block; 171, 172; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:value; 175, attribute; 175, 176; 175, 177; 176, identifier:last_change_var; 177, identifier:text; 178, comment; 179, comment; 180, if_statement; 180, 181; 180, 187; 180, 188; 180, 189; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:value; 184, identifier:startswith; 185, argument_list; 185, 186; 186, string:'<DIDL-Lite'; 187, comment; 188, comment; 189, block; 189, 190; 190, try_statement; 190, 191; 190, 210; 191, block; 191, 192; 191, 199; 191, 204; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 195; 194, identifier:didl; 195, call; 195, 196; 195, 197; 196, identifier:from_didl_string; 197, argument_list; 197, 198; 198, identifier:value; 199, if_statement; 199, 200; 199, 202; 200, not_operator; 200, 201; 201, identifier:didl; 202, block; 202, 203; 203, continue_statement; 204, expression_statement; 204, 205; 205, assignment; 205, 206; 205, 207; 206, identifier:value; 207, subscript; 207, 208; 207, 209; 208, identifier:didl; 209, integer:0; 210, except_clause; 210, 211; 210, 215; 211, as_pattern; 211, 212; 211, 213; 212, identifier:SoCoException; 213, as_pattern_target; 213, 214; 214, identifier:original_exception; 215, block; 215, 216; 215, 232; 215, 241; 216, expression_statement; 216, 217; 217, call; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:log; 220, identifier:debug; 221, argument_list; 221, 222; 221, 227; 221, 228; 222, concatenated_string; 222, 223; 222, 224; 222, 225; 222, 226; 223, string:"Event contains illegal metadata"; 224, string:"for '%s'.\n"; 225, string:"Error message: '%s'\n"; 226, string:"The result will be a SoCoFault."; 227, identifier:tag; 228, call; 228, 229; 228, 230; 229, identifier:str; 230, argument_list; 230, 231; 231, identifier:original_exception; 232, expression_statement; 232, 233; 233, assignment; 233, 234; 233, 235; 234, identifier:event_parse_exception; 235, call; 235, 236; 235, 237; 236, identifier:EventParseException; 237, argument_list; 237, 238; 237, 239; 237, 240; 238, identifier:tag; 239, identifier:value; 240, identifier:original_exception; 241, expression_statement; 241, 242; 242, assignment; 242, 243; 242, 244; 243, identifier:value; 244, call; 244, 245; 244, 246; 245, identifier:SoCoFault; 246, argument_list; 246, 247; 247, identifier:event_parse_exception; 248, expression_statement; 248, 249; 249, assignment; 249, 250; 249, 251; 250, identifier:channel; 251, call; 251, 252; 251, 255; 252, attribute; 252, 253; 252, 254; 253, identifier:last_change_var; 254, identifier:get; 255, argument_list; 255, 256; 256, string:'channel'; 257, if_statement; 257, 258; 257, 261; 257, 286; 258, comparison_operator:is; 258, 259; 258, 260; 259, identifier:channel; 260, None; 261, block; 261, 262; 261, 278; 262, if_statement; 262, 263; 262, 271; 263, comparison_operator:is; 263, 264; 263, 270; 264, call; 264, 265; 264, 268; 265, attribute; 265, 266; 265, 267; 266, identifier:result; 267, identifier:get; 268, argument_list; 268, 269; 269, identifier:tag; 270, None; 271, block; 271, 272; 272, expression_statement; 272, 273; 273, assignment; 273, 274; 273, 277; 274, subscript; 274, 275; 274, 276; 275, identifier:result; 276, identifier:tag; 277, dictionary; 278, expression_statement; 278, 279; 279, assignment; 279, 280; 279, 285; 280, subscript; 280, 281; 280, 284; 281, subscript; 281, 282; 281, 283; 282, identifier:result; 283, identifier:tag; 284, identifier:channel; 285, identifier:value; 286, else_clause; 286, 287; 287, block; 287, 288; 288, expression_statement; 288, 289; 289, assignment; 289, 290; 289, 293; 290, subscript; 290, 291; 290, 292; 291, identifier:result; 292, identifier:tag; 293, identifier:value; 294, else_clause; 294, 295; 295, block; 295, 296; 296, expression_statement; 296, 297; 297, assignment; 297, 298; 297, 306; 298, subscript; 298, 299; 298, 300; 299, identifier:result; 300, call; 300, 301; 300, 302; 301, identifier:camel_to_underscore; 302, argument_list; 302, 303; 303, attribute; 303, 304; 303, 305; 304, identifier:variable; 305, identifier:tag; 306, attribute; 306, 307; 306, 308; 307, identifier:variable; 308, identifier:text; 309, return_statement; 309, 310; 310, identifier:result | def parse_event_xml(xml_event):
"""Parse the body of a UPnP event.
Args:
xml_event (bytes): bytes containing the body of the event encoded
with utf-8.
Returns:
dict: A dict with keys representing the evented variables. The
relevant value will usually be a string representation of the
variable's value, but may on occasion be:
* a dict (eg when the volume changes, the value will itself be a
dict containing the volume for each channel:
:code:`{'Volume': {'LF': '100', 'RF': '100', 'Master': '36'}}`)
* an instance of a `DidlObject` subclass (eg if it represents
track metadata).
* a `SoCoFault` (if a variable contains illegal metadata)
Example:
Run this code, and change your volume, tracks etc::
from __future__ import print_function
try:
from queue import Empty
except: # Py2.7
from Queue import Empty
import soco
from pprint import pprint
from soco.events import event_listener
# pick a device at random
device = soco.discover().pop()
print (device.player_name)
sub = device.renderingControl.subscribe()
sub2 = device.avTransport.subscribe()
while True:
try:
event = sub.events.get(timeout=0.5)
pprint (event.variables)
except Empty:
pass
try:
event = sub2.events.get(timeout=0.5)
pprint (event.variables)
except Empty:
pass
except KeyboardInterrupt:
sub.unsubscribe()
sub2.unsubscribe()
event_listener.stop()
break
"""
result = {}
tree = XML.fromstring(xml_event)
# property values are just under the propertyset, which
# uses this namespace
properties = tree.findall(
'{urn:schemas-upnp-org:event-1-0}property')
for prop in properties: # pylint: disable=too-many-nested-blocks
for variable in prop:
# Special handling for a LastChange event specially. For details on
# LastChange events, see
# http://upnp.org/specs/av/UPnP-av-RenderingControl-v1-Service.pdf
# and http://upnp.org/specs/av/UPnP-av-AVTransport-v1-Service.pdf
if variable.tag == "LastChange":
last_change_tree = XML.fromstring(
variable.text.encode('utf-8'))
# We assume there is only one InstanceID tag. This is true for
# Sonos, as far as we know.
# InstanceID can be in one of two namespaces, depending on
# whether we are looking at an avTransport event, a
# renderingControl event, or a Queue event
# (there, it is named QueueID)
instance = last_change_tree.find(
"{urn:schemas-upnp-org:metadata-1-0/AVT/}InstanceID")
if instance is None:
instance = last_change_tree.find(
"{urn:schemas-upnp-org:metadata-1-0/RCS/}InstanceID")
if instance is None:
instance = last_change_tree.find(
"{urn:schemas-sonos-com:metadata-1-0/Queue/}QueueID")
# Look at each variable within the LastChange event
for last_change_var in instance:
tag = last_change_var.tag
# Remove any namespaces from the tags
if tag.startswith('{'):
tag = tag.split('}', 1)[1]
# Un-camel case it
tag = camel_to_underscore(tag)
# Now extract the relevant value for the variable.
# The UPnP specs suggest that the value of any variable
# evented via a LastChange Event will be in the 'val'
# attribute, but audio related variables may also have a
# 'channel' attribute. In addition, it seems that Sonos
# sometimes uses a text value instead: see
# http://forums.sonos.com/showthread.php?t=34663
value = last_change_var.get('val')
if value is None:
value = last_change_var.text
# If DIDL metadata is returned, convert it to a music
# library data structure
if value.startswith('<DIDL-Lite'):
# Wrap any parsing exception in a SoCoFault, so the
# user can handle it
try:
didl = from_didl_string(value)
if not didl:
continue
value = didl[0]
except SoCoException as original_exception:
log.debug("Event contains illegal metadata"
"for '%s'.\n"
"Error message: '%s'\n"
"The result will be a SoCoFault.",
tag, str(original_exception))
event_parse_exception = EventParseException(
tag, value, original_exception
)
value = SoCoFault(event_parse_exception)
channel = last_change_var.get('channel')
if channel is not None:
if result.get(tag) is None:
result[tag] = {}
result[tag][channel] = value
else:
result[tag] = value
else:
result[camel_to_underscore(variable.tag)] = variable.text
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_restore_coordinator; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 9; 5, 10; 5, 11; 5, 21; 5, 41; 5, 42; 5, 48; 5, 49; 6, expression_statement; 6, 7; 7, comment; 8, comment; 9, comment; 10, comment; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:transport_info; 14, call; 14, 15; 14, 20; 15, attribute; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:device; 19, identifier:get_current_transport_info; 20, argument_list; 21, if_statement; 21, 22; 21, 25; 22, comparison_operator:is; 22, 23; 22, 24; 23, identifier:transport_info; 24, None; 25, block; 25, 26; 26, if_statement; 26, 27; 26, 32; 27, comparison_operator:==; 27, 28; 27, 31; 28, subscript; 28, 29; 28, 30; 29, identifier:transport_info; 30, string:'current_transport_state'; 31, string:'PLAYING'; 32, block; 32, 33; 33, expression_statement; 33, 34; 34, call; 34, 35; 34, 40; 35, attribute; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:device; 39, identifier:pause; 40, argument_list; 41, comment; 42, expression_statement; 42, 43; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:_restore_queue; 47, argument_list; 48, comment; 49, if_statement; 49, 50; 49, 59; 49, 60; 49, 137; 49, 145; 50, boolean_operator:and; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:self; 53, identifier:is_playing_queue; 54, comparison_operator:>; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:playlist_position; 58, integer:0; 59, comment; 60, block; 60, 61; 60, 90; 60, 115; 60, 116; 60, 117; 60, 127; 61, if_statement; 61, 62; 61, 67; 61, 68; 61, 69; 61, 70; 61, 71; 62, comparison_operator:is; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:playlist_position; 66, None; 67, comment; 68, comment; 69, comment; 70, comment; 71, block; 71, 72; 71, 78; 72, expression_statement; 72, 73; 73, augmented_assignment:-=; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:self; 76, identifier:playlist_position; 77, integer:1; 78, expression_statement; 78, 79; 79, call; 79, 80; 79, 85; 80, attribute; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:self; 83, identifier:device; 84, identifier:play_from_queue; 85, argument_list; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:self; 88, identifier:playlist_position; 89, False; 90, if_statement; 90, 91; 90, 96; 91, comparison_operator:is; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:self; 94, identifier:track_position; 95, None; 96, block; 96, 97; 97, if_statement; 97, 98; 97, 103; 98, comparison_operator:!=; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:self; 101, identifier:track_position; 102, string:""; 103, block; 103, 104; 104, expression_statement; 104, 105; 105, call; 105, 106; 105, 111; 106, attribute; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:self; 109, identifier:device; 110, identifier:seek; 111, argument_list; 111, 112; 112, attribute; 112, 113; 112, 114; 113, identifier:self; 114, identifier:track_position; 115, comment; 116, comment; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 124; 119, attribute; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:self; 122, identifier:device; 123, identifier:play_mode; 124, attribute; 124, 125; 124, 126; 125, identifier:self; 126, identifier:play_mode; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 134; 129, attribute; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:self; 132, identifier:device; 133, identifier:cross_fade; 134, attribute; 134, 135; 134, 136; 135, identifier:self; 136, identifier:cross_fade; 137, elif_clause; 137, 138; 137, 141; 137, 142; 137, 143; 138, attribute; 138, 139; 138, 140; 139, identifier:self; 140, identifier:is_playing_cloud_queue; 141, comment; 142, comment; 143, block; 143, 144; 144, pass_statement; 145, else_clause; 145, 146; 145, 147; 145, 148; 146, comment; 147, comment; 148, block; 148, 149; 149, if_statement; 149, 150; 149, 155; 150, comparison_operator:!=; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:self; 153, identifier:media_uri; 154, string:""; 155, block; 155, 156; 156, expression_statement; 156, 157; 157, call; 157, 158; 157, 163; 158, attribute; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:self; 161, identifier:device; 162, identifier:play_uri; 163, argument_list; 163, 164; 163, 167; 163, 170; 164, attribute; 164, 165; 164, 166; 165, identifier:self; 166, identifier:media_uri; 167, attribute; 167, 168; 167, 169; 168, identifier:self; 169, identifier:media_metadata; 170, keyword_argument; 170, 171; 170, 172; 171, identifier:start; 172, False | def _restore_coordinator(self):
"""Do the coordinator-only part of the restore."""
# Start by ensuring that the speaker is paused as we don't want
# things all rolling back when we are changing them, as this could
# include things like audio
transport_info = self.device.get_current_transport_info()
if transport_info is not None:
if transport_info['current_transport_state'] == 'PLAYING':
self.device.pause()
# Check if the queue should be restored
self._restore_queue()
# Reinstate what was playing
if self.is_playing_queue and self.playlist_position > 0:
# was playing from playlist
if self.playlist_position is not None:
# The position in the playlist returned by
# get_current_track_info starts at 1, but when
# playing from playlist, the index starts at 0
# if position > 0:
self.playlist_position -= 1
self.device.play_from_queue(self.playlist_position, False)
if self.track_position is not None:
if self.track_position != "":
self.device.seek(self.track_position)
# reinstate track, position, play mode, cross fade
# Need to make sure there is a proper track selected first
self.device.play_mode = self.play_mode
self.device.cross_fade = self.cross_fade
elif self.is_playing_cloud_queue:
# was playing a cloud queue started by Alexa
# No way yet to re-start this so prevent it throwing an error!
pass
else:
# was playing a stream (radio station, file, or nothing)
# reinstate uri and meta data
if self.media_uri != "":
self.device.play_uri(
self.media_uri, self.media_metadata, start=False) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_loading_order; 3, parameters; 3, 4; 4, identifier:step_files; 5, block; 5, 6; 5, 8; 5, 12; 5, 16; 5, 20; 5, 124; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:tools; 11, list:[]; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:workflows; 15, list:[]; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:workflows_with_subworkflows; 19, list:[]; 20, for_statement; 20, 21; 20, 22; 20, 23; 20, 24; 21, identifier:f; 22, identifier:step_files; 23, comment; 24, block; 24, 25; 25, if_statement; 25, 26; 25, 39; 25, 47; 26, boolean_operator:or; 26, 27; 26, 33; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:f; 30, identifier:startswith; 31, argument_list; 31, 32; 32, string:'http://'; 33, call; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:f; 36, identifier:startswith; 37, argument_list; 37, 38; 38, string:'https://'; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:tools; 44, identifier:append; 45, argument_list; 45, 46; 46, identifier:f; 47, else_clause; 47, 48; 48, block; 48, 49; 48, 56; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:obj; 52, call; 52, 53; 52, 54; 53, identifier:load_yaml; 54, argument_list; 54, 55; 55, identifier:f; 56, if_statement; 56, 57; 56, 66; 56, 115; 57, comparison_operator:==; 57, 58; 57, 65; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:obj; 61, identifier:get; 62, argument_list; 62, 63; 62, 64; 63, string:'class'; 64, string:''; 65, string:'Workflow'; 66, block; 66, 67; 67, if_statement; 67, 68; 67, 75; 67, 106; 68, comparison_operator:in; 68, 69; 68, 70; 69, string:'requirements'; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:obj; 73, identifier:keys; 74, argument_list; 75, block; 75, 76; 75, 83; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 79; 78, identifier:subw; 79, dictionary; 79, 80; 80, pair; 80, 81; 80, 82; 81, string:'class'; 82, string:'SubworkflowFeatureRequirement'; 83, if_statement; 83, 84; 83, 89; 83, 97; 84, comparison_operator:in; 84, 85; 84, 86; 85, identifier:subw; 86, subscript; 86, 87; 86, 88; 87, identifier:obj; 88, string:'requirements'; 89, block; 89, 90; 90, expression_statement; 90, 91; 91, call; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:workflows_with_subworkflows; 94, identifier:append; 95, argument_list; 95, 96; 96, identifier:f; 97, else_clause; 97, 98; 98, block; 98, 99; 99, expression_statement; 99, 100; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:workflows; 103, identifier:append; 104, argument_list; 104, 105; 105, identifier:f; 106, else_clause; 106, 107; 107, block; 107, 108; 108, expression_statement; 108, 109; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:workflows; 112, identifier:append; 113, argument_list; 113, 114; 114, identifier:f; 115, else_clause; 115, 116; 116, block; 116, 117; 117, expression_statement; 117, 118; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:tools; 121, identifier:append; 122, argument_list; 122, 123; 123, identifier:f; 124, return_statement; 124, 125; 125, binary_operator:+; 125, 126; 125, 129; 126, binary_operator:+; 126, 127; 126, 128; 127, identifier:tools; 128, identifier:workflows; 129, identifier:workflows_with_subworkflows | def sort_loading_order(step_files):
"""Sort step files into correct loading order.
The correct loading order is first tools, then workflows without
subworkflows, and then workflows with subworkflows. This order is
required to avoid error messages when a working directory is used.
"""
tools = []
workflows = []
workflows_with_subworkflows = []
for f in step_files:
# assume that urls are tools
if f.startswith('http://') or f.startswith('https://'):
tools.append(f)
else:
obj = load_yaml(f)
if obj.get('class', '') == 'Workflow':
if 'requirements' in obj.keys():
subw = {'class': 'SubworkflowFeatureRequirement'}
if subw in obj['requirements']:
workflows_with_subworkflows.append(f)
else:
workflows.append(f)
else:
workflows.append(f)
else:
tools.append(f)
return tools + workflows + workflows_with_subworkflows |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:add_input; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, dictionary_splat_pattern; 5, 6; 6, identifier:kwargs; 7, block; 7, 8; 7, 10; 7, 16; 7, 57; 7, 61; 7, 67; 7, 83; 7, 99; 7, 113; 7, 122; 7, 215; 7, 221; 7, 238; 7, 239; 7, 252; 7, 253; 7, 254; 7, 278; 8, expression_statement; 8, 9; 9, comment; 10, expression_statement; 10, 11; 11, call; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:_closed; 15, argument_list; 16, function_definition; 16, 17; 16, 18; 16, 20; 17, function_name:_get_item; 18, parameters; 18, 19; 19, identifier:args; 20, block; 20, 21; 20, 23; 20, 32; 20, 40; 20, 55; 21, expression_statement; 21, 22; 22, comment; 23, if_statement; 23, 24; 23, 26; 24, not_operator; 24, 25; 25, identifier:args; 26, block; 26, 27; 27, raise_statement; 27, 28; 28, call; 28, 29; 28, 30; 29, identifier:ValueError; 30, argument_list; 30, 31; 31, string:"No parameter specified."; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:item; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:args; 38, identifier:popitem; 39, argument_list; 40, if_statement; 40, 41; 40, 42; 41, identifier:args; 42, block; 42, 43; 43, raise_statement; 43, 44; 44, call; 44, 45; 44, 46; 45, identifier:ValueError; 46, argument_list; 46, 47; 47, call; 47, 48; 47, 53; 48, attribute; 48, 49; 48, 52; 49, concatenated_string; 49, 50; 49, 51; 50, string:"Too many parameters, not clear what to do "; 51, string:"with {}"; 52, identifier:format; 53, argument_list; 53, 54; 54, identifier:kwargs; 55, return_statement; 55, 56; 56, identifier:item; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:symbols; 60, None; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:input_dict; 64, call; 64, 65; 64, 66; 65, identifier:CommentedMap; 66, argument_list; 67, if_statement; 67, 68; 67, 71; 68, comparison_operator:in; 68, 69; 68, 70; 69, string:'default'; 70, identifier:kwargs; 71, block; 71, 72; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 77; 74, subscript; 74, 75; 74, 76; 75, identifier:input_dict; 76, string:'default'; 77, call; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:kwargs; 80, identifier:pop; 81, argument_list; 81, 82; 82, string:'default'; 83, if_statement; 83, 84; 83, 87; 84, comparison_operator:in; 84, 85; 84, 86; 85, string:'label'; 86, identifier:kwargs; 87, block; 87, 88; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 93; 90, subscript; 90, 91; 90, 92; 91, identifier:input_dict; 92, string:'label'; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:kwargs; 96, identifier:pop; 97, argument_list; 97, 98; 98, string:'label'; 99, if_statement; 99, 100; 99, 103; 100, comparison_operator:in; 100, 101; 100, 102; 101, string:'symbols'; 102, identifier:kwargs; 103, block; 103, 104; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:symbols; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:kwargs; 110, identifier:pop; 111, argument_list; 111, 112; 112, string:'symbols'; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 118; 115, pattern_list; 115, 116; 115, 117; 116, identifier:name; 117, identifier:input_type; 118, call; 118, 119; 118, 120; 119, identifier:_get_item; 120, argument_list; 120, 121; 121, identifier:kwargs; 122, if_statement; 122, 123; 122, 126; 122, 199; 123, comparison_operator:==; 123, 124; 123, 125; 124, identifier:input_type; 125, string:'enum'; 126, block; 126, 127; 126, 133; 126, 139; 126, 140; 126, 150; 126, 151; 126, 161; 126, 162; 126, 175; 126, 176; 126, 187; 126, 193; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:typ; 130, call; 130, 131; 130, 132; 131, identifier:CommentedMap; 132, argument_list; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 138; 135, subscript; 135, 136; 135, 137; 136, identifier:typ; 137, string:'type'; 138, string:'enum'; 139, comment; 140, if_statement; 140, 141; 140, 144; 141, comparison_operator:is; 141, 142; 141, 143; 142, identifier:symbols; 143, None; 144, block; 144, 145; 145, raise_statement; 145, 146; 146, call; 146, 147; 146, 148; 147, identifier:ValueError; 148, argument_list; 148, 149; 149, string:"Please specify the enum's symbols."; 150, comment; 151, if_statement; 151, 152; 151, 155; 152, comparison_operator:==; 152, 153; 152, 154; 153, identifier:symbols; 154, list:[]; 155, block; 155, 156; 156, raise_statement; 156, 157; 157, call; 157, 158; 157, 159; 158, identifier:ValueError; 159, argument_list; 159, 160; 160, string:"The enum's symbols cannot be empty."; 161, comment; 162, if_statement; 162, 163; 162, 169; 163, comparison_operator:!=; 163, 164; 163, 168; 164, call; 164, 165; 164, 166; 165, identifier:type; 166, argument_list; 166, 167; 167, identifier:symbols; 168, identifier:list; 169, block; 169, 170; 170, raise_statement; 170, 171; 171, call; 171, 172; 171, 173; 172, identifier:ValueError; 173, argument_list; 173, 174; 174, string:'Symbols should be a list.'; 175, comment; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:symbols; 179, list_comprehension; 179, 180; 179, 184; 180, call; 180, 181; 180, 182; 181, identifier:str; 182, argument_list; 182, 183; 183, identifier:s; 184, for_in_clause; 184, 185; 184, 186; 185, identifier:s; 186, identifier:symbols; 187, expression_statement; 187, 188; 188, assignment; 188, 189; 188, 192; 189, subscript; 189, 190; 189, 191; 190, identifier:typ; 191, string:'symbols'; 192, identifier:symbols; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 198; 195, subscript; 195, 196; 195, 197; 196, identifier:input_dict; 197, string:'type'; 198, identifier:typ; 199, else_clause; 199, 200; 199, 201; 199, 202; 200, comment; 201, comment; 202, block; 202, 203; 203, if_statement; 203, 204; 203, 208; 204, call; 204, 205; 204, 206; 205, identifier:bool; 206, argument_list; 206, 207; 207, identifier:input_dict; 208, block; 208, 209; 209, expression_statement; 209, 210; 210, assignment; 210, 211; 210, 214; 211, subscript; 211, 212; 211, 213; 212, identifier:input_dict; 213, string:'type'; 214, identifier:input_type; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 218; 217, identifier:msg; 218, binary_operator:+; 218, 219; 218, 220; 219, string:'"{}" is already used as a workflow input. Please use a '; 220, string:'different name.'; 221, if_statement; 221, 222; 221, 227; 222, comparison_operator:in; 222, 223; 222, 224; 223, identifier:name; 224, attribute; 224, 225; 224, 226; 225, identifier:self; 226, identifier:wf_inputs; 227, block; 227, 228; 228, raise_statement; 228, 229; 229, call; 229, 230; 229, 231; 230, identifier:ValueError; 231, argument_list; 231, 232; 232, call; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:msg; 235, identifier:format; 236, argument_list; 236, 237; 237, identifier:name; 238, comment; 239, if_statement; 239, 240; 239, 245; 240, call; 240, 241; 240, 242; 241, identifier:isinstance; 242, argument_list; 242, 243; 242, 244; 243, identifier:input_type; 244, identifier:dict; 245, block; 245, 246; 246, expression_statement; 246, 247; 247, assignment; 247, 248; 247, 251; 248, subscript; 248, 249; 248, 250; 249, identifier:input_dict; 250, string:'type'; 251, identifier:input_type; 252, comment; 253, comment; 254, if_statement; 254, 255; 254, 259; 254, 268; 255, call; 255, 256; 255, 257; 256, identifier:bool; 257, argument_list; 257, 258; 258, identifier:input_dict; 259, block; 259, 260; 260, expression_statement; 260, 261; 261, assignment; 261, 262; 261, 267; 262, subscript; 262, 263; 262, 266; 263, attribute; 263, 264; 263, 265; 264, identifier:self; 265, identifier:wf_inputs; 266, identifier:name; 267, identifier:input_dict; 268, else_clause; 268, 269; 269, block; 269, 270; 270, expression_statement; 270, 271; 271, assignment; 271, 272; 271, 277; 272, subscript; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:self; 275, identifier:wf_inputs; 276, identifier:name; 277, identifier:input_type; 278, return_statement; 278, 279; 279, call; 279, 280; 279, 281; 280, identifier:Reference; 281, argument_list; 281, 282; 282, keyword_argument; 282, 283; 282, 284; 283, identifier:input_name; 284, identifier:name | def add_input(self, **kwargs):
"""Add workflow input.
Args:
kwargs (dict): A dict with a `name: type` item
and optionally a `default: value` item, where name is the
name (id) of the workflow input (e.g., `dir_in`) and type is
the type of the input (e.g., `'Directory'`).
The type of input parameter can be learned from
`step.inputs(step_name=input_name)`.
Returns:
inputname
Raises:
ValueError: No or multiple parameter(s) have been specified.
"""
self._closed()
def _get_item(args):
"""Get a single item from args."""
if not args:
raise ValueError("No parameter specified.")
item = args.popitem()
if args:
raise ValueError("Too many parameters, not clear what to do "
"with {}".format(kwargs))
return item
symbols = None
input_dict = CommentedMap()
if 'default' in kwargs:
input_dict['default'] = kwargs.pop('default')
if 'label' in kwargs:
input_dict['label'] = kwargs.pop('label')
if 'symbols' in kwargs:
symbols = kwargs.pop('symbols')
name, input_type = _get_item(kwargs)
if input_type == 'enum':
typ = CommentedMap()
typ['type'] = 'enum'
# make sure symbols is set
if symbols is None:
raise ValueError("Please specify the enum's symbols.")
# make sure symbols is not empty
if symbols == []:
raise ValueError("The enum's symbols cannot be empty.")
# make sure the symbols are a list
if type(symbols) != list:
raise ValueError('Symbols should be a list.')
# make sure symbols is a list of strings
symbols = [str(s) for s in symbols]
typ['symbols'] = symbols
input_dict['type'] = typ
else:
# Set the 'type' if we can't use simple notation (because there is
# a default value or a label)
if bool(input_dict):
input_dict['type'] = input_type
msg = '"{}" is already used as a workflow input. Please use a ' +\
'different name.'
if name in self.wf_inputs:
raise ValueError(msg.format(name))
# Add 'type' for complex input types, so the user doesn't have to do it
if isinstance(input_type, dict):
input_dict['type'] = input_type
# Make sure we can use the notation without 'type' if the input allows
# it.
if bool(input_dict):
self.wf_inputs[name] = input_dict
else:
self.wf_inputs[name] = input_type
return Reference(input_name=name) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:to_obj; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:wd; 7, False; 8, default_parameter; 8, 9; 8, 10; 9, identifier:pack; 10, False; 11, default_parameter; 11, 12; 11, 13; 12, identifier:relpath; 13, None; 14, block; 14, 15; 14, 17; 14, 23; 14, 29; 14, 35; 14, 41; 14, 57; 14, 73; 14, 86; 14, 103; 14, 120; 14, 137; 14, 145; 14, 153; 14, 159; 14, 188; 14, 194; 15, expression_statement; 15, 16; 16, comment; 17, expression_statement; 17, 18; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:_closed; 22, argument_list; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:obj; 26, call; 26, 27; 26, 28; 27, identifier:CommentedMap; 28, argument_list; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 34; 31, subscript; 31, 32; 31, 33; 32, identifier:obj; 33, string:'cwlVersion'; 34, string:'v1.0'; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 40; 37, subscript; 37, 38; 37, 39; 38, identifier:obj; 39, string:'class'; 40, string:'Workflow'; 41, try_statement; 41, 42; 41, 51; 42, block; 42, 43; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 48; 45, subscript; 45, 46; 45, 47; 46, identifier:obj; 47, string:'doc'; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:documentation; 51, except_clause; 51, 52; 51, 55; 52, tuple; 52, 53; 52, 54; 53, identifier:AttributeError; 54, identifier:ValueError; 55, block; 55, 56; 56, pass_statement; 57, try_statement; 57, 58; 57, 67; 58, block; 58, 59; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 64; 61, subscript; 61, 62; 61, 63; 62, identifier:obj; 63, string:'label'; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:label; 67, except_clause; 67, 68; 67, 71; 68, tuple; 68, 69; 68, 70; 69, identifier:AttributeError; 70, identifier:ValueError; 71, block; 71, 72; 72, pass_statement; 73, if_statement; 73, 74; 73, 79; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:_has_requirements; 78, argument_list; 79, block; 79, 80; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 85; 82, subscript; 82, 83; 82, 84; 83, identifier:obj; 84, string:'requirements'; 85, list:[]; 86, if_statement; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:self; 89, identifier:has_workflow_step; 90, block; 90, 91; 91, expression_statement; 91, 92; 92, call; 92, 93; 92, 98; 93, attribute; 93, 94; 93, 97; 94, subscript; 94, 95; 94, 96; 95, identifier:obj; 96, string:'requirements'; 97, identifier:append; 98, argument_list; 98, 99; 99, dictionary; 99, 100; 100, pair; 100, 101; 100, 102; 101, string:'class'; 102, string:'SubworkflowFeatureRequirement'; 103, if_statement; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:self; 106, identifier:has_scatter_requirement; 107, block; 107, 108; 108, expression_statement; 108, 109; 109, call; 109, 110; 109, 115; 110, attribute; 110, 111; 110, 114; 111, subscript; 111, 112; 111, 113; 112, identifier:obj; 113, string:'requirements'; 114, identifier:append; 115, argument_list; 115, 116; 116, dictionary; 116, 117; 117, pair; 117, 118; 117, 119; 118, string:'class'; 119, string:'ScatterFeatureRequirement'; 120, if_statement; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:self; 123, identifier:has_multiple_inputs; 124, block; 124, 125; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 132; 127, attribute; 127, 128; 127, 131; 128, subscript; 128, 129; 128, 130; 129, identifier:obj; 130, string:'requirements'; 131, identifier:append; 132, argument_list; 132, 133; 133, dictionary; 133, 134; 134, pair; 134, 135; 134, 136; 135, string:'class'; 136, string:'MultipleInputFeatureRequirement'; 137, expression_statement; 137, 138; 138, assignment; 138, 139; 138, 142; 139, subscript; 139, 140; 139, 141; 140, identifier:obj; 141, string:'inputs'; 142, attribute; 142, 143; 142, 144; 143, identifier:self; 144, identifier:wf_inputs; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 150; 147, subscript; 147, 148; 147, 149; 148, identifier:obj; 149, string:'outputs'; 150, attribute; 150, 151; 150, 152; 151, identifier:self; 152, identifier:wf_outputs; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:steps_obj; 156, call; 156, 157; 156, 158; 157, identifier:CommentedMap; 158, argument_list; 159, for_statement; 159, 160; 159, 161; 159, 164; 160, identifier:key; 161, attribute; 161, 162; 161, 163; 162, identifier:self; 163, identifier:wf_steps; 164, block; 164, 165; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 170; 167, subscript; 167, 168; 167, 169; 168, identifier:steps_obj; 169, identifier:key; 170, call; 170, 171; 170, 178; 171, attribute; 171, 172; 171, 177; 172, subscript; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:self; 175, identifier:wf_steps; 176, identifier:key; 177, identifier:to_obj; 178, argument_list; 178, 179; 178, 182; 178, 185; 179, keyword_argument; 179, 180; 179, 181; 180, identifier:relpath; 181, identifier:relpath; 182, keyword_argument; 182, 183; 182, 184; 183, identifier:pack; 184, identifier:pack; 185, keyword_argument; 185, 186; 185, 187; 186, identifier:wd; 187, identifier:wd; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 193; 190, subscript; 190, 191; 190, 192; 191, identifier:obj; 192, string:'steps'; 193, identifier:steps_obj; 194, return_statement; 194, 195; 195, identifier:obj | def to_obj(self, wd=False, pack=False, relpath=None):
"""Return the created workflow as a dict.
The dict can be written to a yaml file.
Returns:
A yaml-compatible dict representing the workflow.
"""
self._closed()
obj = CommentedMap()
obj['cwlVersion'] = 'v1.0'
obj['class'] = 'Workflow'
try:
obj['doc'] = self.documentation
except (AttributeError, ValueError):
pass
try:
obj['label'] = self.label
except (AttributeError, ValueError):
pass
if self._has_requirements():
obj['requirements'] = []
if self.has_workflow_step:
obj['requirements'].append(
{'class': 'SubworkflowFeatureRequirement'})
if self.has_scatter_requirement:
obj['requirements'].append({'class': 'ScatterFeatureRequirement'})
if self.has_multiple_inputs:
obj['requirements'].append(
{'class': 'MultipleInputFeatureRequirement'})
obj['inputs'] = self.wf_inputs
obj['outputs'] = self.wf_outputs
steps_obj = CommentedMap()
for key in self.wf_steps:
steps_obj[key] = self.wf_steps[key].to_obj(relpath=relpath,
pack=pack,
wd=wd)
obj['steps'] = steps_obj
return obj |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:to_script; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:wf_name; 7, string:'wf'; 8, block; 8, 9; 8, 11; 8, 17; 8, 21; 8, 22; 8, 23; 8, 24; 8, 25; 8, 26; 8, 27; 8, 28; 8, 29; 8, 30; 8, 31; 8, 32; 8, 36; 8, 40; 8, 72; 8, 96; 8, 97; 8, 101; 8, 185; 8, 186; 8, 190; 8, 220; 8, 238; 9, expression_statement; 9, 10; 10, comment; 11, expression_statement; 11, 12; 12, call; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:_closed; 16, argument_list; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:script; 20, list:[]; 21, comment; 22, comment; 23, comment; 24, comment; 25, comment; 26, comment; 27, comment; 28, comment; 29, comment; 30, comment; 31, comment; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:params; 35, list:[]; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:returns; 39, list:[]; 40, for_statement; 40, 41; 40, 44; 40, 51; 41, pattern_list; 41, 42; 41, 43; 42, identifier:name; 43, identifier:typ; 44, call; 44, 45; 44, 50; 45, attribute; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:wf_inputs; 49, identifier:items; 50, argument_list; 51, block; 51, 52; 51, 65; 52, expression_statement; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:params; 56, identifier:append; 57, argument_list; 57, 58; 58, call; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, string:'{}=\'{}\''; 61, identifier:format; 62, argument_list; 62, 63; 62, 64; 63, identifier:name; 64, identifier:typ; 65, expression_statement; 65, 66; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:returns; 69, identifier:append; 70, argument_list; 70, 71; 71, identifier:name; 72, expression_statement; 72, 73; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:script; 76, identifier:append; 77, argument_list; 77, 78; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, string:'{} = {}.add_inputs({})'; 81, identifier:format; 82, argument_list; 82, 83; 82, 89; 82, 90; 83, call; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, string:', '; 86, identifier:join; 87, argument_list; 87, 88; 88, identifier:returns; 89, identifier:wf_name; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, string:', '; 93, identifier:join; 94, argument_list; 94, 95; 95, identifier:params; 96, comment; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:returns; 100, list:[]; 101, for_statement; 101, 102; 101, 105; 101, 112; 102, pattern_list; 102, 103; 102, 104; 103, identifier:name; 104, identifier:step; 105, call; 105, 106; 105, 111; 106, attribute; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:self; 109, identifier:wf_steps; 110, identifier:items; 111, argument_list; 112, block; 112, 113; 112, 119; 112, 135; 112, 160; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:pyname; 116, attribute; 116, 117; 116, 118; 117, identifier:step; 118, identifier:python_name; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:returns; 122, list_comprehension; 122, 123; 122, 130; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, string:'{}_{}'; 126, identifier:format; 127, argument_list; 127, 128; 127, 129; 128, identifier:pyname; 129, identifier:o; 130, for_in_clause; 130, 131; 130, 132; 131, identifier:o; 132, subscript; 132, 133; 132, 134; 133, identifier:step; 134, string:'out'; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:params; 138, list_comprehension; 138, 139; 138, 149; 139, call; 139, 140; 139, 143; 140, attribute; 140, 141; 140, 142; 141, string:'{}={}'; 142, identifier:format; 143, argument_list; 143, 144; 143, 145; 144, identifier:name; 145, call; 145, 146; 145, 147; 146, identifier:python_name; 147, argument_list; 147, 148; 148, identifier:param; 149, for_in_clause; 149, 150; 149, 153; 150, pattern_list; 150, 151; 150, 152; 151, identifier:name; 152, identifier:param; 153, call; 153, 154; 153, 159; 154, attribute; 154, 155; 154, 158; 155, subscript; 155, 156; 155, 157; 156, identifier:step; 157, string:'in'; 158, identifier:items; 159, argument_list; 160, expression_statement; 160, 161; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:script; 164, identifier:append; 165, argument_list; 165, 166; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, string:'{} = {}.{}({})'; 169, identifier:format; 170, argument_list; 170, 171; 170, 177; 170, 178; 170, 179; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, string:', '; 174, identifier:join; 175, argument_list; 175, 176; 176, identifier:returns; 177, identifier:wf_name; 178, identifier:pyname; 179, call; 179, 180; 179, 183; 180, attribute; 180, 181; 180, 182; 181, string:', '; 182, identifier:join; 183, argument_list; 183, 184; 184, identifier:params; 185, comment; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:params; 189, list:[]; 190, for_statement; 190, 191; 190, 194; 190, 201; 191, pattern_list; 191, 192; 191, 193; 192, identifier:name; 193, identifier:details; 194, call; 194, 195; 194, 200; 195, attribute; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:self; 198, identifier:wf_outputs; 199, identifier:items; 200, argument_list; 201, block; 201, 202; 202, expression_statement; 202, 203; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:params; 206, identifier:append; 207, argument_list; 207, 208; 208, call; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, string:'{}={}'; 211, identifier:format; 212, argument_list; 212, 213; 212, 214; 213, identifier:name; 214, call; 214, 215; 214, 216; 215, identifier:python_name; 216, argument_list; 216, 217; 217, subscript; 217, 218; 217, 219; 218, identifier:details; 219, string:'outputSource'; 220, expression_statement; 220, 221; 221, call; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:script; 224, identifier:append; 225, argument_list; 225, 226; 226, call; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, string:'{}.add_outputs({})'; 229, identifier:format; 230, argument_list; 230, 231; 230, 232; 231, identifier:wf_name; 232, call; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, string:', '; 235, identifier:join; 236, argument_list; 236, 237; 237, identifier:params; 238, return_statement; 238, 239; 239, call; 239, 240; 239, 243; 240, attribute; 240, 241; 240, 242; 241, string:'\n'; 242, identifier:join; 243, argument_list; 243, 244; 244, identifier:script | def to_script(self, wf_name='wf'):
"""Generated and print the scriptcwl script for the currunt workflow.
Args:
wf_name (str): string used for the WorkflowGenerator object in the
generated script (default: ``wf``).
"""
self._closed()
script = []
# Workflow documentation
# if self.documentation:
# if is_multiline(self.documentation):
# print('doc = """')
# print(self.documentation)
# print('"""')
# print('{}.set_documentation(doc)'.format(wf_name))
# else:
# print('{}.set_documentation(\'{}\')'.format(wf_name,
# self.documentation))
# Workflow inputs
params = []
returns = []
for name, typ in self.wf_inputs.items():
params.append('{}=\'{}\''.format(name, typ))
returns.append(name)
script.append('{} = {}.add_inputs({})'.format(
', '.join(returns), wf_name, ', '.join(params)))
# Workflow steps
returns = []
for name, step in self.wf_steps.items():
pyname = step.python_name
returns = ['{}_{}'.format(pyname, o) for o in step['out']]
params = ['{}={}'.format(name, python_name(param))
for name, param in step['in'].items()]
script.append('{} = {}.{}({})'.format(
', '.join(returns), wf_name, pyname, ', '.join(params)))
# Workflow outputs
params = []
for name, details in self.wf_outputs.items():
params.append('{}={}'.format(
name, python_name(details['outputSource'])))
script.append('{}.add_outputs({})'.format(wf_name, ', '.join(params)))
return '\n'.join(script) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 27; 2, function_name:save; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 4, identifier:self; 5, identifier:fname; 6, default_parameter; 6, 7; 6, 8; 7, identifier:mode; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:validate; 11, True; 12, default_parameter; 12, 13; 12, 14; 13, identifier:encoding; 14, string:'utf-8'; 15, default_parameter; 15, 16; 15, 17; 16, identifier:wd; 17, False; 18, default_parameter; 18, 19; 18, 20; 19, identifier:inline; 20, False; 21, default_parameter; 21, 22; 21, 23; 22, identifier:relative; 23, False; 24, default_parameter; 24, 25; 24, 26; 25, identifier:pack; 26, False; 27, block; 27, 28; 27, 30; 27, 36; 27, 87; 27, 96; 27, 122; 27, 131; 27, 149; 27, 167; 27, 191; 27, 219; 27, 243; 27, 256; 28, expression_statement; 28, 29; 29, comment; 30, expression_statement; 30, 31; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:_closed; 35, argument_list; 36, if_statement; 36, 37; 36, 40; 37, comparison_operator:is; 37, 38; 37, 39; 38, identifier:mode; 39, None; 40, block; 40, 41; 40, 45; 40, 66; 40, 79; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:mode; 44, string:'abs'; 45, if_statement; 45, 46; 45, 47; 45, 52; 45, 59; 46, identifier:pack; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:mode; 51, string:'pack'; 52, elif_clause; 52, 53; 52, 54; 53, identifier:wd; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:mode; 58, string:'wd'; 59, elif_clause; 59, 60; 59, 61; 60, identifier:relative; 61, block; 61, 62; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:mode; 65, string:'rel'; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:msg; 69, call; 69, 70; 69, 76; 70, attribute; 70, 71; 70, 75; 71, concatenated_string; 71, 72; 71, 73; 71, 74; 72, string:'Using deprecated save method. Please save the workflow '; 73, string:'with: wf.save(\'{}\', mode=\'{}\'). Redirecting to new '; 74, string:'save method.'; 75, identifier:format; 76, argument_list; 76, 77; 76, 78; 77, identifier:fname; 78, identifier:mode; 79, expression_statement; 79, 80; 80, call; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:warnings; 83, identifier:warn; 84, argument_list; 84, 85; 84, 86; 85, identifier:msg; 86, identifier:DeprecationWarning; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:modes; 90, tuple; 90, 91; 90, 92; 90, 93; 90, 94; 90, 95; 91, string:'rel'; 92, string:'abs'; 93, string:'wd'; 94, string:'inline'; 95, string:'pack'; 96, if_statement; 96, 97; 96, 100; 97, comparison_operator:not; 97, 98; 97, 99; 98, identifier:mode; 99, identifier:modes; 100, block; 100, 101; 100, 117; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:msg; 104, call; 104, 105; 104, 109; 105, attribute; 105, 106; 105, 107; 105, 108; 106, string:'Illegal mode "{}". Choose one of ({}).'; 107, line_continuation:\; 108, identifier:format; 109, argument_list; 109, 110; 109, 111; 110, identifier:mode; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, string:','; 114, identifier:join; 115, argument_list; 115, 116; 116, identifier:modes; 117, raise_statement; 117, 118; 118, call; 118, 119; 118, 120; 119, identifier:ValueError; 120, argument_list; 120, 121; 121, identifier:msg; 122, if_statement; 122, 123; 122, 124; 123, identifier:validate; 124, block; 124, 125; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:self; 129, identifier:validate; 130, argument_list; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:dirname; 134, call; 134, 135; 134, 140; 135, attribute; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:os; 138, identifier:path; 139, identifier:dirname; 140, argument_list; 140, 141; 141, call; 141, 142; 141, 147; 142, attribute; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:os; 145, identifier:path; 146, identifier:abspath; 147, argument_list; 147, 148; 148, identifier:fname; 149, if_statement; 149, 150; 149, 159; 150, not_operator; 150, 151; 151, call; 151, 152; 151, 157; 152, attribute; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:os; 155, identifier:path; 156, identifier:exists; 157, argument_list; 157, 158; 158, identifier:dirname; 159, block; 159, 160; 160, expression_statement; 160, 161; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:os; 164, identifier:makedirs; 165, argument_list; 165, 166; 166, identifier:dirname; 167, if_statement; 167, 168; 167, 171; 168, comparison_operator:==; 168, 169; 168, 170; 169, identifier:mode; 170, string:'inline'; 171, block; 171, 172; 171, 179; 171, 187; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:msg; 175, parenthesized_expression; 175, 176; 176, concatenated_string; 176, 177; 176, 178; 177, string:'Inline saving is deprecated. Please save the workflow '; 178, string:'using mode=\'pack\'. Setting mode to pack.'; 179, expression_statement; 179, 180; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:warnings; 183, identifier:warn; 184, argument_list; 184, 185; 184, 186; 185, identifier:msg; 186, identifier:DeprecationWarning; 187, expression_statement; 187, 188; 188, assignment; 188, 189; 188, 190; 189, identifier:mode; 190, string:'pack'; 191, if_statement; 191, 192; 191, 195; 192, comparison_operator:==; 192, 193; 192, 194; 193, identifier:mode; 194, string:'rel'; 195, block; 195, 196; 195, 200; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 199; 198, identifier:relpath; 199, identifier:dirname; 200, expression_statement; 200, 201; 201, call; 201, 202; 201, 203; 202, identifier:save_yaml; 203, argument_list; 203, 204; 203, 207; 203, 210; 203, 213; 203, 216; 204, keyword_argument; 204, 205; 204, 206; 205, identifier:fname; 206, identifier:fname; 207, keyword_argument; 207, 208; 207, 209; 208, identifier:wf; 209, identifier:self; 210, keyword_argument; 210, 211; 210, 212; 211, identifier:pack; 212, False; 213, keyword_argument; 213, 214; 213, 215; 214, identifier:relpath; 215, identifier:relpath; 216, keyword_argument; 216, 217; 216, 218; 217, identifier:wd; 218, False; 219, if_statement; 219, 220; 219, 223; 220, comparison_operator:==; 220, 221; 220, 222; 221, identifier:mode; 222, string:'abs'; 223, block; 223, 224; 224, expression_statement; 224, 225; 225, call; 225, 226; 225, 227; 226, identifier:save_yaml; 227, argument_list; 227, 228; 227, 231; 227, 234; 227, 237; 227, 240; 228, keyword_argument; 228, 229; 228, 230; 229, identifier:fname; 230, identifier:fname; 231, keyword_argument; 231, 232; 231, 233; 232, identifier:wf; 233, identifier:self; 234, keyword_argument; 234, 235; 234, 236; 235, identifier:pack; 236, False; 237, keyword_argument; 237, 238; 237, 239; 238, identifier:relpath; 239, None; 240, keyword_argument; 240, 241; 240, 242; 241, identifier:wd; 242, False; 243, if_statement; 243, 244; 243, 247; 244, comparison_operator:==; 244, 245; 244, 246; 245, identifier:mode; 246, string:'pack'; 247, block; 247, 248; 248, expression_statement; 248, 249; 249, call; 249, 250; 249, 253; 250, attribute; 250, 251; 250, 252; 251, identifier:self; 252, identifier:_pack; 253, argument_list; 253, 254; 253, 255; 254, identifier:fname; 255, identifier:encoding; 256, if_statement; 256, 257; 256, 260; 257, comparison_operator:==; 257, 258; 257, 259; 258, identifier:mode; 259, string:'wd'; 260, block; 260, 261; 261, if_statement; 261, 262; 261, 269; 261, 275; 262, comparison_operator:is; 262, 263; 262, 268; 263, call; 263, 264; 263, 267; 264, attribute; 264, 265; 264, 266; 265, identifier:self; 266, identifier:get_working_dir; 267, argument_list; 268, None; 269, block; 269, 270; 270, raise_statement; 270, 271; 271, call; 271, 272; 271, 273; 272, identifier:ValueError; 273, argument_list; 273, 274; 274, string:'Working directory not set.'; 275, else_clause; 275, 276; 275, 277; 276, comment; 277, block; 277, 278; 277, 289; 277, 303; 277, 322; 277, 323; 277, 324; 278, expression_statement; 278, 279; 279, assignment; 279, 280; 279, 281; 280, identifier:bn; 281, call; 281, 282; 281, 287; 282, attribute; 282, 283; 282, 286; 283, attribute; 283, 284; 283, 285; 284, identifier:os; 285, identifier:path; 286, identifier:basename; 287, argument_list; 287, 288; 288, identifier:fname; 289, expression_statement; 289, 290; 290, assignment; 290, 291; 290, 292; 291, identifier:wd_file; 292, call; 292, 293; 292, 298; 293, attribute; 293, 294; 293, 297; 294, attribute; 294, 295; 294, 296; 295, identifier:os; 296, identifier:path; 297, identifier:join; 298, argument_list; 298, 299; 298, 302; 299, attribute; 299, 300; 299, 301; 300, identifier:self; 301, identifier:working_dir; 302, identifier:bn; 303, expression_statement; 303, 304; 304, call; 304, 305; 304, 306; 305, identifier:save_yaml; 306, argument_list; 306, 307; 306, 310; 306, 313; 306, 316; 306, 319; 307, keyword_argument; 307, 308; 307, 309; 308, identifier:fname; 309, identifier:wd_file; 310, keyword_argument; 310, 311; 310, 312; 311, identifier:wf; 312, identifier:self; 313, keyword_argument; 313, 314; 313, 315; 314, identifier:pack; 315, False; 316, keyword_argument; 316, 317; 316, 318; 317, identifier:relpath; 318, None; 319, keyword_argument; 319, 320; 319, 321; 320, identifier:wd; 321, True; 322, comment; 323, comment; 324, try_statement; 324, 325; 324, 334; 325, block; 325, 326; 326, expression_statement; 326, 327; 327, call; 327, 328; 327, 331; 328, attribute; 328, 329; 328, 330; 329, identifier:shutil; 330, identifier:copy2; 331, argument_list; 331, 332; 331, 333; 332, identifier:wd_file; 333, identifier:fname; 334, except_clause; 334, 335; 334, 338; 335, attribute; 335, 336; 335, 337; 336, identifier:shutil; 337, identifier:Error; 338, block; 338, 339; 339, pass_statement | def save(self, fname, mode=None, validate=True, encoding='utf-8',
wd=False, inline=False, relative=False, pack=False):
"""Save the workflow to file.
Save the workflow to a CWL file that can be run with a CWL runner.
Args:
fname (str): file to save the workflow to.
mode (str): one of (rel, abs, wd, inline, pack)
encoding (str): file encoding to use (default: ``utf-8``).
"""
self._closed()
if mode is None:
mode = 'abs'
if pack:
mode = 'pack'
elif wd:
mode = 'wd'
elif relative:
mode = 'rel'
msg = 'Using deprecated save method. Please save the workflow ' \
'with: wf.save(\'{}\', mode=\'{}\'). Redirecting to new ' \
'save method.'.format(fname, mode)
warnings.warn(msg, DeprecationWarning)
modes = ('rel', 'abs', 'wd', 'inline', 'pack')
if mode not in modes:
msg = 'Illegal mode "{}". Choose one of ({}).'\
.format(mode, ','.join(modes))
raise ValueError(msg)
if validate:
self.validate()
dirname = os.path.dirname(os.path.abspath(fname))
if not os.path.exists(dirname):
os.makedirs(dirname)
if mode == 'inline':
msg = ('Inline saving is deprecated. Please save the workflow '
'using mode=\'pack\'. Setting mode to pack.')
warnings.warn(msg, DeprecationWarning)
mode = 'pack'
if mode == 'rel':
relpath = dirname
save_yaml(fname=fname, wf=self, pack=False, relpath=relpath,
wd=False)
if mode == 'abs':
save_yaml(fname=fname, wf=self, pack=False, relpath=None,
wd=False)
if mode == 'pack':
self._pack(fname, encoding)
if mode == 'wd':
if self.get_working_dir() is None:
raise ValueError('Working directory not set.')
else:
# save in working_dir
bn = os.path.basename(fname)
wd_file = os.path.join(self.working_dir, bn)
save_yaml(fname=wd_file, wf=self, pack=False, relpath=None,
wd=True)
# and copy workflow file to other location (as though all steps
# are in the same directory as the workflow)
try:
shutil.copy2(wd_file, fname)
except shutil.Error:
pass |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:get_snodas_ds; 3, parameters; 3, 4; 3, 5; 4, identifier:dem_dt; 5, default_parameter; 5, 6; 5, 7; 6, identifier:code; 7, integer:1036; 8, block; 8, 9; 8, 11; 8, 14; 8, 17; 8, 21; 8, 25; 8, 37; 8, 55; 8, 56; 8, 108; 8, 346; 9, expression_statement; 9, 10; 10, comment; 11, import_statement; 11, 12; 12, dotted_name; 12, 13; 13, identifier:tarfile; 14, import_statement; 14, 15; 15, dotted_name; 15, 16; 16, identifier:gzip; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:snodas_ds; 20, None; 21, expression_statement; 21, 22; 22, assignment; 22, 23; 22, 24; 23, identifier:snodas_url_str; 24, None; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:outdir; 28, call; 28, 29; 28, 34; 29, attribute; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:os; 32, identifier:path; 33, identifier:join; 34, argument_list; 34, 35; 34, 36; 35, identifier:datadir; 36, string:'snodas'; 37, if_statement; 37, 38; 37, 47; 38, not_operator; 38, 39; 39, call; 39, 40; 39, 45; 40, attribute; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:os; 43, identifier:path; 44, identifier:exists; 45, argument_list; 45, 46; 46, identifier:outdir; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:os; 52, identifier:makedirs; 53, argument_list; 53, 54; 54, identifier:outdir; 55, comment; 56, if_statement; 56, 57; 56, 74; 56, 83; 56, 101; 57, boolean_operator:and; 57, 58; 57, 66; 58, comparison_operator:>=; 58, 59; 58, 60; 59, identifier:dem_dt; 60, call; 60, 61; 60, 62; 61, identifier:datetime; 62, argument_list; 62, 63; 62, 64; 62, 65; 63, integer:2003; 64, integer:9; 65, integer:30; 66, comparison_operator:<; 66, 67; 66, 68; 67, identifier:dem_dt; 68, call; 68, 69; 68, 70; 69, identifier:datetime; 70, argument_list; 70, 71; 70, 72; 70, 73; 71, integer:2010; 72, integer:1; 73, integer:1; 74, block; 74, 75; 74, 79; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:snodas_url_str; 78, string:'ftp://sidads.colorado.edu/DATASETS/NOAA/G02158/masked/%Y/%m_%b/SNODAS_%Y%m%d.tar'; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 82; 81, identifier:tar_subfn_str_fmt; 82, string:'us_ssmv1%itS__T0001TTNATS%%Y%%m%%d05HP001.%s.gz'; 83, elif_clause; 83, 84; 83, 92; 84, comparison_operator:>=; 84, 85; 84, 86; 85, identifier:dem_dt; 86, call; 86, 87; 86, 88; 87, identifier:datetime; 88, argument_list; 88, 89; 88, 90; 88, 91; 89, integer:2010; 90, integer:1; 91, integer:1; 92, block; 92, 93; 92, 97; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:snodas_url_str; 96, string:'ftp://sidads.colorado.edu/DATASETS/NOAA/G02158/unmasked/%Y/%m_%b/SNODAS_unmasked_%Y%m%d.tar'; 97, expression_statement; 97, 98; 98, assignment; 98, 99; 98, 100; 99, identifier:tar_subfn_str_fmt; 100, string:'./zz_ssmv1%itS__T0001TTNATS%%Y%%m%%d05HP001.%s.gz'; 101, else_clause; 101, 102; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, call; 104, 105; 104, 106; 105, identifier:print; 106, argument_list; 106, 107; 107, string:"No SNODAS data available for input date"; 108, if_statement; 108, 109; 108, 112; 109, comparison_operator:is; 109, 110; 109, 111; 110, identifier:snodas_url_str; 111, None; 112, block; 112, 113; 112, 122; 112, 134; 112, 139; 112, 148; 112, 149; 112, 272; 112, 273; 112, 277; 112, 281; 112, 288; 112, 292; 112, 309; 112, 315; 112, 323; 112, 330; 112, 336; 112, 337; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:snodas_url; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:dem_dt; 119, identifier:strftime; 120, argument_list; 120, 121; 121, identifier:snodas_url_str; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:snodas_tar_fn; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:iolib; 128, identifier:getfile; 129, argument_list; 129, 130; 129, 131; 130, identifier:snodas_url; 131, keyword_argument; 131, 132; 131, 133; 132, identifier:outdir; 133, identifier:outdir; 134, expression_statement; 134, 135; 135, call; 135, 136; 135, 137; 136, identifier:print; 137, argument_list; 137, 138; 138, string:"Unpacking"; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:tar; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:tarfile; 145, identifier:open; 146, argument_list; 146, 147; 147, identifier:snodas_tar_fn; 148, comment; 149, for_statement; 149, 150; 149, 151; 149, 154; 150, identifier:ext; 151, tuple; 151, 152; 151, 153; 152, string:'dat'; 153, string:'Hdr'; 154, block; 154, 155; 154, 163; 154, 172; 154, 185; 154, 190; 154, 207; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:tar_subfn_str; 158, binary_operator:%; 158, 159; 158, 160; 159, identifier:tar_subfn_str_fmt; 160, tuple; 160, 161; 160, 162; 161, identifier:code; 162, identifier:ext; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:tar_subfn_gz; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:dem_dt; 169, identifier:strftime; 170, argument_list; 170, 171; 171, identifier:tar_subfn_str; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:tar_subfn; 175, subscript; 175, 176; 175, 184; 176, call; 176, 177; 176, 182; 177, attribute; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:os; 180, identifier:path; 181, identifier:splitext; 182, argument_list; 182, 183; 183, identifier:tar_subfn_gz; 184, integer:0; 185, expression_statement; 185, 186; 186, call; 186, 187; 186, 188; 187, identifier:print; 188, argument_list; 188, 189; 189, identifier:tar_subfn; 190, if_statement; 190, 191; 190, 194; 191, comparison_operator:is; 191, 192; 191, 193; 192, identifier:outdir; 193, None; 194, block; 194, 195; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 198; 197, identifier:tar_subfn; 198, call; 198, 199; 198, 204; 199, attribute; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:os; 202, identifier:path; 203, identifier:join; 204, argument_list; 204, 205; 204, 206; 205, identifier:outdir; 206, identifier:tar_subfn; 207, if_statement; 207, 208; 207, 217; 207, 218; 208, not_operator; 208, 209; 209, call; 209, 210; 209, 215; 210, attribute; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:os; 213, identifier:path; 214, identifier:exists; 215, argument_list; 215, 216; 216, identifier:tar_subfn; 217, comment; 218, block; 218, 219; 218, 226; 218, 265; 219, expression_statement; 219, 220; 220, call; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:tar; 223, identifier:extract; 224, argument_list; 224, 225; 225, identifier:tar_subfn_gz; 226, with_statement; 226, 227; 226, 239; 227, with_clause; 227, 228; 228, with_item; 228, 229; 229, as_pattern; 229, 230; 229, 237; 230, call; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:gzip; 233, identifier:open; 234, argument_list; 234, 235; 234, 236; 235, identifier:tar_subfn_gz; 236, string:'rb'; 237, as_pattern_target; 237, 238; 238, identifier:f; 239, block; 239, 240; 239, 248; 239, 259; 240, expression_statement; 240, 241; 241, assignment; 241, 242; 241, 243; 242, identifier:outf; 243, call; 243, 244; 243, 245; 244, identifier:open; 245, argument_list; 245, 246; 245, 247; 246, identifier:tar_subfn; 247, string:'wb'; 248, expression_statement; 248, 249; 249, call; 249, 250; 249, 253; 250, attribute; 250, 251; 250, 252; 251, identifier:outf; 252, identifier:write; 253, argument_list; 253, 254; 254, call; 254, 255; 254, 258; 255, attribute; 255, 256; 255, 257; 256, identifier:f; 257, identifier:read; 258, argument_list; 259, expression_statement; 259, 260; 260, call; 260, 261; 260, 264; 261, attribute; 261, 262; 261, 263; 262, identifier:outf; 263, identifier:close; 264, argument_list; 265, expression_statement; 265, 266; 266, call; 266, 267; 266, 270; 267, attribute; 267, 268; 267, 269; 268, identifier:os; 269, identifier:remove; 270, argument_list; 270, 271; 271, identifier:tar_subfn_gz; 272, comment; 273, expression_statement; 273, 274; 274, assignment; 274, 275; 274, 276; 275, identifier:bad_str; 276, string:'Created by module comment'; 277, expression_statement; 277, 278; 278, assignment; 278, 279; 278, 280; 279, identifier:snodas_fn; 280, identifier:tar_subfn; 281, expression_statement; 281, 282; 282, assignment; 282, 283; 282, 284; 283, identifier:f; 284, call; 284, 285; 284, 286; 285, identifier:open; 286, argument_list; 286, 287; 287, identifier:snodas_fn; 288, expression_statement; 288, 289; 289, assignment; 289, 290; 289, 291; 290, identifier:output; 291, list:[]; 292, for_statement; 292, 293; 292, 294; 292, 295; 293, identifier:line; 294, identifier:f; 295, block; 295, 296; 296, if_statement; 296, 297; 296, 301; 297, not_operator; 297, 298; 298, comparison_operator:in; 298, 299; 298, 300; 299, identifier:bad_str; 300, identifier:line; 301, block; 301, 302; 302, expression_statement; 302, 303; 303, call; 303, 304; 303, 307; 304, attribute; 304, 305; 304, 306; 305, identifier:output; 306, identifier:append; 307, argument_list; 307, 308; 308, identifier:line; 309, expression_statement; 309, 310; 310, call; 310, 311; 310, 314; 311, attribute; 311, 312; 311, 313; 312, identifier:f; 313, identifier:close; 314, argument_list; 315, expression_statement; 315, 316; 316, assignment; 316, 317; 316, 318; 317, identifier:f; 318, call; 318, 319; 318, 320; 319, identifier:open; 320, argument_list; 320, 321; 320, 322; 321, identifier:snodas_fn; 322, string:'w'; 323, expression_statement; 323, 324; 324, call; 324, 325; 324, 328; 325, attribute; 325, 326; 325, 327; 326, identifier:f; 327, identifier:writelines; 328, argument_list; 328, 329; 329, identifier:output; 330, expression_statement; 330, 331; 331, call; 331, 332; 331, 335; 332, attribute; 332, 333; 332, 334; 333, identifier:f; 334, identifier:close; 335, argument_list; 336, comment; 337, expression_statement; 337, 338; 338, assignment; 338, 339; 338, 340; 339, identifier:snodas_ds; 340, call; 340, 341; 340, 344; 341, attribute; 341, 342; 341, 343; 342, identifier:gdal; 343, identifier:Open; 344, argument_list; 344, 345; 345, identifier:snodas_fn; 346, return_statement; 346, 347; 347, identifier:snodas_ds | def get_snodas_ds(dem_dt, code=1036):
"""Function to fetch and process SNODAS snow depth products for input datetime
http://nsidc.org/data/docs/noaa/g02158_snodas_snow_cover_model/index.html
Product codes:
1036 is snow depth
1034 is SWE
filename format: us_ssmv11036tS__T0001TTNATS2015042205HP001.Hdr
"""
import tarfile
import gzip
snodas_ds = None
snodas_url_str = None
outdir = os.path.join(datadir, 'snodas')
if not os.path.exists(outdir):
os.makedirs(outdir)
#Note: unmasked products (beyond CONUS) are only available from 2010-present
if dem_dt >= datetime(2003,9,30) and dem_dt < datetime(2010,1,1):
snodas_url_str = 'ftp://sidads.colorado.edu/DATASETS/NOAA/G02158/masked/%Y/%m_%b/SNODAS_%Y%m%d.tar'
tar_subfn_str_fmt = 'us_ssmv1%itS__T0001TTNATS%%Y%%m%%d05HP001.%s.gz'
elif dem_dt >= datetime(2010,1,1):
snodas_url_str = 'ftp://sidads.colorado.edu/DATASETS/NOAA/G02158/unmasked/%Y/%m_%b/SNODAS_unmasked_%Y%m%d.tar'
tar_subfn_str_fmt = './zz_ssmv1%itS__T0001TTNATS%%Y%%m%%d05HP001.%s.gz'
else:
print("No SNODAS data available for input date")
if snodas_url_str is not None:
snodas_url = dem_dt.strftime(snodas_url_str)
snodas_tar_fn = iolib.getfile(snodas_url, outdir=outdir)
print("Unpacking")
tar = tarfile.open(snodas_tar_fn)
#gunzip to extract both dat and Hdr files, tar.gz
for ext in ('dat', 'Hdr'):
tar_subfn_str = tar_subfn_str_fmt % (code, ext)
tar_subfn_gz = dem_dt.strftime(tar_subfn_str)
tar_subfn = os.path.splitext(tar_subfn_gz)[0]
print(tar_subfn)
if outdir is not None:
tar_subfn = os.path.join(outdir, tar_subfn)
if not os.path.exists(tar_subfn):
#Should be able to do this without writing intermediate gz to disk
tar.extract(tar_subfn_gz)
with gzip.open(tar_subfn_gz, 'rb') as f:
outf = open(tar_subfn, 'wb')
outf.write(f.read())
outf.close()
os.remove(tar_subfn_gz)
#Need to delete 'Created by module comment' line from Hdr, can contain too many characters
bad_str = 'Created by module comment'
snodas_fn = tar_subfn
f = open(snodas_fn)
output = []
for line in f:
if not bad_str in line:
output.append(line)
f.close()
f = open(snodas_fn, 'w')
f.writelines(output)
f.close()
#Return GDAL dataset for extracted product
snodas_ds = gdal.Open(snodas_fn)
return snodas_ds |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 2, function_name:get_modscag_fn_list; 3, parameters; 3, 4; 3, 5; 3, 13; 4, identifier:dem_dt; 5, default_parameter; 5, 6; 5, 7; 6, identifier:tile_list; 7, tuple; 7, 8; 7, 9; 7, 10; 7, 11; 7, 12; 8, string:'h08v04'; 9, string:'h09v04'; 10, string:'h10v04'; 11, string:'h08v05'; 12, string:'h09v05'; 13, default_parameter; 13, 14; 13, 15; 14, identifier:pad_days; 15, integer:7; 16, block; 16, 17; 16, 19; 16, 20; 16, 21; 16, 22; 16, 23; 16, 26; 16, 29; 16, 34; 16, 42; 16, 51; 16, 74; 16, 86; 16, 104; 16, 108; 16, 499; 17, expression_statement; 17, 18; 18, comment; 19, comment; 20, comment; 21, comment; 22, comment; 23, import_statement; 23, 24; 24, dotted_name; 24, 25; 25, identifier:re; 26, import_statement; 26, 27; 27, dotted_name; 27, 28; 28, identifier:requests; 29, import_from_statement; 29, 30; 29, 32; 30, dotted_name; 30, 31; 31, identifier:bs4; 32, dotted_name; 32, 33; 33, identifier:BeautifulSoup; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:auth; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:iolib; 40, identifier:get_auth; 41, argument_list; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:pad_days; 45, call; 45, 46; 45, 47; 46, identifier:timedelta; 47, argument_list; 47, 48; 48, keyword_argument; 48, 49; 48, 50; 49, identifier:days; 50, identifier:pad_days; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:dt_list; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:timelib; 57, identifier:dt_range; 58, argument_list; 58, 59; 58, 62; 58, 70; 59, binary_operator:-; 59, 60; 59, 61; 60, identifier:dem_dt; 61, identifier:pad_days; 62, binary_operator:+; 62, 63; 62, 66; 63, binary_operator:+; 63, 64; 63, 65; 64, identifier:dem_dt; 65, identifier:pad_days; 66, call; 66, 67; 66, 68; 67, identifier:timedelta; 68, argument_list; 68, 69; 69, integer:1; 70, call; 70, 71; 70, 72; 71, identifier:timedelta; 72, argument_list; 72, 73; 73, integer:1; 74, expression_statement; 74, 75; 75, assignment; 75, 76; 75, 77; 76, identifier:outdir; 77, call; 77, 78; 77, 83; 78, attribute; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:os; 81, identifier:path; 82, identifier:join; 83, argument_list; 83, 84; 83, 85; 84, identifier:datadir; 85, string:'modscag'; 86, if_statement; 86, 87; 86, 96; 87, not_operator; 87, 88; 88, call; 88, 89; 88, 94; 89, attribute; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:os; 92, identifier:path; 93, identifier:exists; 94, argument_list; 94, 95; 95, identifier:outdir; 96, block; 96, 97; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:os; 101, identifier:makedirs; 102, argument_list; 102, 103; 103, identifier:outdir; 104, expression_statement; 104, 105; 105, assignment; 105, 106; 105, 107; 106, identifier:out_vrt_fn_list; 107, list:[]; 108, for_statement; 108, 109; 108, 110; 108, 111; 109, identifier:dt; 110, identifier:dt_list; 111, block; 111, 112; 111, 129; 111, 130; 111, 184; 111, 185; 111, 186; 111, 190; 111, 191; 111, 192; 111, 458; 111, 459; 112, expression_statement; 112, 113; 113, assignment; 113, 114; 113, 115; 114, identifier:out_vrt_fn; 115, call; 115, 116; 115, 121; 116, attribute; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:os; 119, identifier:path; 120, identifier:join; 121, argument_list; 121, 122; 121, 123; 122, identifier:outdir; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:dt; 126, identifier:strftime; 127, argument_list; 127, 128; 128, string:'%Y%m%d_snow_fraction.vrt'; 129, comment; 130, if_statement; 130, 131; 130, 139; 131, call; 131, 132; 131, 137; 132, attribute; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:os; 135, identifier:path; 136, identifier:exists; 137, argument_list; 137, 138; 138, identifier:out_vrt_fn; 139, block; 139, 140; 139, 149; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:vrt_ds; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:gdal; 146, identifier:Open; 147, argument_list; 147, 148; 148, identifier:out_vrt_fn; 149, if_statement; 149, 150; 149, 175; 150, call; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:np; 153, identifier:all; 154, argument_list; 154, 155; 155, list_comprehension; 155, 156; 155, 172; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:np; 159, identifier:any; 160, argument_list; 160, 161; 161, list_comprehension; 161, 162; 161, 165; 162, comparison_operator:in; 162, 163; 162, 164; 163, identifier:tile; 164, identifier:sub_fn; 165, for_in_clause; 165, 166; 165, 167; 166, identifier:sub_fn; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:vrt_ds; 170, identifier:GetFileList; 171, argument_list; 172, for_in_clause; 172, 173; 172, 174; 173, identifier:tile; 174, identifier:tile_list; 175, block; 175, 176; 175, 183; 176, expression_statement; 176, 177; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:out_vrt_fn_list; 180, identifier:append; 181, argument_list; 181, 182; 182, identifier:out_vrt_fn; 183, continue_statement; 184, comment; 185, comment; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:modscag_fn_list; 189, list:[]; 190, comment; 191, comment; 192, for_statement; 192, 193; 192, 194; 192, 195; 193, identifier:tile; 194, identifier:tile_list; 195, block; 195, 196; 195, 200; 195, 209; 195, 216; 195, 228; 195, 232; 195, 265; 195, 302; 195, 335; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 199; 198, identifier:modscag_url_str; 199, string:'https://snow-data.jpl.nasa.gov/modscag-historic/%Y/%j/'; 200, expression_statement; 200, 201; 201, assignment; 201, 202; 201, 203; 202, identifier:modscag_url_base; 203, call; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:dt; 206, identifier:strftime; 207, argument_list; 207, 208; 208, identifier:modscag_url_str; 209, expression_statement; 209, 210; 210, call; 210, 211; 210, 212; 211, identifier:print; 212, argument_list; 212, 213; 213, binary_operator:%; 213, 214; 213, 215; 214, string:"Trying: %s"; 215, identifier:modscag_url_base; 216, expression_statement; 216, 217; 217, assignment; 217, 218; 217, 219; 218, identifier:r; 219, call; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:requests; 222, identifier:get; 223, argument_list; 223, 224; 223, 225; 224, identifier:modscag_url_base; 225, keyword_argument; 225, 226; 225, 227; 226, identifier:auth; 227, identifier:auth; 228, expression_statement; 228, 229; 229, assignment; 229, 230; 229, 231; 230, identifier:modscag_url_fn; 231, list:[]; 232, if_statement; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:r; 235, identifier:ok; 236, block; 236, 237; 236, 247; 237, expression_statement; 237, 238; 238, assignment; 238, 239; 238, 240; 239, identifier:parsed_html; 240, call; 240, 241; 240, 242; 241, identifier:BeautifulSoup; 242, argument_list; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:r; 245, identifier:content; 246, string:"html.parser"; 247, expression_statement; 247, 248; 248, assignment; 248, 249; 248, 250; 249, identifier:modscag_url_fn; 250, call; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:parsed_html; 253, identifier:findAll; 254, argument_list; 254, 255; 255, keyword_argument; 255, 256; 255, 257; 256, identifier:text; 257, call; 257, 258; 257, 261; 258, attribute; 258, 259; 258, 260; 259, identifier:re; 260, identifier:compile; 261, argument_list; 261, 262; 262, binary_operator:%; 262, 263; 262, 264; 263, string:'%s.*snow_fraction.tif'; 264, identifier:tile; 265, if_statement; 265, 266; 265, 268; 265, 269; 266, not_operator; 266, 267; 267, identifier:modscag_url_fn; 268, comment; 269, block; 269, 270; 269, 274; 269, 283; 269, 290; 270, expression_statement; 270, 271; 271, assignment; 271, 272; 271, 273; 272, identifier:modscag_url_str; 273, string:'https://snow-data.jpl.nasa.gov/modscag/%Y/%j/'; 274, expression_statement; 274, 275; 275, assignment; 275, 276; 275, 277; 276, identifier:modscag_url_base; 277, call; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, identifier:dt; 280, identifier:strftime; 281, argument_list; 281, 282; 282, identifier:modscag_url_str; 283, expression_statement; 283, 284; 284, call; 284, 285; 284, 286; 285, identifier:print; 286, argument_list; 286, 287; 287, binary_operator:%; 287, 288; 287, 289; 288, string:"Trying: %s"; 289, identifier:modscag_url_base; 290, expression_statement; 290, 291; 291, assignment; 291, 292; 291, 293; 292, identifier:r; 293, call; 293, 294; 293, 297; 294, attribute; 294, 295; 294, 296; 295, identifier:requests; 296, identifier:get; 297, argument_list; 297, 298; 297, 299; 298, identifier:modscag_url_base; 299, keyword_argument; 299, 300; 299, 301; 300, identifier:auth; 301, identifier:auth; 302, if_statement; 302, 303; 302, 306; 303, attribute; 303, 304; 303, 305; 304, identifier:r; 305, identifier:ok; 306, block; 306, 307; 306, 317; 307, expression_statement; 307, 308; 308, assignment; 308, 309; 308, 310; 309, identifier:parsed_html; 310, call; 310, 311; 310, 312; 311, identifier:BeautifulSoup; 312, argument_list; 312, 313; 312, 316; 313, attribute; 313, 314; 313, 315; 314, identifier:r; 315, identifier:content; 316, string:"html.parser"; 317, expression_statement; 317, 318; 318, assignment; 318, 319; 318, 320; 319, identifier:modscag_url_fn; 320, call; 320, 321; 320, 324; 321, attribute; 321, 322; 321, 323; 322, identifier:parsed_html; 323, identifier:findAll; 324, argument_list; 324, 325; 325, keyword_argument; 325, 326; 325, 327; 326, identifier:text; 327, call; 327, 328; 327, 331; 328, attribute; 328, 329; 328, 330; 329, identifier:re; 330, identifier:compile; 331, argument_list; 331, 332; 332, binary_operator:%; 332, 333; 332, 334; 333, string:'%s.*snow_fraction.tif'; 334, identifier:tile; 335, if_statement; 335, 336; 335, 338; 335, 346; 336, not_operator; 336, 337; 337, identifier:modscag_url_fn; 338, block; 338, 339; 339, expression_statement; 339, 340; 340, call; 340, 341; 340, 342; 341, identifier:print; 342, argument_list; 342, 343; 343, binary_operator:%; 343, 344; 343, 345; 344, string:"Unable to fetch MODSCAG for %s"; 345, identifier:dt; 346, else_clause; 346, 347; 346, 348; 346, 349; 347, comment; 348, comment; 349, block; 349, 350; 349, 360; 349, 361; 349, 379; 350, expression_statement; 350, 351; 351, assignment; 351, 352; 351, 353; 352, identifier:parsed_html; 353, call; 353, 354; 353, 355; 354, identifier:BeautifulSoup; 355, argument_list; 355, 356; 355, 359; 356, attribute; 356, 357; 356, 358; 357, identifier:r; 358, identifier:content; 359, string:"html.parser"; 360, comment; 361, expression_statement; 361, 362; 362, assignment; 362, 363; 362, 364; 363, identifier:modscag_url_fn; 364, call; 364, 365; 364, 368; 365, attribute; 365, 366; 365, 367; 366, identifier:parsed_html; 367, identifier:findAll; 368, argument_list; 368, 369; 369, keyword_argument; 369, 370; 369, 371; 370, identifier:text; 371, call; 371, 372; 371, 375; 372, attribute; 372, 373; 372, 374; 373, identifier:re; 374, identifier:compile; 375, argument_list; 375, 376; 376, binary_operator:%; 376, 377; 376, 378; 377, string:'%s.*snow_fraction.tif'; 378, identifier:tile; 379, if_statement; 379, 380; 379, 381; 380, identifier:modscag_url_fn; 381, block; 381, 382; 381, 388; 381, 400; 381, 405; 381, 427; 381, 451; 382, expression_statement; 382, 383; 383, assignment; 383, 384; 383, 385; 384, identifier:modscag_url_fn; 385, subscript; 385, 386; 385, 387; 386, identifier:modscag_url_fn; 387, integer:0; 388, expression_statement; 388, 389; 389, assignment; 389, 390; 389, 391; 390, identifier:modscag_url; 391, call; 391, 392; 391, 397; 392, attribute; 392, 393; 392, 396; 393, attribute; 393, 394; 393, 395; 394, identifier:os; 395, identifier:path; 396, identifier:join; 397, argument_list; 397, 398; 397, 399; 398, identifier:modscag_url_base; 399, identifier:modscag_url_fn; 400, expression_statement; 400, 401; 401, call; 401, 402; 401, 403; 402, identifier:print; 403, argument_list; 403, 404; 404, identifier:modscag_url; 405, expression_statement; 405, 406; 406, assignment; 406, 407; 406, 408; 407, identifier:modscag_fn; 408, call; 408, 409; 408, 414; 409, attribute; 409, 410; 409, 413; 410, attribute; 410, 411; 410, 412; 411, identifier:os; 412, identifier:path; 413, identifier:join; 414, argument_list; 414, 415; 414, 416; 415, identifier:outdir; 416, subscript; 416, 417; 416, 425; 417, call; 417, 418; 417, 423; 418, attribute; 418, 419; 418, 422; 419, attribute; 419, 420; 419, 421; 420, identifier:os; 421, identifier:path; 422, identifier:split; 423, argument_list; 423, 424; 424, identifier:modscag_url_fn; 425, unary_operator:-; 425, 426; 426, integer:1; 427, if_statement; 427, 428; 427, 437; 428, not_operator; 428, 429; 429, call; 429, 430; 429, 435; 430, attribute; 430, 431; 430, 434; 431, attribute; 431, 432; 431, 433; 432, identifier:os; 433, identifier:path; 434, identifier:exists; 435, argument_list; 435, 436; 436, identifier:modscag_fn; 437, block; 437, 438; 438, expression_statement; 438, 439; 439, call; 439, 440; 439, 443; 440, attribute; 440, 441; 440, 442; 441, identifier:iolib; 442, identifier:getfile2; 443, argument_list; 443, 444; 443, 445; 443, 448; 444, identifier:modscag_url; 445, keyword_argument; 445, 446; 445, 447; 446, identifier:auth; 447, identifier:auth; 448, keyword_argument; 448, 449; 448, 450; 449, identifier:outdir; 450, identifier:outdir; 451, expression_statement; 451, 452; 452, call; 452, 453; 452, 456; 453, attribute; 453, 454; 453, 455; 454, identifier:modscag_fn_list; 455, identifier:append; 456, argument_list; 456, 457; 457, identifier:modscag_fn; 458, comment; 459, if_statement; 459, 460; 459, 461; 460, identifier:modscag_fn_list; 461, block; 461, 462; 461, 470; 461, 477; 461, 482; 461, 492; 462, expression_statement; 462, 463; 463, assignment; 463, 464; 463, 465; 464, identifier:cmd; 465, list:['gdalbuildvrt', '-vrtnodata', '255', out_vrt_fn]; 465, 466; 465, 467; 465, 468; 465, 469; 466, string:'gdalbuildvrt'; 467, string:'-vrtnodata'; 468, string:'255'; 469, identifier:out_vrt_fn; 470, expression_statement; 470, 471; 471, call; 471, 472; 471, 475; 472, attribute; 472, 473; 472, 474; 473, identifier:cmd; 474, identifier:extend; 475, argument_list; 475, 476; 476, identifier:modscag_fn_list; 477, expression_statement; 477, 478; 478, call; 478, 479; 478, 480; 479, identifier:print; 480, argument_list; 480, 481; 481, identifier:cmd; 482, expression_statement; 482, 483; 483, call; 483, 484; 483, 487; 484, attribute; 484, 485; 484, 486; 485, identifier:subprocess; 486, identifier:call; 487, argument_list; 487, 488; 487, 489; 488, identifier:cmd; 489, keyword_argument; 489, 490; 489, 491; 490, identifier:shell; 491, False; 492, expression_statement; 492, 493; 493, call; 493, 494; 493, 497; 494, attribute; 494, 495; 494, 496; 495, identifier:out_vrt_fn_list; 496, identifier:append; 497, argument_list; 497, 498; 498, identifier:out_vrt_fn; 499, return_statement; 499, 500; 500, identifier:out_vrt_fn_list | def get_modscag_fn_list(dem_dt, tile_list=('h08v04', 'h09v04', 'h10v04', 'h08v05', 'h09v05'), pad_days=7):
"""Function to fetch and process MODSCAG fractional snow cover products for input datetime
Products are tiled in MODIS sinusoidal projection
example url: https://snow-data.jpl.nasa.gov/modscag-historic/2015/001/MOD09GA.A2015001.h07v03.005.2015006001833.snow_fraction.tif
"""
#Could also use global MODIS 500 m snowcover grids, 8 day
#http://nsidc.org/data/docs/daac/modis_v5/mod10a2_modis_terra_snow_8-day_global_500m_grid.gd.html
#These are HDF4, sinusoidal
#Should be able to load up with warplib without issue
import re
import requests
from bs4 import BeautifulSoup
auth = iolib.get_auth()
pad_days = timedelta(days=pad_days)
dt_list = timelib.dt_range(dem_dt-pad_days, dem_dt+pad_days+timedelta(1), timedelta(1))
outdir = os.path.join(datadir, 'modscag')
if not os.path.exists(outdir):
os.makedirs(outdir)
out_vrt_fn_list = []
for dt in dt_list:
out_vrt_fn = os.path.join(outdir, dt.strftime('%Y%m%d_snow_fraction.vrt'))
#If we already have a vrt and it contains all of the necessary tiles
if os.path.exists(out_vrt_fn):
vrt_ds = gdal.Open(out_vrt_fn)
if np.all([np.any([tile in sub_fn for sub_fn in vrt_ds.GetFileList()]) for tile in tile_list]):
out_vrt_fn_list.append(out_vrt_fn)
continue
#Otherwise, download missing tiles and rebuild
#Try to use historic products
modscag_fn_list = []
#Note: not all tiles are available for same date ranges in historic vs. real-time
#Need to repeat search tile-by-tile
for tile in tile_list:
modscag_url_str = 'https://snow-data.jpl.nasa.gov/modscag-historic/%Y/%j/'
modscag_url_base = dt.strftime(modscag_url_str)
print("Trying: %s" % modscag_url_base)
r = requests.get(modscag_url_base, auth=auth)
modscag_url_fn = []
if r.ok:
parsed_html = BeautifulSoup(r.content, "html.parser")
modscag_url_fn = parsed_html.findAll(text=re.compile('%s.*snow_fraction.tif' % tile))
if not modscag_url_fn:
#Couldn't find historic, try to use real-time products
modscag_url_str = 'https://snow-data.jpl.nasa.gov/modscag/%Y/%j/'
modscag_url_base = dt.strftime(modscag_url_str)
print("Trying: %s" % modscag_url_base)
r = requests.get(modscag_url_base, auth=auth)
if r.ok:
parsed_html = BeautifulSoup(r.content, "html.parser")
modscag_url_fn = parsed_html.findAll(text=re.compile('%s.*snow_fraction.tif' % tile))
if not modscag_url_fn:
print("Unable to fetch MODSCAG for %s" % dt)
else:
#OK, we got
#Now extract actual tif filenames to fetch from html
parsed_html = BeautifulSoup(r.content, "html.parser")
#Fetch all tiles
modscag_url_fn = parsed_html.findAll(text=re.compile('%s.*snow_fraction.tif' % tile))
if modscag_url_fn:
modscag_url_fn = modscag_url_fn[0]
modscag_url = os.path.join(modscag_url_base, modscag_url_fn)
print(modscag_url)
modscag_fn = os.path.join(outdir, os.path.split(modscag_url_fn)[-1])
if not os.path.exists(modscag_fn):
iolib.getfile2(modscag_url, auth=auth, outdir=outdir)
modscag_fn_list.append(modscag_fn)
#Mosaic tiles - currently a hack
if modscag_fn_list:
cmd = ['gdalbuildvrt', '-vrtnodata', '255', out_vrt_fn]
cmd.extend(modscag_fn_list)
print(cmd)
subprocess.call(cmd, shell=False)
out_vrt_fn_list.append(out_vrt_fn)
return out_vrt_fn_list |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:_decode_record; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:s; 6, default_parameter; 6, 7; 6, 8; 7, identifier:line; 8, integer:0; 9, block; 9, 10; 9, 12; 9, 21; 9, 27; 9, 95; 9, 101; 9, 116; 9, 128; 9, 134; 9, 149; 9, 156; 9, 160; 9, 172; 10, expression_statement; 10, 11; 11, string:'''Decode one record of HEX file.
@param s line with HEX record.
@param line line number (for error messages).
@raise EndOfFile if EOF record encountered.
'''; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:s; 15, call; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:s; 18, identifier:rstrip; 19, argument_list; 19, 20; 20, string:'\r\n'; 21, if_statement; 21, 22; 21, 24; 22, not_operator; 22, 23; 23, identifier:s; 24, block; 24, 25; 24, 26; 25, return_statement; 26, comment; 27, if_statement; 27, 28; 27, 33; 27, 86; 28, comparison_operator:==; 28, 29; 28, 32; 29, subscript; 29, 30; 29, 31; 30, identifier:s; 31, integer:0; 32, string:':'; 33, block; 33, 34; 33, 67; 33, 74; 34, try_statement; 34, 35; 34, 54; 35, block; 35, 36; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:bin; 39, call; 39, 40; 39, 41; 40, identifier:array; 41, argument_list; 41, 42; 41, 43; 42, string:'B'; 43, call; 43, 44; 43, 45; 44, identifier:unhexlify; 45, argument_list; 45, 46; 46, call; 46, 47; 46, 48; 47, identifier:asbytes; 48, argument_list; 48, 49; 49, subscript; 49, 50; 49, 51; 50, identifier:s; 51, slice; 51, 52; 51, 53; 52, integer:1; 53, colon; 54, except_clause; 54, 55; 54, 58; 54, 59; 55, tuple; 55, 56; 55, 57; 56, identifier:TypeError; 57, identifier:ValueError; 58, comment; 59, block; 59, 60; 60, raise_statement; 60, 61; 61, call; 61, 62; 61, 63; 62, identifier:HexRecordError; 63, argument_list; 63, 64; 64, keyword_argument; 64, 65; 64, 66; 65, identifier:line; 66, identifier:line; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:length; 70, call; 70, 71; 70, 72; 71, identifier:len; 72, argument_list; 72, 73; 73, identifier:bin; 74, if_statement; 74, 75; 74, 78; 75, comparison_operator:<; 75, 76; 75, 77; 76, identifier:length; 77, integer:5; 78, block; 78, 79; 79, raise_statement; 79, 80; 80, call; 80, 81; 80, 82; 81, identifier:HexRecordError; 82, argument_list; 82, 83; 83, keyword_argument; 83, 84; 83, 85; 84, identifier:line; 85, identifier:line; 86, else_clause; 86, 87; 87, block; 87, 88; 88, raise_statement; 88, 89; 89, call; 89, 90; 89, 91; 90, identifier:HexRecordError; 91, argument_list; 91, 92; 92, keyword_argument; 92, 93; 92, 94; 93, identifier:line; 94, identifier:line; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:record_length; 98, subscript; 98, 99; 98, 100; 99, identifier:bin; 100, integer:0; 101, if_statement; 101, 102; 101, 108; 102, comparison_operator:!=; 102, 103; 102, 104; 103, identifier:length; 104, parenthesized_expression; 104, 105; 105, binary_operator:+; 105, 106; 105, 107; 106, integer:5; 107, identifier:record_length; 108, block; 108, 109; 109, raise_statement; 109, 110; 110, call; 110, 111; 110, 112; 111, identifier:RecordLengthError; 112, argument_list; 112, 113; 113, keyword_argument; 113, 114; 113, 115; 114, identifier:line; 115, identifier:line; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:addr; 119, binary_operator:+; 119, 120; 119, 125; 120, binary_operator:*; 120, 121; 120, 124; 121, subscript; 121, 122; 121, 123; 122, identifier:bin; 123, integer:1; 124, integer:256; 125, subscript; 125, 126; 125, 127; 126, identifier:bin; 127, integer:2; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:record_type; 131, subscript; 131, 132; 131, 133; 132, identifier:bin; 133, integer:3; 134, if_statement; 134, 135; 134, 141; 135, not_operator; 135, 136; 136, parenthesized_expression; 136, 137; 137, comparison_operator:<=; 137, 138; 137, 139; 137, 140; 138, integer:0; 139, identifier:record_type; 140, integer:5; 141, block; 141, 142; 142, raise_statement; 142, 143; 143, call; 143, 144; 143, 145; 144, identifier:RecordTypeError; 145, argument_list; 145, 146; 146, keyword_argument; 146, 147; 146, 148; 147, identifier:line; 148, identifier:line; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 152; 151, identifier:crc; 152, call; 152, 153; 152, 154; 153, identifier:sum; 154, argument_list; 154, 155; 155, identifier:bin; 156, expression_statement; 156, 157; 157, augmented_assignment:&=; 157, 158; 157, 159; 158, identifier:crc; 159, integer:0x0FF; 160, if_statement; 160, 161; 160, 164; 161, comparison_operator:!=; 161, 162; 161, 163; 162, identifier:crc; 163, integer:0; 164, block; 164, 165; 165, raise_statement; 165, 166; 166, call; 166, 167; 166, 168; 167, identifier:RecordChecksumError; 168, argument_list; 168, 169; 169, keyword_argument; 169, 170; 169, 171; 170, identifier:line; 171, identifier:line; 172, if_statement; 172, 173; 172, 176; 172, 177; 172, 235; 172, 255; 172, 294; 172, 333; 172, 395; 173, comparison_operator:==; 173, 174; 173, 175; 174, identifier:record_type; 175, integer:0; 176, comment; 177, block; 177, 178; 177, 184; 178, expression_statement; 178, 179; 179, augmented_assignment:+=; 179, 180; 179, 181; 180, identifier:addr; 181, attribute; 181, 182; 181, 183; 182, identifier:self; 183, identifier:_offset; 184, for_statement; 184, 185; 184, 186; 184, 193; 185, identifier:i; 186, call; 186, 187; 186, 188; 187, identifier:range_g; 188, argument_list; 188, 189; 188, 190; 189, integer:4; 190, binary_operator:+; 190, 191; 190, 192; 191, integer:4; 192, identifier:record_length; 193, block; 193, 194; 193, 218; 193, 228; 193, 232; 193, 233; 193, 234; 194, if_statement; 194, 195; 194, 207; 195, not_operator; 195, 196; 196, comparison_operator:is; 196, 197; 196, 206; 197, call; 197, 198; 197, 203; 198, attribute; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:self; 201, identifier:_buf; 202, identifier:get; 203, argument_list; 203, 204; 203, 205; 204, identifier:addr; 205, None; 206, None; 207, block; 207, 208; 208, raise_statement; 208, 209; 209, call; 209, 210; 209, 211; 210, identifier:AddressOverlapError; 211, argument_list; 211, 212; 211, 215; 212, keyword_argument; 212, 213; 212, 214; 213, identifier:address; 214, identifier:addr; 215, keyword_argument; 215, 216; 215, 217; 216, identifier:line; 217, identifier:line; 218, expression_statement; 218, 219; 219, assignment; 219, 220; 219, 225; 220, subscript; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:self; 223, identifier:_buf; 224, identifier:addr; 225, subscript; 225, 226; 225, 227; 226, identifier:bin; 227, identifier:i; 228, expression_statement; 228, 229; 229, augmented_assignment:+=; 229, 230; 229, 231; 230, identifier:addr; 231, integer:1; 232, comment; 233, comment; 234, comment; 235, elif_clause; 235, 236; 235, 239; 235, 240; 236, comparison_operator:==; 236, 237; 236, 238; 237, identifier:record_type; 238, integer:1; 239, comment; 240, block; 240, 241; 240, 253; 241, if_statement; 241, 242; 241, 245; 242, comparison_operator:!=; 242, 243; 242, 244; 243, identifier:record_length; 244, integer:0; 245, block; 245, 246; 246, raise_statement; 246, 247; 247, call; 247, 248; 247, 249; 248, identifier:EOFRecordError; 249, argument_list; 249, 250; 250, keyword_argument; 250, 251; 250, 252; 251, identifier:line; 252, identifier:line; 253, raise_statement; 253, 254; 254, identifier:_EndOfFile; 255, elif_clause; 255, 256; 255, 259; 255, 260; 256, comparison_operator:==; 256, 257; 256, 258; 257, identifier:record_type; 258, integer:2; 259, comment; 260, block; 260, 261; 260, 277; 261, if_statement; 261, 262; 261, 269; 262, boolean_operator:or; 262, 263; 262, 266; 263, comparison_operator:!=; 263, 264; 263, 265; 264, identifier:record_length; 265, integer:2; 266, comparison_operator:!=; 266, 267; 266, 268; 267, identifier:addr; 268, integer:0; 269, block; 269, 270; 270, raise_statement; 270, 271; 271, call; 271, 272; 271, 273; 272, identifier:ExtendedSegmentAddressRecordError; 273, argument_list; 273, 274; 274, keyword_argument; 274, 275; 274, 276; 275, identifier:line; 276, identifier:line; 277, expression_statement; 277, 278; 278, assignment; 278, 279; 278, 282; 279, attribute; 279, 280; 279, 281; 280, identifier:self; 281, identifier:_offset; 282, binary_operator:*; 282, 283; 282, 293; 283, parenthesized_expression; 283, 284; 284, binary_operator:+; 284, 285; 284, 290; 285, binary_operator:*; 285, 286; 285, 289; 286, subscript; 286, 287; 286, 288; 287, identifier:bin; 288, integer:4; 289, integer:256; 290, subscript; 290, 291; 290, 292; 291, identifier:bin; 292, integer:5; 293, integer:16; 294, elif_clause; 294, 295; 294, 298; 294, 299; 295, comparison_operator:==; 295, 296; 295, 297; 296, identifier:record_type; 297, integer:4; 298, comment; 299, block; 299, 300; 299, 316; 300, if_statement; 300, 301; 300, 308; 301, boolean_operator:or; 301, 302; 301, 305; 302, comparison_operator:!=; 302, 303; 302, 304; 303, identifier:record_length; 304, integer:2; 305, comparison_operator:!=; 305, 306; 305, 307; 306, identifier:addr; 307, integer:0; 308, block; 308, 309; 309, raise_statement; 309, 310; 310, call; 310, 311; 310, 312; 311, identifier:ExtendedLinearAddressRecordError; 312, argument_list; 312, 313; 313, keyword_argument; 313, 314; 313, 315; 314, identifier:line; 315, identifier:line; 316, expression_statement; 316, 317; 317, assignment; 317, 318; 317, 321; 318, attribute; 318, 319; 318, 320; 319, identifier:self; 320, identifier:_offset; 321, binary_operator:*; 321, 322; 321, 332; 322, parenthesized_expression; 322, 323; 323, binary_operator:+; 323, 324; 323, 329; 324, binary_operator:*; 324, 325; 324, 328; 325, subscript; 325, 326; 325, 327; 326, identifier:bin; 327, integer:4; 328, integer:256; 329, subscript; 329, 330; 329, 331; 330, identifier:bin; 331, integer:5; 332, integer:65536; 333, elif_clause; 333, 334; 333, 337; 333, 338; 334, comparison_operator:==; 334, 335; 334, 336; 335, identifier:record_type; 336, integer:3; 337, comment; 338, block; 338, 339; 338, 355; 338, 367; 339, if_statement; 339, 340; 339, 347; 340, boolean_operator:or; 340, 341; 340, 344; 341, comparison_operator:!=; 341, 342; 341, 343; 342, identifier:record_length; 343, integer:4; 344, comparison_operator:!=; 344, 345; 344, 346; 345, identifier:addr; 346, integer:0; 347, block; 347, 348; 348, raise_statement; 348, 349; 349, call; 349, 350; 349, 351; 350, identifier:StartSegmentAddressRecordError; 351, argument_list; 351, 352; 352, keyword_argument; 352, 353; 352, 354; 353, identifier:line; 354, identifier:line; 355, if_statement; 355, 356; 355, 359; 356, attribute; 356, 357; 356, 358; 357, identifier:self; 358, identifier:start_addr; 359, block; 359, 360; 360, raise_statement; 360, 361; 361, call; 361, 362; 361, 363; 362, identifier:DuplicateStartAddressRecordError; 363, argument_list; 363, 364; 364, keyword_argument; 364, 365; 364, 366; 365, identifier:line; 366, identifier:line; 367, expression_statement; 367, 368; 368, assignment; 368, 369; 368, 372; 369, attribute; 369, 370; 369, 371; 370, identifier:self; 371, identifier:start_addr; 372, dictionary; 372, 373; 372, 384; 373, pair; 373, 374; 373, 375; 374, string:'CS'; 375, binary_operator:+; 375, 376; 375, 381; 376, binary_operator:*; 376, 377; 376, 380; 377, subscript; 377, 378; 377, 379; 378, identifier:bin; 379, integer:4; 380, integer:256; 381, subscript; 381, 382; 381, 383; 382, identifier:bin; 383, integer:5; 384, pair; 384, 385; 384, 386; 385, string:'IP'; 386, binary_operator:+; 386, 387; 386, 392; 387, binary_operator:*; 387, 388; 387, 391; 388, subscript; 388, 389; 388, 390; 389, identifier:bin; 390, integer:6; 391, integer:256; 392, subscript; 392, 393; 392, 394; 393, identifier:bin; 394, integer:7; 395, elif_clause; 395, 396; 395, 399; 395, 400; 396, comparison_operator:==; 396, 397; 396, 398; 397, identifier:record_type; 398, integer:5; 399, comment; 400, block; 400, 401; 400, 417; 400, 429; 401, if_statement; 401, 402; 401, 409; 402, boolean_operator:or; 402, 403; 402, 406; 403, comparison_operator:!=; 403, 404; 403, 405; 404, identifier:record_length; 405, integer:4; 406, comparison_operator:!=; 406, 407; 406, 408; 407, identifier:addr; 408, integer:0; 409, block; 409, 410; 410, raise_statement; 410, 411; 411, call; 411, 412; 411, 413; 412, identifier:StartLinearAddressRecordError; 413, argument_list; 413, 414; 414, keyword_argument; 414, 415; 414, 416; 415, identifier:line; 416, identifier:line; 417, if_statement; 417, 418; 417, 421; 418, attribute; 418, 419; 418, 420; 419, identifier:self; 420, identifier:start_addr; 421, block; 421, 422; 422, raise_statement; 422, 423; 423, call; 423, 424; 423, 425; 424, identifier:DuplicateStartAddressRecordError; 425, argument_list; 425, 426; 426, keyword_argument; 426, 427; 426, 428; 427, identifier:line; 428, identifier:line; 429, expression_statement; 429, 430; 430, assignment; 430, 431; 430, 434; 431, attribute; 431, 432; 431, 433; 432, identifier:self; 433, identifier:start_addr; 434, dictionary; 434, 435; 435, pair; 435, 436; 435, 437; 436, string:'EIP'; 437, parenthesized_expression; 437, 438; 438, binary_operator:+; 438, 439; 438, 456; 439, binary_operator:+; 439, 440; 439, 451; 440, binary_operator:+; 440, 441; 440, 446; 441, binary_operator:*; 441, 442; 441, 445; 442, subscript; 442, 443; 442, 444; 443, identifier:bin; 444, integer:4; 445, integer:16777216; 446, binary_operator:*; 446, 447; 446, 450; 447, subscript; 447, 448; 447, 449; 448, identifier:bin; 449, integer:5; 450, integer:65536; 451, binary_operator:*; 451, 452; 451, 455; 452, subscript; 452, 453; 452, 454; 453, identifier:bin; 454, integer:6; 455, integer:256; 456, subscript; 456, 457; 456, 458; 457, identifier:bin; 458, integer:7 | def _decode_record(self, s, line=0):
'''Decode one record of HEX file.
@param s line with HEX record.
@param line line number (for error messages).
@raise EndOfFile if EOF record encountered.
'''
s = s.rstrip('\r\n')
if not s:
return # empty line
if s[0] == ':':
try:
bin = array('B', unhexlify(asbytes(s[1:])))
except (TypeError, ValueError):
# this might be raised by unhexlify when odd hexascii digits
raise HexRecordError(line=line)
length = len(bin)
if length < 5:
raise HexRecordError(line=line)
else:
raise HexRecordError(line=line)
record_length = bin[0]
if length != (5 + record_length):
raise RecordLengthError(line=line)
addr = bin[1]*256 + bin[2]
record_type = bin[3]
if not (0 <= record_type <= 5):
raise RecordTypeError(line=line)
crc = sum(bin)
crc &= 0x0FF
if crc != 0:
raise RecordChecksumError(line=line)
if record_type == 0:
# data record
addr += self._offset
for i in range_g(4, 4+record_length):
if not self._buf.get(addr, None) is None:
raise AddressOverlapError(address=addr, line=line)
self._buf[addr] = bin[i]
addr += 1 # FIXME: addr should be wrapped
# BUT after 02 record (at 64K boundary)
# and after 04 record (at 4G boundary)
elif record_type == 1:
# end of file record
if record_length != 0:
raise EOFRecordError(line=line)
raise _EndOfFile
elif record_type == 2:
# Extended 8086 Segment Record
if record_length != 2 or addr != 0:
raise ExtendedSegmentAddressRecordError(line=line)
self._offset = (bin[4]*256 + bin[5]) * 16
elif record_type == 4:
# Extended Linear Address Record
if record_length != 2 or addr != 0:
raise ExtendedLinearAddressRecordError(line=line)
self._offset = (bin[4]*256 + bin[5]) * 65536
elif record_type == 3:
# Start Segment Address Record
if record_length != 4 or addr != 0:
raise StartSegmentAddressRecordError(line=line)
if self.start_addr:
raise DuplicateStartAddressRecordError(line=line)
self.start_addr = {'CS': bin[4]*256 + bin[5],
'IP': bin[6]*256 + bin[7],
}
elif record_type == 5:
# Start Linear Address Record
if record_length != 4 or addr != 0:
raise StartLinearAddressRecordError(line=line)
if self.start_addr:
raise DuplicateStartAddressRecordError(line=line)
self.start_addr = {'EIP': (bin[4]*16777216 +
bin[5]*65536 +
bin[6]*256 +
bin[7]),
} |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:_get_start_end; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:start; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:end; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:size; 13, None; 14, block; 14, 15; 14, 17; 14, 34; 14, 150; 15, expression_statement; 15, 16; 16, comment; 17, if_statement; 17, 18; 17, 31; 18, boolean_operator:and; 18, 19; 18, 26; 19, comparison_operator:==; 19, 20; 19, 23; 20, tuple; 20, 21; 20, 22; 21, identifier:start; 22, identifier:end; 23, tuple; 23, 24; 23, 25; 24, None; 25, None; 26, comparison_operator:==; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:_buf; 30, dictionary; 31, block; 31, 32; 32, raise_statement; 32, 33; 33, identifier:EmptyIntelHexError; 34, if_statement; 34, 35; 34, 38; 34, 109; 35, comparison_operator:is; 35, 36; 35, 37; 36, identifier:size; 37, None; 38, block; 38, 39; 38, 53; 38, 70; 39, if_statement; 39, 40; 39, 45; 40, comparison_operator:not; 40, 41; 40, 42; 41, None; 42, tuple; 42, 43; 42, 44; 43, identifier:start; 44, identifier:end; 45, block; 45, 46; 46, raise_statement; 46, 47; 47, call; 47, 48; 47, 49; 48, identifier:ValueError; 49, argument_list; 49, 50; 50, concatenated_string; 50, 51; 50, 52; 51, string:"tobinarray: you can't use start,end and size"; 52, string:" arguments in the same time"; 53, if_statement; 53, 54; 53, 61; 54, comparison_operator:==; 54, 55; 54, 58; 55, tuple; 55, 56; 55, 57; 56, identifier:start; 57, identifier:end; 58, tuple; 58, 59; 58, 60; 59, None; 60, None; 61, block; 61, 62; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:start; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:minaddr; 69, argument_list; 70, if_statement; 70, 71; 70, 74; 70, 83; 71, comparison_operator:is; 71, 72; 71, 73; 72, identifier:start; 73, None; 74, block; 74, 75; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:end; 78, binary_operator:-; 78, 79; 78, 82; 79, binary_operator:+; 79, 80; 79, 81; 80, identifier:start; 81, identifier:size; 82, integer:1; 83, else_clause; 83, 84; 84, block; 84, 85; 84, 93; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:start; 88, binary_operator:+; 88, 89; 88, 92; 89, binary_operator:-; 89, 90; 89, 91; 90, identifier:end; 91, identifier:size; 92, integer:1; 93, if_statement; 93, 94; 93, 97; 94, comparison_operator:<; 94, 95; 94, 96; 95, identifier:start; 96, integer:0; 97, block; 97, 98; 98, raise_statement; 98, 99; 99, call; 99, 100; 99, 101; 100, identifier:ValueError; 101, argument_list; 101, 102; 102, binary_operator:%; 102, 103; 102, 106; 103, concatenated_string; 103, 104; 103, 105; 104, string:"tobinarray: invalid size (%d) "; 105, string:"for given end address (%d)"; 106, tuple; 106, 107; 106, 108; 107, identifier:size; 108, identifier:end; 109, else_clause; 109, 110; 110, block; 110, 111; 110, 124; 110, 137; 111, if_statement; 111, 112; 111, 115; 112, comparison_operator:is; 112, 113; 112, 114; 113, identifier:start; 114, None; 115, block; 115, 116; 116, expression_statement; 116, 117; 117, assignment; 117, 118; 117, 119; 118, identifier:start; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:self; 122, identifier:minaddr; 123, argument_list; 124, if_statement; 124, 125; 124, 128; 125, comparison_operator:is; 125, 126; 125, 127; 126, identifier:end; 127, None; 128, block; 128, 129; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:end; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:self; 135, identifier:maxaddr; 136, argument_list; 137, if_statement; 137, 138; 137, 141; 138, comparison_operator:>; 138, 139; 138, 140; 139, identifier:start; 140, identifier:end; 141, block; 141, 142; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 147; 144, pattern_list; 144, 145; 144, 146; 145, identifier:start; 146, identifier:end; 147, expression_list; 147, 148; 147, 149; 148, identifier:end; 149, identifier:start; 150, return_statement; 150, 151; 151, expression_list; 151, 152; 151, 153; 152, identifier:start; 153, identifier:end | def _get_start_end(self, start=None, end=None, size=None):
"""Return default values for start and end if they are None.
If this IntelHex object is empty then it's error to
invoke this method with both start and end as None.
"""
if (start,end) == (None,None) and self._buf == {}:
raise EmptyIntelHexError
if size is not None:
if None not in (start, end):
raise ValueError("tobinarray: you can't use start,end and size"
" arguments in the same time")
if (start, end) == (None, None):
start = self.minaddr()
if start is not None:
end = start + size - 1
else:
start = end - size + 1
if start < 0:
raise ValueError("tobinarray: invalid size (%d) "
"for given end address (%d)" % (size,end))
else:
if start is None:
start = self.minaddr()
if end is None:
end = self.maxaddr()
if start > end:
start, end = end, start
return start, end |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:dump; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:tofile; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:width; 10, integer:16; 11, default_parameter; 11, 12; 11, 13; 12, identifier:withpadding; 13, False; 14, block; 14, 15; 14, 17; 14, 34; 14, 35; 14, 42; 14, 53; 14, 54; 14, 151; 14, 152; 14, 161; 15, expression_statement; 15, 16; 16, comment; 17, if_statement; 17, 18; 17, 28; 18, boolean_operator:or; 18, 19; 18, 25; 19, not_operator; 19, 20; 20, call; 20, 21; 20, 22; 21, identifier:isinstance; 22, argument_list; 22, 23; 22, 24; 23, identifier:width; 24, identifier:int; 25, comparison_operator:<; 25, 26; 25, 27; 26, identifier:width; 27, integer:1; 28, block; 28, 29; 29, raise_statement; 29, 30; 30, call; 30, 31; 30, 32; 31, identifier:ValueError; 32, argument_list; 32, 33; 33, string:'width must be a positive integer.'; 34, comment; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:width; 38, call; 38, 39; 38, 40; 39, identifier:int; 40, argument_list; 40, 41; 41, identifier:width; 42, if_statement; 42, 43; 42, 46; 43, comparison_operator:is; 43, 44; 43, 45; 44, identifier:tofile; 45, None; 46, block; 46, 47; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:tofile; 50, attribute; 50, 51; 50, 52; 51, identifier:sys; 52, identifier:stdout; 53, comment; 54, if_statement; 54, 55; 54, 60; 55, comparison_operator:is; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:self; 58, identifier:start_addr; 59, None; 60, block; 60, 61; 60, 72; 60, 83; 60, 94; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:cs; 64, call; 64, 65; 64, 70; 65, attribute; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:start_addr; 69, identifier:get; 70, argument_list; 70, 71; 71, string:'CS'; 72, expression_statement; 72, 73; 73, assignment; 73, 74; 73, 75; 74, identifier:ip; 75, call; 75, 76; 75, 81; 76, attribute; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:self; 79, identifier:start_addr; 80, identifier:get; 81, argument_list; 81, 82; 82, string:'IP'; 83, expression_statement; 83, 84; 84, assignment; 84, 85; 84, 86; 85, identifier:eip; 86, call; 86, 87; 86, 92; 87, attribute; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:self; 90, identifier:start_addr; 91, identifier:get; 92, argument_list; 92, 93; 93, string:'EIP'; 94, if_statement; 94, 95; 94, 106; 94, 116; 94, 140; 95, boolean_operator:and; 95, 96; 95, 103; 96, boolean_operator:and; 96, 97; 96, 100; 97, comparison_operator:is; 97, 98; 97, 99; 98, identifier:eip; 99, None; 100, comparison_operator:is; 100, 101; 100, 102; 101, identifier:cs; 102, None; 103, comparison_operator:is; 103, 104; 103, 105; 104, identifier:ip; 105, None; 106, block; 106, 107; 107, expression_statement; 107, 108; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:tofile; 111, identifier:write; 112, argument_list; 112, 113; 113, binary_operator:%; 113, 114; 113, 115; 114, string:'EIP = 0x%08X\n'; 115, identifier:eip; 116, elif_clause; 116, 117; 116, 128; 117, boolean_operator:and; 117, 118; 117, 125; 118, boolean_operator:and; 118, 119; 118, 122; 119, comparison_operator:is; 119, 120; 119, 121; 120, identifier:eip; 121, None; 122, comparison_operator:is; 122, 123; 122, 124; 123, identifier:cs; 124, None; 125, comparison_operator:is; 125, 126; 125, 127; 126, identifier:ip; 127, None; 128, block; 128, 129; 129, expression_statement; 129, 130; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:tofile; 133, identifier:write; 134, argument_list; 134, 135; 135, binary_operator:%; 135, 136; 135, 137; 136, string:'CS = 0x%04X, IP = 0x%04X\n'; 137, tuple; 137, 138; 137, 139; 138, identifier:cs; 139, identifier:ip; 140, else_clause; 140, 141; 141, block; 141, 142; 142, expression_statement; 142, 143; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:tofile; 146, identifier:write; 147, argument_list; 147, 148; 148, binary_operator:%; 148, 149; 148, 150; 149, string:'start_addr = %r\n'; 150, identifier:start_addr; 151, comment; 152, expression_statement; 152, 153; 153, assignment; 153, 154; 153, 155; 154, identifier:addresses; 155, call; 155, 156; 155, 157; 156, identifier:dict_keys; 157, argument_list; 157, 158; 158, attribute; 158, 159; 158, 160; 159, identifier:self; 160, identifier:_buf; 161, if_statement; 161, 162; 161, 163; 162, identifier:addresses; 163, block; 163, 164; 163, 170; 163, 176; 163, 183; 163, 192; 163, 204; 163, 220; 163, 221; 163, 227; 163, 234; 163, 249; 164, expression_statement; 164, 165; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:addresses; 168, identifier:sort; 169, argument_list; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 173; 172, identifier:minaddr; 173, subscript; 173, 174; 173, 175; 174, identifier:addresses; 175, integer:0; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 179; 178, identifier:maxaddr; 179, subscript; 179, 180; 179, 181; 180, identifier:addresses; 181, unary_operator:-; 181, 182; 182, integer:1; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 186; 185, identifier:startaddr; 186, binary_operator:*; 186, 187; 186, 191; 187, parenthesized_expression; 187, 188; 188, binary_operator://; 188, 189; 188, 190; 189, identifier:minaddr; 190, identifier:width; 191, identifier:width; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 195; 194, identifier:endaddr; 195, binary_operator:*; 195, 196; 195, 203; 196, parenthesized_expression; 196, 197; 197, binary_operator:+; 197, 198; 197, 202; 198, parenthesized_expression; 198, 199; 199, binary_operator://; 199, 200; 199, 201; 200, identifier:maxaddr; 201, identifier:width; 202, integer:1; 203, identifier:width; 204, expression_statement; 204, 205; 205, assignment; 205, 206; 205, 207; 206, identifier:maxdigits; 207, call; 207, 208; 207, 209; 208, identifier:max; 209, argument_list; 209, 210; 209, 219; 210, binary_operator:-; 210, 211; 210, 218; 211, call; 211, 212; 211, 213; 212, identifier:len; 213, argument_list; 213, 214; 214, call; 214, 215; 214, 216; 215, identifier:hex; 216, argument_list; 216, 217; 217, identifier:endaddr; 218, integer:2; 219, integer:4; 220, comment; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 224; 223, identifier:templa; 224, binary_operator:%; 224, 225; 224, 226; 225, string:'%%0%dX'; 226, identifier:maxdigits; 227, expression_statement; 227, 228; 228, assignment; 228, 229; 228, 230; 229, identifier:rangewidth; 230, call; 230, 231; 230, 232; 231, identifier:range_l; 232, argument_list; 232, 233; 233, identifier:width; 234, if_statement; 234, 235; 234, 236; 234, 243; 235, identifier:withpadding; 236, block; 236, 237; 237, expression_statement; 237, 238; 238, assignment; 238, 239; 238, 240; 239, identifier:pad; 240, attribute; 240, 241; 240, 242; 241, identifier:self; 242, identifier:padding; 243, else_clause; 243, 244; 244, block; 244, 245; 245, expression_statement; 245, 246; 246, assignment; 246, 247; 246, 248; 247, identifier:pad; 248, None; 249, for_statement; 249, 250; 249, 251; 249, 257; 250, identifier:i; 251, call; 251, 252; 251, 253; 252, identifier:range_g; 253, argument_list; 253, 254; 253, 255; 253, 256; 254, identifier:startaddr; 255, identifier:endaddr; 256, identifier:width; 257, block; 257, 258; 257, 267; 257, 274; 257, 278; 257, 352; 258, expression_statement; 258, 259; 259, call; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, identifier:tofile; 262, identifier:write; 263, argument_list; 263, 264; 264, binary_operator:%; 264, 265; 264, 266; 265, identifier:templa; 266, identifier:i; 267, expression_statement; 267, 268; 268, call; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:tofile; 271, identifier:write; 272, argument_list; 272, 273; 273, string:' '; 274, expression_statement; 274, 275; 275, assignment; 275, 276; 275, 277; 276, identifier:s; 277, list:[]; 278, for_statement; 278, 279; 278, 280; 278, 281; 279, identifier:j; 280, identifier:rangewidth; 281, block; 281, 282; 281, 296; 282, expression_statement; 282, 283; 283, assignment; 283, 284; 283, 285; 284, identifier:x; 285, call; 285, 286; 285, 291; 286, attribute; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:self; 289, identifier:_buf; 290, identifier:get; 291, argument_list; 291, 292; 291, 295; 292, binary_operator:+; 292, 293; 292, 294; 293, identifier:i; 294, identifier:j; 295, identifier:pad; 296, if_statement; 296, 297; 296, 300; 296, 336; 297, comparison_operator:is; 297, 298; 297, 299; 298, identifier:x; 299, None; 300, block; 300, 301; 300, 310; 301, expression_statement; 301, 302; 302, call; 302, 303; 302, 306; 303, attribute; 303, 304; 303, 305; 304, identifier:tofile; 305, identifier:write; 306, argument_list; 306, 307; 307, binary_operator:%; 307, 308; 307, 309; 308, string:' %02X'; 309, identifier:x; 310, if_statement; 310, 311; 310, 315; 310, 316; 310, 327; 311, comparison_operator:<=; 311, 312; 311, 313; 311, 314; 312, integer:32; 313, identifier:x; 314, integer:127; 315, comment; 316, block; 316, 317; 317, expression_statement; 317, 318; 318, call; 318, 319; 318, 322; 319, attribute; 319, 320; 319, 321; 320, identifier:s; 321, identifier:append; 322, argument_list; 322, 323; 323, call; 323, 324; 323, 325; 324, identifier:chr; 325, argument_list; 325, 326; 326, identifier:x; 327, else_clause; 327, 328; 328, block; 328, 329; 329, expression_statement; 329, 330; 330, call; 330, 331; 330, 334; 331, attribute; 331, 332; 331, 333; 332, identifier:s; 333, identifier:append; 334, argument_list; 334, 335; 335, string:'.'; 336, else_clause; 336, 337; 337, block; 337, 338; 337, 345; 338, expression_statement; 338, 339; 339, call; 339, 340; 339, 343; 340, attribute; 340, 341; 340, 342; 341, identifier:tofile; 342, identifier:write; 343, argument_list; 343, 344; 344, string:' --'; 345, expression_statement; 345, 346; 346, call; 346, 347; 346, 350; 347, attribute; 347, 348; 347, 349; 348, identifier:s; 349, identifier:append; 350, argument_list; 350, 351; 351, string:' '; 352, expression_statement; 352, 353; 353, call; 353, 354; 353, 357; 354, attribute; 354, 355; 354, 356; 355, identifier:tofile; 356, identifier:write; 357, argument_list; 357, 358; 358, binary_operator:+; 358, 359; 358, 367; 359, binary_operator:+; 359, 360; 359, 361; 360, string:' |'; 361, call; 361, 362; 361, 365; 362, attribute; 362, 363; 362, 364; 363, string:''; 364, identifier:join; 365, argument_list; 365, 366; 366, identifier:s; 367, string:'|\n' | def dump(self, tofile=None, width=16, withpadding=False):
"""Dump object content to specified file object or to stdout if None.
Format is a hexdump with some header information at the beginning,
addresses on the left, and data on right.
@param tofile file-like object to dump to
@param width number of bytes per line (i.e. columns)
@param withpadding print padding character instead of '--'
@raise ValueError if width is not a positive integer
"""
if not isinstance(width,int) or width < 1:
raise ValueError('width must be a positive integer.')
# The integer can be of float type - does not work with bit operations
width = int(width)
if tofile is None:
tofile = sys.stdout
# start addr possibly
if self.start_addr is not None:
cs = self.start_addr.get('CS')
ip = self.start_addr.get('IP')
eip = self.start_addr.get('EIP')
if eip is not None and cs is None and ip is None:
tofile.write('EIP = 0x%08X\n' % eip)
elif eip is None and cs is not None and ip is not None:
tofile.write('CS = 0x%04X, IP = 0x%04X\n' % (cs, ip))
else:
tofile.write('start_addr = %r\n' % start_addr)
# actual data
addresses = dict_keys(self._buf)
if addresses:
addresses.sort()
minaddr = addresses[0]
maxaddr = addresses[-1]
startaddr = (minaddr // width) * width
endaddr = ((maxaddr // width) + 1) * width
maxdigits = max(len(hex(endaddr)) - 2, 4) # Less 2 to exclude '0x'
templa = '%%0%dX' % maxdigits
rangewidth = range_l(width)
if withpadding:
pad = self.padding
else:
pad = None
for i in range_g(startaddr, endaddr, width):
tofile.write(templa % i)
tofile.write(' ')
s = []
for j in rangewidth:
x = self._buf.get(i+j, pad)
if x is not None:
tofile.write(' %02X' % x)
if 32 <= x < 127: # GNU less does not like 0x7F (128 decimal) so we'd better show it as dot
s.append(chr(x))
else:
s.append('.')
else:
tofile.write(' --')
s.append(' ')
tofile.write(' |' + ''.join(s) + '|\n') |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:add_recipe_folder; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:recipe_folder; 6, default_parameter; 6, 7; 6, 8; 7, identifier:whitelist; 8, None; 9, block; 9, 10; 9, 12; 9, 24; 9, 33; 9, 96; 10, expression_statement; 10, 11; 11, comment; 12, if_statement; 12, 13; 12, 16; 13, comparison_operator:is; 13, 14; 13, 15; 14, identifier:whitelist; 15, None; 16, block; 16, 17; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:whitelist; 20, call; 20, 21; 20, 22; 21, identifier:set; 22, argument_list; 22, 23; 23, identifier:whitelist; 24, if_statement; 24, 25; 24, 28; 25, comparison_operator:==; 25, 26; 25, 27; 26, identifier:recipe_folder; 27, string:''; 28, block; 28, 29; 29, expression_statement; 29, 30; 30, assignment; 30, 31; 30, 32; 31, identifier:recipe_folder; 32, string:'.'; 33, for_statement; 33, 34; 33, 35; 33, 52; 34, identifier:yaml_file; 35, list_comprehension; 35, 36; 35, 37; 35, 45; 36, identifier:x; 37, for_in_clause; 37, 38; 37, 39; 38, identifier:x; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:os; 42, identifier:listdir; 43, argument_list; 43, 44; 44, identifier:recipe_folder; 45, if_clause; 45, 46; 46, call; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:x; 49, identifier:endswith; 50, argument_list; 50, 51; 51, string:'.yaml'; 52, block; 52, 53; 52, 63; 52, 86; 53, if_statement; 53, 54; 53, 61; 54, boolean_operator:and; 54, 55; 54, 58; 55, comparison_operator:is; 55, 56; 55, 57; 56, identifier:whitelist; 57, None; 58, comparison_operator:not; 58, 59; 58, 60; 59, identifier:yaml_file; 60, identifier:whitelist; 61, block; 61, 62; 62, continue_statement; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:recipe; 66, call; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:RecipeObject; 69, identifier:FromFile; 70, argument_list; 70, 71; 70, 80; 70, 83; 71, call; 71, 72; 71, 77; 72, attribute; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:os; 75, identifier:path; 76, identifier:join; 77, argument_list; 77, 78; 77, 79; 78, identifier:recipe_folder; 79, identifier:yaml_file; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:_recipe_actions; 83, attribute; 83, 84; 83, 85; 84, identifier:self; 85, identifier:_recipe_resources; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 95; 88, subscript; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:self; 91, identifier:_recipes; 92, attribute; 92, 93; 92, 94; 93, identifier:recipe; 94, identifier:name; 95, identifier:recipe; 96, for_statement; 96, 97; 96, 98; 96, 115; 97, identifier:ship_file; 98, list_comprehension; 98, 99; 98, 100; 98, 108; 99, identifier:x; 100, for_in_clause; 100, 101; 100, 102; 101, identifier:x; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:os; 105, identifier:listdir; 106, argument_list; 106, 107; 107, identifier:recipe_folder; 108, if_clause; 108, 109; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:x; 112, identifier:endswith; 113, argument_list; 113, 114; 114, string:'.ship'; 115, block; 115, 116; 115, 126; 115, 149; 116, if_statement; 116, 117; 116, 124; 117, boolean_operator:and; 117, 118; 117, 121; 118, comparison_operator:is; 118, 119; 118, 120; 119, identifier:whitelist; 120, None; 121, comparison_operator:not; 121, 122; 121, 123; 122, identifier:ship_file; 123, identifier:whitelist; 124, block; 124, 125; 125, continue_statement; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:recipe; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:RecipeObject; 132, identifier:FromArchive; 133, argument_list; 133, 134; 133, 143; 133, 146; 134, call; 134, 135; 134, 140; 135, attribute; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:os; 138, identifier:path; 139, identifier:join; 140, argument_list; 140, 141; 140, 142; 141, identifier:recipe_folder; 142, identifier:ship_file; 143, attribute; 143, 144; 143, 145; 144, identifier:self; 145, identifier:_recipe_actions; 146, attribute; 146, 147; 146, 148; 147, identifier:self; 148, identifier:_recipe_resources; 149, expression_statement; 149, 150; 150, assignment; 150, 151; 150, 158; 151, subscript; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:self; 154, identifier:_recipes; 155, attribute; 155, 156; 155, 157; 156, identifier:recipe; 157, identifier:name; 158, identifier:recipe | def add_recipe_folder(self, recipe_folder, whitelist=None):
"""Add all recipes inside a folder to this RecipeManager with an optional whitelist.
Args:
recipe_folder (str): The path to the folder of recipes to add.
whitelist (list): Only include files whose os.basename() matches something
on the whitelist
"""
if whitelist is not None:
whitelist = set(whitelist)
if recipe_folder == '':
recipe_folder = '.'
for yaml_file in [x for x in os.listdir(recipe_folder) if x.endswith('.yaml')]:
if whitelist is not None and yaml_file not in whitelist:
continue
recipe = RecipeObject.FromFile(os.path.join(recipe_folder, yaml_file), self._recipe_actions, self._recipe_resources)
self._recipes[recipe.name] = recipe
for ship_file in [x for x in os.listdir(recipe_folder) if x.endswith('.ship')]:
if whitelist is not None and ship_file not in whitelist:
continue
recipe = RecipeObject.FromArchive(os.path.join(recipe_folder, ship_file), self._recipe_actions, self._recipe_resources)
self._recipes[recipe.name] = recipe |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:run; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:include_reset; 7, True; 8, default_parameter; 8, 9; 8, 10; 9, identifier:accelerated; 10, True; 11, block; 11, 12; 11, 14; 11, 22; 11, 33; 11, 38; 11, 39; 11, 43; 11, 96; 11, 117; 12, expression_statement; 12, 13; 13, comment; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:_start_tick; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:tick_count; 22, if_statement; 22, 23; 22, 31; 23, call; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:_check_stop_conditions; 27, argument_list; 27, 28; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:sensor_graph; 31, block; 31, 32; 32, return_statement; 33, if_statement; 33, 34; 33, 35; 34, identifier:include_reset; 35, block; 35, 36; 35, 37; 36, pass_statement; 37, comment; 38, comment; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:i; 42, None; 43, for_statement; 43, 44; 43, 47; 43, 53; 44, pattern_list; 44, 45; 44, 46; 45, identifier:i; 46, identifier:stim; 47, call; 47, 48; 47, 49; 48, identifier:enumerate; 49, argument_list; 49, 50; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:stimuli; 53, block; 53, 54; 53, 62; 53, 81; 54, if_statement; 54, 55; 54, 60; 55, comparison_operator:!=; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:stim; 58, identifier:time; 59, integer:0; 60, block; 60, 61; 61, break_statement; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:reading; 65, call; 65, 66; 65, 67; 66, identifier:IOTileReading; 67, argument_list; 67, 68; 67, 71; 67, 78; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:tick_count; 71, call; 71, 72; 71, 77; 72, attribute; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:stim; 75, identifier:stream; 76, identifier:encode; 77, argument_list; 78, attribute; 78, 79; 78, 80; 79, identifier:stim; 80, identifier:value; 81, expression_statement; 81, 82; 82, call; 82, 83; 82, 88; 83, attribute; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:sensor_graph; 87, identifier:process_input; 88, argument_list; 88, 89; 88, 92; 88, 93; 89, attribute; 89, 90; 89, 91; 90, identifier:stim; 91, identifier:stream; 92, identifier:reading; 93, attribute; 93, 94; 93, 95; 94, identifier:self; 95, identifier:rpc_executor; 96, if_statement; 96, 97; 96, 104; 97, boolean_operator:and; 97, 98; 97, 101; 98, comparison_operator:is; 98, 99; 98, 100; 99, identifier:i; 100, None; 101, comparison_operator:>; 101, 102; 101, 103; 102, identifier:i; 103, integer:0; 104, block; 104, 105; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:self; 109, identifier:stimuli; 110, subscript; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:self; 113, identifier:stimuli; 114, slice; 114, 115; 114, 116; 115, identifier:i; 116, colon; 117, while_statement; 117, 118; 117, 127; 117, 128; 118, not_operator; 118, 119; 119, call; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:self; 122, identifier:_check_stop_conditions; 123, argument_list; 123, 124; 124, attribute; 124, 125; 124, 126; 125, identifier:self; 126, identifier:sensor_graph; 127, comment; 128, block; 128, 129; 128, 135; 128, 141; 128, 142; 128, 143; 128, 149; 128, 150; 128, 154; 128, 209; 128, 230; 128, 239; 128, 315; 128, 321; 128, 322; 128, 323; 129, expression_statement; 129, 130; 130, assignment; 130, 131; 130, 132; 131, identifier:now; 132, call; 132, 133; 132, 134; 133, identifier:monotonic; 134, argument_list; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:next_tick; 138, binary_operator:+; 138, 139; 138, 140; 139, identifier:now; 140, float:1.0; 141, comment; 142, comment; 143, expression_statement; 143, 144; 144, augmented_assignment:+=; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:self; 147, identifier:tick_count; 148, integer:1; 149, comment; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:i; 153, None; 154, for_statement; 154, 155; 154, 158; 154, 164; 155, pattern_list; 155, 156; 155, 157; 156, identifier:i; 157, identifier:stim; 158, call; 158, 159; 158, 160; 159, identifier:enumerate; 160, argument_list; 160, 161; 161, attribute; 161, 162; 161, 163; 162, identifier:self; 163, identifier:stimuli; 164, block; 164, 165; 164, 175; 164, 194; 165, if_statement; 165, 166; 165, 173; 166, comparison_operator:!=; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:stim; 169, identifier:time; 170, attribute; 170, 171; 170, 172; 171, identifier:self; 172, identifier:tick_count; 173, block; 173, 174; 174, break_statement; 175, expression_statement; 175, 176; 176, assignment; 176, 177; 176, 178; 177, identifier:reading; 178, call; 178, 179; 178, 180; 179, identifier:IOTileReading; 180, argument_list; 180, 181; 180, 184; 180, 191; 181, attribute; 181, 182; 181, 183; 182, identifier:self; 183, identifier:tick_count; 184, call; 184, 185; 184, 190; 185, attribute; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:stim; 188, identifier:stream; 189, identifier:encode; 190, argument_list; 191, attribute; 191, 192; 191, 193; 192, identifier:stim; 193, identifier:value; 194, expression_statement; 194, 195; 195, call; 195, 196; 195, 201; 196, attribute; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:self; 199, identifier:sensor_graph; 200, identifier:process_input; 201, argument_list; 201, 202; 201, 205; 201, 206; 202, attribute; 202, 203; 202, 204; 203, identifier:stim; 204, identifier:stream; 205, identifier:reading; 206, attribute; 206, 207; 206, 208; 207, identifier:self; 208, identifier:rpc_executor; 209, if_statement; 209, 210; 209, 217; 210, boolean_operator:and; 210, 211; 210, 214; 211, comparison_operator:is; 211, 212; 211, 213; 212, identifier:i; 213, None; 214, comparison_operator:>; 214, 215; 214, 216; 215, identifier:i; 216, integer:0; 217, block; 217, 218; 218, expression_statement; 218, 219; 219, assignment; 219, 220; 219, 223; 220, attribute; 220, 221; 220, 222; 221, identifier:self; 222, identifier:stimuli; 223, subscript; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:self; 226, identifier:stimuli; 227, slice; 227, 228; 227, 229; 228, identifier:i; 229, colon; 230, expression_statement; 230, 231; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:self; 234, identifier:_check_additional_ticks; 235, argument_list; 235, 236; 236, attribute; 236, 237; 236, 238; 237, identifier:self; 238, identifier:tick_count; 239, if_statement; 239, 240; 239, 248; 240, comparison_operator:==; 240, 241; 240, 247; 241, parenthesized_expression; 241, 242; 242, binary_operator:%; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:self; 245, identifier:tick_count; 246, integer:10; 247, integer:0; 248, block; 248, 249; 248, 266; 248, 279; 248, 280; 248, 302; 249, expression_statement; 249, 250; 250, assignment; 250, 251; 250, 252; 251, identifier:reading; 252, call; 252, 253; 252, 254; 253, identifier:IOTileReading; 254, argument_list; 254, 255; 254, 258; 254, 263; 255, attribute; 255, 256; 255, 257; 256, identifier:self; 257, identifier:tick_count; 258, call; 258, 259; 258, 262; 259, attribute; 259, 260; 259, 261; 260, identifier:system_tick; 261, identifier:encode; 262, argument_list; 263, attribute; 263, 264; 263, 265; 264, identifier:self; 265, identifier:tick_count; 266, expression_statement; 266, 267; 267, call; 267, 268; 267, 273; 268, attribute; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:self; 271, identifier:sensor_graph; 272, identifier:process_input; 273, argument_list; 273, 274; 273, 275; 273, 276; 274, identifier:system_tick; 275, identifier:reading; 276, attribute; 276, 277; 276, 278; 277, identifier:self; 278, identifier:rpc_executor; 279, comment; 280, expression_statement; 280, 281; 281, assignment; 281, 282; 281, 283; 282, identifier:reading; 283, call; 283, 284; 283, 285; 284, identifier:IOTileReading; 285, argument_list; 285, 286; 285, 289; 285, 294; 286, attribute; 286, 287; 286, 288; 287, identifier:self; 288, identifier:tick_count; 289, call; 289, 290; 289, 293; 290, attribute; 290, 291; 290, 292; 291, identifier:battery_voltage; 292, identifier:encode; 293, argument_list; 294, call; 294, 295; 294, 296; 295, identifier:int; 296, argument_list; 296, 297; 297, binary_operator:*; 297, 298; 297, 301; 298, attribute; 298, 299; 298, 300; 299, identifier:self; 300, identifier:voltage; 301, integer:65536; 302, expression_statement; 302, 303; 303, call; 303, 304; 303, 309; 304, attribute; 304, 305; 304, 308; 305, attribute; 305, 306; 305, 307; 306, identifier:self; 307, identifier:sensor_graph; 308, identifier:process_input; 309, argument_list; 309, 310; 309, 311; 309, 312; 310, identifier:battery_voltage; 311, identifier:reading; 312, attribute; 312, 313; 312, 314; 313, identifier:self; 314, identifier:rpc_executor; 315, expression_statement; 315, 316; 316, assignment; 316, 317; 316, 318; 317, identifier:now; 318, call; 318, 319; 318, 320; 319, identifier:monotonic; 320, argument_list; 321, comment; 322, comment; 323, if_statement; 323, 324; 323, 332; 324, boolean_operator:and; 324, 325; 324, 328; 325, parenthesized_expression; 325, 326; 326, not_operator; 326, 327; 327, identifier:accelerated; 328, parenthesized_expression; 328, 329; 329, comparison_operator:<; 329, 330; 329, 331; 330, identifier:now; 331, identifier:next_tick; 332, block; 332, 333; 333, expression_statement; 333, 334; 334, call; 334, 335; 334, 338; 335, attribute; 335, 336; 335, 337; 336, identifier:time; 337, identifier:sleep; 338, argument_list; 338, 339; 339, binary_operator:-; 339, 340; 339, 341; 340, identifier:next_tick; 341, identifier:now | def run(self, include_reset=True, accelerated=True):
"""Run this sensor graph until a stop condition is hit.
Multiple calls to this function are useful only if
there has been some change in the stop conditions that would
cause the second call to not exit immediately.
Args:
include_reset (bool): Start the sensor graph run with
a reset event to match what would happen when an
actual device powers on.
accelerated (bool): Whether to run this sensor graph as
fast as possible or to delay tick events to simulate
the actual passage of wall clock time.
"""
self._start_tick = self.tick_count
if self._check_stop_conditions(self.sensor_graph):
return
if include_reset:
pass # TODO: include a reset event here
# Process all stimuli that occur at the start of the simulation
i = None
for i, stim in enumerate(self.stimuli):
if stim.time != 0:
break
reading = IOTileReading(self.tick_count, stim.stream.encode(), stim.value)
self.sensor_graph.process_input(stim.stream, reading, self.rpc_executor)
if i is not None and i > 0:
self.stimuli = self.stimuli[i:]
while not self._check_stop_conditions(self.sensor_graph):
# Process one more one second tick
now = monotonic()
next_tick = now + 1.0
# To match what is done in actual hardware, we increment tick count so the first tick
# is 1.
self.tick_count += 1
# Process all stimuli that occur at this tick of the simulation
i = None
for i, stim in enumerate(self.stimuli):
if stim.time != self.tick_count:
break
reading = IOTileReading(self.tick_count, stim.stream.encode(), stim.value)
self.sensor_graph.process_input(stim.stream, reading, self.rpc_executor)
if i is not None and i > 0:
self.stimuli = self.stimuli[i:]
self._check_additional_ticks(self.tick_count)
if (self.tick_count % 10) == 0:
reading = IOTileReading(self.tick_count, system_tick.encode(), self.tick_count)
self.sensor_graph.process_input(system_tick, reading, self.rpc_executor)
# Every 10 seconds the battery voltage is reported in 16.16 fixed point format in volts
reading = IOTileReading(self.tick_count, battery_voltage.encode(), int(self.voltage * 65536))
self.sensor_graph.process_input(battery_voltage, reading, self.rpc_executor)
now = monotonic()
# If we are trying to execute this sensor graph in realtime, wait for
# the remaining slice of this tick.
if (not accelerated) and (now < next_tick):
time.sleep(next_tick - now) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_convert_default_value; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:default; 6, block; 6, 7; 6, 9; 6, 16; 6, 47; 6, 75; 6, 87; 6, 101; 7, expression_statement; 7, 8; 8, comment; 9, if_statement; 9, 10; 9, 13; 10, comparison_operator:is; 10, 11; 10, 12; 11, identifier:default; 12, None; 13, block; 13, 14; 14, return_statement; 14, 15; 15, None; 16, if_statement; 16, 17; 16, 22; 17, call; 17, 18; 17, 19; 18, identifier:isinstance; 19, argument_list; 19, 20; 19, 21; 20, identifier:default; 21, identifier:str; 22, block; 22, 23; 22, 39; 23, if_statement; 23, 24; 23, 29; 24, comparison_operator:==; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:special_type; 28, string:'string'; 29, block; 29, 30; 30, return_statement; 30, 31; 31, binary_operator:+; 31, 32; 31, 38; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:default; 35, identifier:encode; 36, argument_list; 36, 37; 37, string:'utf-8'; 38, string:b'\0'; 39, raise_statement; 39, 40; 40, call; 40, 41; 40, 42; 41, identifier:DataError; 42, argument_list; 42, 43; 42, 44; 43, string:"You can only pass a unicode string if you are declaring a string type config variable"; 44, keyword_argument; 44, 45; 44, 46; 45, identifier:default; 46, identifier:default; 47, if_statement; 47, 48; 47, 55; 48, call; 48, 49; 48, 50; 49, identifier:isinstance; 50, argument_list; 50, 51; 50, 52; 51, identifier:default; 52, tuple; 52, 53; 52, 54; 53, identifier:bytes; 54, identifier:bytearray; 55, block; 55, 56; 55, 73; 56, if_statement; 56, 57; 56, 68; 57, boolean_operator:and; 57, 58; 57, 63; 58, comparison_operator:==; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:special_type; 62, string:'string'; 63, call; 63, 64; 63, 65; 64, identifier:isinstance; 65, argument_list; 65, 66; 65, 67; 66, identifier:default; 67, identifier:bytes; 68, block; 68, 69; 69, expression_statement; 69, 70; 70, augmented_assignment:+=; 70, 71; 70, 72; 71, identifier:default; 72, string:b'\0'; 73, return_statement; 73, 74; 74, identifier:default; 75, if_statement; 75, 76; 75, 81; 76, call; 76, 77; 76, 78; 77, identifier:isinstance; 78, argument_list; 78, 79; 78, 80; 79, identifier:default; 80, identifier:int; 81, block; 81, 82; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:default; 85, list:[default]; 85, 86; 86, identifier:default; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:format_string; 90, binary_operator:+; 90, 91; 90, 92; 91, string:"<"; 92, parenthesized_expression; 92, 93; 93, binary_operator:*; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:self; 96, identifier:base_type; 97, call; 97, 98; 97, 99; 98, identifier:len; 99, argument_list; 99, 100; 100, identifier:default; 101, return_statement; 101, 102; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:struct; 105, identifier:pack; 106, argument_list; 106, 107; 106, 108; 107, identifier:format_string; 108, list_splat; 108, 109; 109, identifier:default | def _convert_default_value(self, default):
"""Convert the passed default value to binary.
The default value (if passed) may be specified as either a `bytes`
object or a python int or list of ints. If an int or list of ints is
passed, it is converted to binary. Otherwise, the raw binary data is
used.
If you pass a bytes object with python_type as True, do not null terminate
it, an additional null termination will be added.
Passing a unicode string is only allowed if as_string is True and it
will be encoded as utf-8 and null terminated for use as a default value.
"""
if default is None:
return None
if isinstance(default, str):
if self.special_type == 'string':
return default.encode('utf-8') + b'\0'
raise DataError("You can only pass a unicode string if you are declaring a string type config variable", default=default)
if isinstance(default, (bytes, bytearray)):
if self.special_type == 'string' and isinstance(default, bytes):
default += b'\0'
return default
if isinstance(default, int):
default = [default]
format_string = "<" + (self.base_type*len(default))
return struct.pack(format_string, *default) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:latch; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 28; 5, 29; 5, 30; 5, 43; 5, 57; 5, 106; 5, 127; 5, 139; 5, 173; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 17; 9, comparison_operator:==; 9, 10; 9, 16; 10, call; 10, 11; 10, 12; 11, identifier:len; 12, argument_list; 12, 13; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:current_value; 16, integer:0; 17, block; 17, 18; 18, raise_statement; 18, 19; 19, call; 19, 20; 19, 21; 20, identifier:DataError; 21, argument_list; 21, 22; 21, 23; 22, string:"There was no data in a config variable during latching"; 23, keyword_argument; 23, 24; 23, 25; 24, identifier:name; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:name; 28, comment; 29, comment; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:remaining; 33, binary_operator:%; 33, 34; 33, 40; 34, call; 34, 35; 34, 36; 35, identifier:len; 36, argument_list; 36, 37; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:current_value; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:unit_size; 43, if_statement; 43, 44; 43, 47; 44, comparison_operator:>; 44, 45; 44, 46; 45, identifier:remaining; 46, integer:0; 47, block; 47, 48; 48, expression_statement; 48, 49; 49, augmented_assignment:+=; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:current_value; 53, call; 53, 54; 53, 55; 54, identifier:bytearray; 55, argument_list; 55, 56; 56, identifier:remaining; 57, if_statement; 57, 58; 57, 63; 58, comparison_operator:==; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:special_type; 62, string:'string'; 63, block; 63, 64; 63, 89; 64, if_statement; 64, 65; 64, 73; 65, comparison_operator:!=; 65, 66; 65, 72; 66, subscript; 66, 67; 66, 70; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:current_value; 70, unary_operator:-; 70, 71; 71, integer:1; 72, integer:0; 73, block; 73, 74; 74, raise_statement; 74, 75; 75, call; 75, 76; 75, 77; 76, identifier:DataError; 77, argument_list; 77, 78; 77, 79; 77, 84; 78, string:"String type was specified by data did not end with a null byte"; 79, keyword_argument; 79, 80; 79, 81; 80, identifier:data; 81, attribute; 81, 82; 81, 83; 82, identifier:self; 83, identifier:current_value; 84, keyword_argument; 84, 85; 84, 86; 85, identifier:name; 86, attribute; 86, 87; 86, 88; 87, identifier:self; 88, identifier:name; 89, return_statement; 89, 90; 90, call; 90, 91; 90, 104; 91, attribute; 91, 92; 91, 103; 92, call; 92, 93; 92, 94; 93, identifier:bytes; 94, argument_list; 94, 95; 95, subscript; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:current_value; 99, slice; 99, 100; 99, 101; 100, colon; 101, unary_operator:-; 101, 102; 102, integer:1; 103, identifier:decode; 104, argument_list; 104, 105; 105, string:'utf-8'; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:fmt_code; 109, binary_operator:+; 109, 110; 109, 111; 110, string:"<"; 111, parenthesized_expression; 111, 112; 112, binary_operator:*; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:self; 115, identifier:base_type; 116, parenthesized_expression; 116, 117; 117, binary_operator://; 117, 118; 117, 124; 118, call; 118, 119; 118, 120; 119, identifier:len; 120, argument_list; 120, 121; 121, attribute; 121, 122; 121, 123; 122, identifier:self; 123, identifier:current_value; 124, attribute; 124, 125; 124, 126; 125, identifier:self; 126, identifier:unit_size; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:data; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:struct; 133, identifier:unpack; 134, argument_list; 134, 135; 134, 136; 135, identifier:fmt_code; 136, attribute; 136, 137; 136, 138; 137, identifier:self; 138, identifier:current_value; 139, if_statement; 139, 140; 139, 143; 139, 151; 140, attribute; 140, 141; 140, 142; 141, identifier:self; 142, identifier:variable; 143, block; 143, 144; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:data; 147, call; 147, 148; 147, 149; 148, identifier:list; 149, argument_list; 149, 150; 150, identifier:data; 151, else_clause; 151, 152; 152, block; 152, 153; 152, 159; 153, expression_statement; 153, 154; 154, assignment; 154, 155; 154, 156; 155, identifier:data; 156, subscript; 156, 157; 156, 158; 157, identifier:data; 158, integer:0; 159, if_statement; 159, 160; 159, 165; 160, comparison_operator:==; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:self; 163, identifier:special_type; 164, string:'bool'; 165, block; 165, 166; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 169; 168, identifier:data; 169, call; 169, 170; 169, 171; 170, identifier:bool; 171, argument_list; 171, 172; 172, identifier:data; 173, return_statement; 173, 174; 174, identifier:data | def latch(self):
"""Convert the current value inside this config descriptor to a python object.
The conversion proceeds by mapping the given type name to a native
python class and performing the conversion. You can override what
python object is used as the destination class by passing a
python_type parameter to __init__.
The default mapping is:
- char (u)int8_t, (u)int16_t, (u)int32_t: int
- char[] (u)int8_t[], (u)int16_t[]0, u(int32_t): list of int
If you want to parse a char[] or uint8_t[] as a python string, it
needs to be null terminated and you should pass python_type='string'.
If you are declaring a scalar integer type and wish it to be decoded
as a bool, you can pass python_type='bool' to the constructor.
All integers are decoded as little-endian.
Returns:
object: The corresponding python object.
This will either be an int, list of int or string based on the
type_name specified and the optional python_type keyword argument
to the constructor.
Raises:
DataError: if the object cannot be converted to the desired type.
ArgumentError: if an invalid python_type was specified during construction.
"""
if len(self.current_value) == 0:
raise DataError("There was no data in a config variable during latching", name=self.name)
# Make sure the data ends on a unit boundary. This would have happened automatically
# in an actual device by the C runtime 0 padding out the storage area.
remaining = len(self.current_value) % self.unit_size
if remaining > 0:
self.current_value += bytearray(remaining)
if self.special_type == 'string':
if self.current_value[-1] != 0:
raise DataError("String type was specified by data did not end with a null byte", data=self.current_value, name=self.name)
return bytes(self.current_value[:-1]).decode('utf-8')
fmt_code = "<" + (self.base_type * (len(self.current_value) // self.unit_size))
data = struct.unpack(fmt_code, self.current_value)
if self.variable:
data = list(data)
else:
data = data[0]
if self.special_type == 'bool':
data = bool(data)
return data |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_contents_dir; 3, parameters; 3, 4; 4, identifier:node; 5, block; 5, 6; 5, 8; 5, 12; 5, 48; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:contents; 11, list:[]; 12, for_statement; 12, 13; 12, 14; 12, 30; 13, identifier:n; 14, call; 14, 15; 14, 16; 15, identifier:sorted; 16, argument_list; 16, 17; 16, 22; 17, call; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:node; 20, identifier:children; 21, argument_list; 22, keyword_argument; 22, 23; 22, 24; 23, identifier:key; 24, lambda; 24, 25; 24, 27; 25, lambda_parameters; 25, 26; 26, identifier:t; 27, attribute; 27, 28; 27, 29; 28, identifier:t; 29, identifier:name; 30, block; 30, 31; 31, expression_statement; 31, 32; 32, call; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:contents; 35, identifier:append; 36, argument_list; 36, 37; 37, binary_operator:%; 37, 38; 37, 39; 38, string:'%s %s\n'; 39, tuple; 39, 40; 39, 45; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:n; 43, identifier:get_csig; 44, argument_list; 45, attribute; 45, 46; 45, 47; 46, identifier:n; 47, identifier:name; 48, return_statement; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, string:''; 52, identifier:join; 53, argument_list; 53, 54; 54, identifier:contents | def get_contents_dir(node):
"""Return content signatures and names of all our children
separated by new-lines. Ensure that the nodes are sorted."""
contents = []
for n in sorted(node.children(), key=lambda t: t.name):
contents.append('%s %s\n' % (n.get_csig(), n.name))
return ''.join(contents) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:prepare; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 45; 5, 82; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 14; 9, comparison_operator:is; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:self; 12, identifier:depends; 13, None; 14, block; 14, 15; 15, for_statement; 15, 16; 15, 17; 15, 20; 16, identifier:d; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:depends; 20, block; 20, 21; 21, if_statement; 21, 22; 21, 27; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:d; 25, identifier:missing; 26, argument_list; 27, block; 27, 28; 27, 32; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:msg; 31, string:"Explicit dependency `%s' not found, needed by target `%s'."; 32, raise_statement; 32, 33; 33, call; 33, 34; 33, 39; 34, attribute; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:SCons; 37, identifier:Errors; 38, identifier:StopError; 39, argument_list; 39, 40; 40, binary_operator:%; 40, 41; 40, 42; 41, identifier:msg; 42, tuple; 42, 43; 42, 44; 43, identifier:d; 44, identifier:self; 45, if_statement; 45, 46; 45, 51; 46, comparison_operator:is; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:implicit; 50, None; 51, block; 51, 52; 52, for_statement; 52, 53; 52, 54; 52, 57; 53, identifier:i; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:implicit; 57, block; 57, 58; 58, if_statement; 58, 59; 58, 64; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:i; 62, identifier:missing; 63, argument_list; 64, block; 64, 65; 64, 69; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:msg; 68, string:"Implicit dependency `%s' not found, needed by target `%s'."; 69, raise_statement; 69, 70; 70, call; 70, 71; 70, 76; 71, attribute; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:SCons; 74, identifier:Errors; 75, identifier:StopError; 76, argument_list; 76, 77; 77, binary_operator:%; 77, 78; 77, 79; 78, identifier:msg; 79, tuple; 79, 80; 79, 81; 80, identifier:i; 81, identifier:self; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:binfo; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:self; 90, identifier:get_binfo; 91, argument_list | def prepare(self):
"""Prepare for this Node to be built.
This is called after the Taskmaster has decided that the Node
is out-of-date and must be rebuilt, but before actually calling
the method to build the Node.
This default implementation checks that explicit or implicit
dependencies either exist or are derived, and initializes the
BuildInfo structure that will hold the information about how
this node is, uh, built.
(The existence of source files is checked separately by the
Executor, which aggregates checks for all of the targets built
by a specific action.)
Overriding this method allows for for a Node subclass to remove
the underlying file from the file system. Note that subclass
methods should call this base class method to get the child
check and the BuildInfo structure.
"""
if self.depends is not None:
for d in self.depends:
if d.missing():
msg = "Explicit dependency `%s' not found, needed by target `%s'."
raise SCons.Errors.StopError(msg % (d, self))
if self.implicit is not None:
for i in self.implicit:
if i.missing():
msg = "Implicit dependency `%s' not found, needed by target `%s'."
raise SCons.Errors.StopError(msg % (i, self))
self.binfo = self.get_binfo() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:scan; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 9; 5, 10; 5, 11; 5, 19; 5, 25; 5, 33; 5, 39; 5, 48; 5, 56; 5, 64; 5, 65; 5, 141; 5, 142; 5, 153; 5, 154; 5, 155; 5, 163; 6, expression_statement; 6, 7; 7, comment; 8, comment; 9, comment; 10, comment; 11, if_statement; 11, 12; 11, 17; 12, comparison_operator:is; 12, 13; 12, 16; 13, attribute; 13, 14; 13, 15; 14, identifier:self; 15, identifier:implicit; 16, None; 17, block; 17, 18; 18, return_statement; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:self; 23, identifier:implicit; 24, list:[]; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:implicit_set; 30, call; 30, 31; 30, 32; 31, identifier:set; 32, argument_list; 33, expression_statement; 33, 34; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:_children_reset; 38, argument_list; 39, if_statement; 39, 40; 39, 46; 40, not_operator; 40, 41; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:has_builder; 45, argument_list; 46, block; 46, 47; 47, return_statement; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:build_env; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:self; 54, identifier:get_build_env; 55, argument_list; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:executor; 59, call; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:get_executor; 63, argument_list; 64, comment; 65, if_statement; 65, 66; 65, 70; 66, boolean_operator:and; 66, 67; 66, 68; 67, identifier:implicit_cache; 68, not_operator; 68, 69; 69, identifier:implicit_deps_changed; 70, block; 70, 71; 70, 79; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:implicit; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:get_stored_implicit; 78, argument_list; 79, if_statement; 79, 80; 79, 83; 79, 84; 79, 85; 79, 86; 79, 87; 79, 88; 79, 89; 79, 90; 79, 91; 80, comparison_operator:is; 80, 81; 80, 82; 81, identifier:implicit; 82, None; 83, comment; 84, comment; 85, comment; 86, comment; 87, comment; 88, comment; 89, comment; 90, comment; 91, block; 91, 92; 91, 107; 91, 117; 91, 118; 91, 119; 92, for_statement; 92, 93; 92, 94; 92, 99; 93, identifier:tgt; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:executor; 97, identifier:get_all_targets; 98, argument_list; 99, block; 99, 100; 100, expression_statement; 100, 101; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:tgt; 104, identifier:add_to_implicit; 105, argument_list; 105, 106; 106, identifier:implicit; 107, if_statement; 107, 108; 107, 115; 108, boolean_operator:or; 108, 109; 108, 110; 109, identifier:implicit_deps_unchanged; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:self; 113, identifier:is_up_to_date; 114, argument_list; 115, block; 115, 116; 116, return_statement; 117, comment; 118, comment; 119, for_statement; 119, 120; 119, 121; 119, 126; 120, identifier:tgt; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:executor; 124, identifier:get_all_targets; 125, argument_list; 126, block; 126, 127; 126, 133; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 132; 129, attribute; 129, 130; 129, 131; 130, identifier:tgt; 131, identifier:implicit; 132, list:[]; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:tgt; 137, identifier:implicit_set; 138, call; 138, 139; 138, 140; 139, identifier:set; 140, argument_list; 141, comment; 142, expression_statement; 142, 143; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:executor; 146, identifier:scan_sources; 147, argument_list; 147, 148; 148, attribute; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:self; 151, identifier:builder; 152, identifier:source_scanner; 153, comment; 154, comment; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 158; 157, identifier:scanner; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:self; 161, identifier:get_target_scanner; 162, argument_list; 163, if_statement; 163, 164; 163, 165; 164, identifier:scanner; 165, block; 165, 166; 166, expression_statement; 166, 167; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:executor; 170, identifier:scan_targets; 171, argument_list; 171, 172; 172, identifier:scanner | def scan(self):
"""Scan this node's dependents for implicit dependencies."""
# Don't bother scanning non-derived files, because we don't
# care what their dependencies are.
# Don't scan again, if we already have scanned.
if self.implicit is not None:
return
self.implicit = []
self.implicit_set = set()
self._children_reset()
if not self.has_builder():
return
build_env = self.get_build_env()
executor = self.get_executor()
# Here's where we implement --implicit-cache.
if implicit_cache and not implicit_deps_changed:
implicit = self.get_stored_implicit()
if implicit is not None:
# We now add the implicit dependencies returned from the
# stored .sconsign entry to have already been converted
# to Nodes for us. (We used to run them through a
# source_factory function here.)
# Update all of the targets with them. This
# essentially short-circuits an N*M scan of the
# sources for each individual target, which is a hell
# of a lot more efficient.
for tgt in executor.get_all_targets():
tgt.add_to_implicit(implicit)
if implicit_deps_unchanged or self.is_up_to_date():
return
# one of this node's sources has changed,
# so we must recalculate the implicit deps for all targets
for tgt in executor.get_all_targets():
tgt.implicit = []
tgt.implicit_set = set()
# Have the executor scan the sources.
executor.scan_sources(self.builder.source_scanner)
# If there's a target scanner, have the executor scan the target
# node itself and associated targets that might be built.
scanner = self.get_target_scanner()
if scanner:
executor.scan_targets(scanner) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_binfo; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 18; 5, 26; 5, 32; 5, 40; 5, 46; 5, 79; 5, 113; 5, 119; 5, 141; 5, 157; 5, 165; 5, 185; 5, 195; 5, 215; 6, expression_statement; 6, 7; 7, comment; 8, try_statement; 8, 9; 8, 14; 9, block; 9, 10; 10, return_statement; 10, 11; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:binfo; 14, except_clause; 14, 15; 14, 16; 15, identifier:AttributeError; 16, block; 16, 17; 17, pass_statement; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:binfo; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:new_binfo; 25, argument_list; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:binfo; 31, identifier:binfo; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:executor; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:self; 38, identifier:get_executor; 39, argument_list; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:ignore_set; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:ignore_set; 46, if_statement; 46, 47; 46, 52; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:has_builder; 51, argument_list; 52, block; 52, 53; 52, 62; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:binfo; 57, identifier:bact; 58, call; 58, 59; 58, 60; 59, identifier:str; 60, argument_list; 60, 61; 61, identifier:executor; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:binfo; 66, identifier:bactsig; 67, call; 67, 68; 67, 73; 68, attribute; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:SCons; 71, identifier:Util; 72, identifier:MD5signature; 73, argument_list; 73, 74; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:executor; 77, identifier:get_contents; 78, argument_list; 79, if_statement; 79, 80; 79, 83; 79, 99; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:_specific_sources; 83, block; 83, 84; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:sources; 87, list_comprehension; 87, 88; 87, 89; 87, 94; 88, identifier:s; 89, for_in_clause; 89, 90; 89, 91; 90, identifier:s; 91, attribute; 91, 92; 91, 93; 92, identifier:self; 93, identifier:sources; 94, if_clause; 94, 95; 95, not_operator; 95, 96; 96, comparison_operator:in; 96, 97; 96, 98; 97, identifier:s; 98, identifier:ignore_set; 99, else_clause; 99, 100; 100, block; 100, 101; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:sources; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:executor; 107, identifier:get_unignored_sources; 108, argument_list; 108, 109; 108, 110; 109, identifier:self; 110, attribute; 110, 111; 110, 112; 111, identifier:self; 112, identifier:ignore; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:seen; 116, call; 116, 117; 116, 118; 117, identifier:set; 118, argument_list; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:binfo; 123, identifier:bsources; 124, list_comprehension; 124, 125; 124, 126; 124, 129; 125, identifier:s; 126, for_in_clause; 126, 127; 126, 128; 127, identifier:s; 128, identifier:sources; 129, if_clause; 129, 130; 130, boolean_operator:and; 130, 131; 130, 134; 131, comparison_operator:not; 131, 132; 131, 133; 132, identifier:s; 133, identifier:seen; 134, not_operator; 134, 135; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:seen; 138, identifier:add; 139, argument_list; 139, 140; 140, identifier:s; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:binfo; 145, identifier:bsourcesigs; 146, list_comprehension; 146, 147; 146, 152; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:s; 150, identifier:get_ninfo; 151, argument_list; 152, for_in_clause; 152, 153; 152, 154; 153, identifier:s; 154, attribute; 154, 155; 154, 156; 155, identifier:binfo; 156, identifier:bsources; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:binfo; 161, identifier:bdepends; 162, attribute; 162, 163; 162, 164; 163, identifier:self; 164, identifier:depends; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:binfo; 169, identifier:bdependsigs; 170, list_comprehension; 170, 171; 170, 176; 170, 181; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:d; 174, identifier:get_ninfo; 175, argument_list; 176, for_in_clause; 176, 177; 176, 178; 177, identifier:d; 178, attribute; 178, 179; 178, 180; 179, identifier:self; 180, identifier:depends; 181, if_clause; 181, 182; 182, comparison_operator:not; 182, 183; 182, 184; 183, identifier:d; 184, identifier:ignore_set; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:binfo; 189, identifier:bimplicit; 190, boolean_operator:or; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:self; 193, identifier:implicit; 194, list:[]; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 200; 197, attribute; 197, 198; 197, 199; 198, identifier:binfo; 199, identifier:bimplicitsigs; 200, list_comprehension; 200, 201; 200, 206; 200, 211; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:i; 204, identifier:get_ninfo; 205, argument_list; 206, for_in_clause; 206, 207; 206, 208; 207, identifier:i; 208, attribute; 208, 209; 208, 210; 209, identifier:binfo; 210, identifier:bimplicit; 211, if_clause; 211, 212; 212, comparison_operator:not; 212, 213; 212, 214; 213, identifier:i; 214, identifier:ignore_set; 215, return_statement; 215, 216; 216, identifier:binfo | def get_binfo(self):
"""
Fetch a node's build information.
node - the node whose sources will be collected
cache - alternate node to use for the signature cache
returns - the build signature
This no longer handles the recursive descent of the
node's children's signatures. We expect that they're
already built and updated by someone else, if that's
what's wanted.
"""
try:
return self.binfo
except AttributeError:
pass
binfo = self.new_binfo()
self.binfo = binfo
executor = self.get_executor()
ignore_set = self.ignore_set
if self.has_builder():
binfo.bact = str(executor)
binfo.bactsig = SCons.Util.MD5signature(executor.get_contents())
if self._specific_sources:
sources = [ s for s in self.sources if not s in ignore_set]
else:
sources = executor.get_unignored_sources(self, self.ignore)
seen = set()
binfo.bsources = [s for s in sources if s not in seen and not seen.add(s)]
binfo.bsourcesigs = [s.get_ninfo() for s in binfo.bsources]
binfo.bdepends = self.depends
binfo.bdependsigs = [d.get_ninfo() for d in self.depends if d not in ignore_set]
binfo.bimplicit = self.implicit or []
binfo.bimplicitsigs = [i.get_ninfo() for i in binfo.bimplicit if i not in ignore_set]
return binfo |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:main; 3, parameters; 3, 4; 4, default_parameter; 4, 5; 4, 6; 5, identifier:argv; 6, None; 7, block; 7, 8; 7, 10; 7, 25; 7, 32; 7, 38; 7, 44; 7, 48; 7, 56; 7, 91; 7, 98; 7, 106; 7, 114; 7, 122; 7, 128; 7, 136; 7, 154; 7, 158; 7, 222; 7, 223; 7, 224; 7, 239; 7, 244; 7, 245; 7, 380; 7, 381; 8, expression_statement; 8, 9; 9, comment; 10, if_statement; 10, 11; 10, 14; 11, comparison_operator:is; 11, 12; 11, 13; 12, identifier:argv; 13, None; 14, block; 14, 15; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:argv; 18, subscript; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:sys; 21, identifier:argv; 22, slice; 22, 23; 22, 24; 23, integer:1; 24, colon; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:args; 28, call; 28, 29; 28, 30; 29, identifier:parse_global_args; 30, argument_list; 30, 31; 31, identifier:argv; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 37; 34, attribute; 34, 35; 34, 36; 35, identifier:type_system; 36, identifier:interactive; 37, True; 38, expression_statement; 38, 39; 39, assignment; 39, 40; 39, 41; 40, identifier:line; 41, attribute; 41, 42; 41, 43; 42, identifier:args; 43, identifier:commands; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:timeout_thread; 47, None; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:timeout_stop_event; 51, call; 51, 52; 51, 55; 52, attribute; 52, 53; 52, 54; 53, identifier:threading; 54, identifier:Event; 55, argument_list; 56, if_statement; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:args; 59, identifier:timeout; 60, block; 60, 61; 60, 79; 60, 85; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:timeout_thread; 64, call; 64, 65; 64, 68; 65, attribute; 65, 66; 65, 67; 66, identifier:threading; 67, identifier:Thread; 68, argument_list; 68, 69; 68, 72; 69, keyword_argument; 69, 70; 69, 71; 70, identifier:target; 71, identifier:timeout_thread_handler; 72, keyword_argument; 72, 73; 72, 74; 73, identifier:args; 74, tuple; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:args; 77, identifier:timeout; 78, identifier:timeout_stop_event; 79, expression_statement; 79, 80; 80, assignment; 80, 81; 80, 84; 81, attribute; 81, 82; 81, 83; 82, identifier:timeout_thread; 83, identifier:daemon; 84, True; 85, expression_statement; 85, 86; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:timeout_thread; 89, identifier:start; 90, argument_list; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:shell; 94, call; 94, 95; 94, 96; 95, identifier:HierarchicalShell; 96, argument_list; 96, 97; 97, string:'iotile'; 98, expression_statement; 98, 99; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:shell; 102, identifier:root_add; 103, argument_list; 103, 104; 103, 105; 104, string:"registry"; 105, string:"iotile.core.dev.annotated_registry,registry"; 106, expression_statement; 106, 107; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:shell; 110, identifier:root_add; 111, argument_list; 111, 112; 111, 113; 112, string:"config"; 113, string:"iotile.core.dev.config,ConfigManager"; 114, expression_statement; 114, 115; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:shell; 118, identifier:root_add; 119, argument_list; 119, 120; 119, 121; 120, string:'hw'; 121, string:"iotile.core.hw.hwmanager,HardwareManager"; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:reg; 125, call; 125, 126; 125, 127; 126, identifier:ComponentRegistry; 127, argument_list; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:plugins; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:reg; 134, identifier:list_plugins; 135, argument_list; 136, for_statement; 136, 137; 136, 140; 136, 145; 137, pattern_list; 137, 138; 137, 139; 138, identifier:key; 139, identifier:val; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:plugins; 143, identifier:items; 144, argument_list; 145, block; 145, 146; 146, expression_statement; 146, 147; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:shell; 150, identifier:root_add; 151, argument_list; 151, 152; 151, 153; 152, identifier:key; 153, identifier:val; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:finished; 157, False; 158, try_statement; 158, 159; 158, 177; 158, 202; 159, block; 159, 160; 160, if_statement; 160, 161; 160, 167; 161, comparison_operator:>; 161, 162; 161, 166; 162, call; 162, 163; 162, 164; 163, identifier:len; 164, argument_list; 164, 165; 165, identifier:line; 166, integer:0; 167, block; 167, 168; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:finished; 171, call; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:shell; 174, identifier:invoke; 175, argument_list; 175, 176; 176, identifier:line; 177, except_clause; 177, 178; 177, 182; 178, as_pattern; 178, 179; 178, 180; 179, identifier:IOTileException; 180, as_pattern_target; 180, 181; 181, identifier:exc; 182, block; 182, 183; 182, 192; 182, 193; 182, 194; 182, 200; 183, expression_statement; 183, 184; 184, call; 184, 185; 184, 186; 185, identifier:print; 186, argument_list; 186, 187; 187, call; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:exc; 190, identifier:format; 191, argument_list; 192, comment; 193, comment; 194, expression_statement; 194, 195; 195, call; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:SharedLoop; 198, identifier:stop; 199, argument_list; 200, return_statement; 200, 201; 201, integer:1; 202, except_clause; 202, 203; 202, 204; 202, 205; 202, 206; 202, 207; 203, identifier:Exception; 204, comment; 205, comment; 206, comment; 207, block; 207, 208; 207, 214; 207, 220; 208, expression_statement; 208, 209; 209, call; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:traceback; 212, identifier:print_exc; 213, argument_list; 214, expression_statement; 214, 215; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:SharedLoop; 218, identifier:stop; 219, argument_list; 220, return_statement; 220, 221; 221, integer:1; 222, comment; 223, comment; 224, if_statement; 224, 225; 224, 230; 225, boolean_operator:or; 225, 226; 225, 229; 226, attribute; 226, 227; 226, 228; 227, identifier:args; 228, identifier:quit; 229, identifier:finished; 230, block; 230, 231; 230, 237; 231, expression_statement; 231, 232; 232, call; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:SharedLoop; 235, identifier:stop; 236, argument_list; 237, return_statement; 237, 238; 238, integer:0; 239, expression_statement; 239, 240; 240, call; 240, 241; 240, 242; 241, identifier:setup_completion; 242, argument_list; 242, 243; 243, identifier:shell; 244, comment; 245, try_statement; 245, 246; 245, 353; 245, 354; 245, 355; 245, 363; 245, 371; 246, block; 246, 247; 247, while_statement; 247, 248; 247, 249; 248, True; 249, block; 249, 250; 249, 290; 249, 291; 249, 292; 249, 345; 250, try_statement; 250, 251; 250, 281; 251, block; 251, 252; 251, 265; 251, 266; 252, expression_statement; 252, 253; 253, assignment; 253, 254; 253, 255; 254, identifier:linebuf; 255, call; 255, 256; 255, 257; 256, identifier:input; 257, argument_list; 257, 258; 258, binary_operator:%; 258, 259; 258, 260; 259, string:"(%s) "; 260, call; 260, 261; 260, 264; 261, attribute; 261, 262; 261, 263; 262, identifier:shell; 263, identifier:context_name; 264, argument_list; 265, comment; 266, if_statement; 266, 267; 266, 279; 267, boolean_operator:and; 267, 268; 267, 274; 268, comparison_operator:>; 268, 269; 268, 273; 269, call; 269, 270; 269, 271; 270, identifier:len; 271, argument_list; 271, 272; 272, identifier:linebuf; 273, integer:0; 274, comparison_operator:==; 274, 275; 274, 278; 275, subscript; 275, 276; 275, 277; 276, identifier:linebuf; 277, integer:0; 278, string:'#'; 279, block; 279, 280; 280, continue_statement; 281, except_clause; 281, 282; 281, 283; 282, identifier:KeyboardInterrupt; 283, block; 283, 284; 283, 289; 284, expression_statement; 284, 285; 285, call; 285, 286; 285, 287; 286, identifier:print; 287, argument_list; 287, 288; 288, string:""; 289, continue_statement; 290, comment; 291, comment; 292, try_statement; 292, 293; 292, 303; 292, 319; 292, 334; 293, block; 293, 294; 294, expression_statement; 294, 295; 295, assignment; 295, 296; 295, 297; 296, identifier:finished; 297, call; 297, 298; 297, 301; 298, attribute; 298, 299; 298, 300; 299, identifier:shell; 300, identifier:invoke_string; 301, argument_list; 301, 302; 302, identifier:linebuf; 303, except_clause; 303, 304; 303, 305; 304, identifier:KeyboardInterrupt; 305, block; 305, 306; 305, 311; 306, expression_statement; 306, 307; 307, call; 307, 308; 307, 309; 308, identifier:print; 309, argument_list; 309, 310; 310, string:""; 311, if_statement; 311, 312; 311, 317; 312, call; 312, 313; 312, 316; 313, attribute; 313, 314; 313, 315; 314, identifier:timeout_stop_event; 315, identifier:is_set; 316, argument_list; 317, block; 317, 318; 318, break_statement; 319, except_clause; 319, 320; 319, 324; 320, as_pattern; 320, 321; 320, 322; 321, identifier:IOTileException; 322, as_pattern_target; 322, 323; 323, identifier:exc; 324, block; 324, 325; 325, expression_statement; 325, 326; 326, call; 326, 327; 326, 328; 327, identifier:print; 328, argument_list; 328, 329; 329, call; 329, 330; 329, 333; 330, attribute; 330, 331; 330, 332; 331, identifier:exc; 332, identifier:format; 333, argument_list; 334, except_clause; 334, 335; 334, 336; 334, 337; 334, 338; 335, identifier:Exception; 336, comment; 337, comment; 338, block; 338, 339; 339, expression_statement; 339, 340; 340, call; 340, 341; 340, 344; 341, attribute; 341, 342; 341, 343; 342, identifier:traceback; 343, identifier:print_exc; 344, argument_list; 345, if_statement; 345, 346; 345, 351; 346, call; 346, 347; 346, 350; 347, attribute; 347, 348; 347, 349; 348, identifier:shell; 349, identifier:finished; 350, argument_list; 351, block; 351, 352; 352, break_statement; 353, comment; 354, comment; 355, except_clause; 355, 356; 355, 357; 356, identifier:EOFError; 357, block; 357, 358; 358, expression_statement; 358, 359; 359, call; 359, 360; 359, 361; 360, identifier:print; 361, argument_list; 361, 362; 362, string:""; 363, except_clause; 363, 364; 363, 365; 364, identifier:KeyboardInterrupt; 365, block; 365, 366; 366, expression_statement; 366, 367; 367, call; 367, 368; 367, 369; 368, identifier:print; 369, argument_list; 369, 370; 370, string:""; 371, finally_clause; 371, 372; 371, 373; 372, comment; 373, block; 373, 374; 374, expression_statement; 374, 375; 375, call; 375, 376; 375, 379; 376, attribute; 376, 377; 376, 378; 377, identifier:SharedLoop; 378, identifier:stop; 379, argument_list; 380, comment; 381, if_statement; 381, 382; 381, 385; 382, comparison_operator:is; 382, 383; 382, 384; 383, identifier:timeout_thread; 384, None; 385, block; 385, 386; 385, 392; 386, expression_statement; 386, 387; 387, call; 387, 388; 387, 391; 388, attribute; 388, 389; 388, 390; 389, identifier:timeout_stop_event; 390, identifier:set; 391, argument_list; 392, expression_statement; 392, 393; 393, call; 393, 394; 393, 397; 394, attribute; 394, 395; 394, 396; 395, identifier:timeout_thread; 396, identifier:join; 397, argument_list | def main(argv=None):
"""Run the iotile shell tool.
You can optionally pass the arguments that should be run
in the argv parameter. If nothing is passed, the args
are pulled from sys.argv.
The return value of this function is the return value
of the shell command.
"""
if argv is None:
argv = sys.argv[1:]
args = parse_global_args(argv)
type_system.interactive = True
line = args.commands
timeout_thread = None
timeout_stop_event = threading.Event()
if args.timeout:
timeout_thread = threading.Thread(target=timeout_thread_handler, args=(args.timeout, timeout_stop_event))
timeout_thread.daemon = True
timeout_thread.start()
shell = HierarchicalShell('iotile')
shell.root_add("registry", "iotile.core.dev.annotated_registry,registry")
shell.root_add("config", "iotile.core.dev.config,ConfigManager")
shell.root_add('hw', "iotile.core.hw.hwmanager,HardwareManager")
reg = ComponentRegistry()
plugins = reg.list_plugins()
for key, val in plugins.items():
shell.root_add(key, val)
finished = False
try:
if len(line) > 0:
finished = shell.invoke(line)
except IOTileException as exc:
print(exc.format())
# if the command passed on the command line fails, then we should
# just exit rather than drop the user into a shell.
SharedLoop.stop()
return 1
except Exception: # pylint:disable=broad-except; We need to make sure we always call cmdstream.do_final_close()
# Catch all exceptions because otherwise we won't properly close cmdstreams
# since the program will be said to except 'abnormally'
traceback.print_exc()
SharedLoop.stop()
return 1
# If the user tells us to never spawn a shell, make sure we don't
# Also, if we finished our command and there is no context, quit now
if args.quit or finished:
SharedLoop.stop()
return 0
setup_completion(shell)
# We ended the initial command with a context, start a shell
try:
while True:
try:
linebuf = input("(%s) " % shell.context_name())
# Skip comments automatically
if len(linebuf) > 0 and linebuf[0] == '#':
continue
except KeyboardInterrupt:
print("")
continue
# Catch exception outside the loop so we stop invoking submethods if a parent
# fails because then the context and results would be unpredictable
try:
finished = shell.invoke_string(linebuf)
except KeyboardInterrupt:
print("")
if timeout_stop_event.is_set():
break
except IOTileException as exc:
print(exc.format())
except Exception: #pylint:disable=broad-except;
# We want to make sure the iotile tool never crashes when in interactive shell mode
traceback.print_exc()
if shell.finished():
break
# Make sure to catch ^C and ^D so that we can cleanly dispose of subprocess resources if
# there are any.
except EOFError:
print("")
except KeyboardInterrupt:
print("")
finally:
# Make sure we close any open CMDStream communication channels so that we don't lockup at exit
SharedLoop.stop()
# Make sure we cleanly join our timeout thread before exiting
if timeout_thread is not None:
timeout_stop_event.set()
timeout_thread.join() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:DialectAddToEnv; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:env; 5, identifier:dialect; 6, identifier:suffixes; 7, identifier:ppsuffixes; 8, default_parameter; 8, 9; 8, 10; 9, identifier:support_module; 10, integer:0; 11, block; 11, 12; 11, 14; 11, 20; 11, 35; 11, 53; 11, 64; 11, 76; 11, 89; 11, 125; 11, 161; 11, 183; 11, 207; 11, 208; 11, 223; 11, 238; 11, 251; 12, expression_statement; 12, 13; 13, comment; 14, expression_statement; 14, 15; 15, call; 15, 16; 15, 17; 16, identifier:ComputeFortranSuffixes; 17, argument_list; 17, 18; 17, 19; 18, identifier:suffixes; 19, identifier:ppsuffixes; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:fscan; 23, call; 23, 24; 23, 31; 24, attribute; 24, 25; 24, 30; 25, attribute; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:SCons; 28, identifier:Scanner; 29, identifier:Fortran; 30, identifier:FortranScan; 31, argument_list; 31, 32; 32, binary_operator:%; 32, 33; 32, 34; 33, string:"%sPATH"; 34, identifier:dialect; 35, for_statement; 35, 36; 35, 37; 35, 40; 36, identifier:suffix; 37, binary_operator:+; 37, 38; 37, 39; 38, identifier:suffixes; 39, identifier:ppsuffixes; 40, block; 40, 41; 41, expression_statement; 41, 42; 42, call; 42, 43; 42, 50; 43, attribute; 43, 44; 43, 49; 44, attribute; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:SCons; 47, identifier:Tool; 48, identifier:SourceFileScanner; 49, identifier:add_scanner; 50, argument_list; 50, 51; 50, 52; 51, identifier:suffix; 52, identifier:fscan; 53, expression_statement; 53, 54; 54, call; 54, 55; 54, 58; 55, attribute; 55, 56; 55, 57; 56, identifier:env; 57, identifier:AppendUnique; 58, argument_list; 58, 59; 59, keyword_argument; 59, 60; 59, 61; 60, identifier:FORTRANSUFFIXES; 61, binary_operator:+; 61, 62; 61, 63; 62, identifier:suffixes; 63, identifier:ppsuffixes; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 71; 65, 72; 66, pattern_list; 66, 67; 66, 68; 66, 69; 66, 70; 67, identifier:compaction; 68, identifier:compppaction; 69, identifier:shcompaction; 70, identifier:shcompppaction; 71, line_continuation:\; 72, call; 72, 73; 72, 74; 73, identifier:CreateDialectActions; 74, argument_list; 74, 75; 75, identifier:dialect; 76, expression_statement; 76, 77; 77, assignment; 77, 78; 77, 81; 78, pattern_list; 78, 79; 78, 80; 79, identifier:static_obj; 80, identifier:shared_obj; 81, call; 81, 82; 81, 87; 82, attribute; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:SCons; 85, identifier:Tool; 86, identifier:createObjBuilders; 87, argument_list; 87, 88; 88, identifier:env; 89, for_statement; 89, 90; 89, 91; 89, 92; 90, identifier:suffix; 91, identifier:suffixes; 92, block; 92, 93; 92, 101; 92, 109; 92, 117; 93, expression_statement; 93, 94; 94, call; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:static_obj; 97, identifier:add_action; 98, argument_list; 98, 99; 98, 100; 99, identifier:suffix; 100, identifier:compaction; 101, expression_statement; 101, 102; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:shared_obj; 105, identifier:add_action; 106, argument_list; 106, 107; 106, 108; 107, identifier:suffix; 108, identifier:shcompaction; 109, expression_statement; 109, 110; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:static_obj; 113, identifier:add_emitter; 114, argument_list; 114, 115; 114, 116; 115, identifier:suffix; 116, identifier:FortranEmitter; 117, expression_statement; 117, 118; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:shared_obj; 121, identifier:add_emitter; 122, argument_list; 122, 123; 122, 124; 123, identifier:suffix; 124, identifier:ShFortranEmitter; 125, for_statement; 125, 126; 125, 127; 125, 128; 126, identifier:suffix; 127, identifier:ppsuffixes; 128, block; 128, 129; 128, 137; 128, 145; 128, 153; 129, expression_statement; 129, 130; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:static_obj; 133, identifier:add_action; 134, argument_list; 134, 135; 134, 136; 135, identifier:suffix; 136, identifier:compppaction; 137, expression_statement; 137, 138; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:shared_obj; 141, identifier:add_action; 142, argument_list; 142, 143; 142, 144; 143, identifier:suffix; 144, identifier:shcompppaction; 145, expression_statement; 145, 146; 146, call; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:static_obj; 149, identifier:add_emitter; 150, argument_list; 150, 151; 150, 152; 151, identifier:suffix; 152, identifier:FortranEmitter; 153, expression_statement; 153, 154; 154, call; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:shared_obj; 157, identifier:add_emitter; 158, argument_list; 158, 159; 158, 160; 159, identifier:suffix; 160, identifier:ShFortranEmitter; 161, if_statement; 161, 162; 161, 167; 162, comparison_operator:not; 162, 163; 162, 166; 163, binary_operator:%; 163, 164; 163, 165; 164, string:'%sFLAGS'; 165, identifier:dialect; 166, identifier:env; 167, block; 167, 168; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 175; 170, subscript; 170, 171; 170, 172; 171, identifier:env; 172, binary_operator:%; 172, 173; 172, 174; 173, string:'%sFLAGS'; 174, identifier:dialect; 175, call; 175, 176; 175, 181; 176, attribute; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:SCons; 179, identifier:Util; 180, identifier:CLVar; 181, argument_list; 181, 182; 182, string:''; 183, if_statement; 183, 184; 183, 189; 184, comparison_operator:not; 184, 185; 184, 188; 185, binary_operator:%; 185, 186; 185, 187; 186, string:'SH%sFLAGS'; 187, identifier:dialect; 188, identifier:env; 189, block; 189, 190; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 197; 192, subscript; 192, 193; 192, 194; 193, identifier:env; 194, binary_operator:%; 194, 195; 194, 196; 195, string:'SH%sFLAGS'; 196, identifier:dialect; 197, call; 197, 198; 197, 203; 198, attribute; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:SCons; 201, identifier:Util; 202, identifier:CLVar; 203, argument_list; 203, 204; 204, binary_operator:%; 204, 205; 204, 206; 205, string:'$%sFLAGS'; 206, identifier:dialect; 207, comment; 208, if_statement; 208, 209; 208, 214; 209, comparison_operator:not; 209, 210; 209, 213; 210, binary_operator:%; 210, 211; 210, 212; 211, string:'INC%sPREFIX'; 212, identifier:dialect; 213, identifier:env; 214, block; 214, 215; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 222; 217, subscript; 217, 218; 217, 219; 218, identifier:env; 219, binary_operator:%; 219, 220; 219, 221; 220, string:'INC%sPREFIX'; 221, identifier:dialect; 222, string:'$INCPREFIX'; 223, if_statement; 223, 224; 223, 229; 224, comparison_operator:not; 224, 225; 224, 228; 225, binary_operator:%; 225, 226; 225, 227; 226, string:'INC%sSUFFIX'; 227, identifier:dialect; 228, identifier:env; 229, block; 229, 230; 230, expression_statement; 230, 231; 231, assignment; 231, 232; 231, 237; 232, subscript; 232, 233; 232, 234; 233, identifier:env; 234, binary_operator:%; 234, 235; 234, 236; 235, string:'INC%sSUFFIX'; 236, identifier:dialect; 237, string:'$INCSUFFIX'; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 245; 240, subscript; 240, 241; 240, 242; 241, identifier:env; 242, binary_operator:%; 242, 243; 242, 244; 243, string:'_%sINCFLAGS'; 244, identifier:dialect; 245, binary_operator:%; 245, 246; 245, 247; 246, string:'$( ${_concat(INC%sPREFIX, %sPATH, INC%sSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)'; 247, tuple; 247, 248; 247, 249; 247, 250; 248, identifier:dialect; 249, identifier:dialect; 250, identifier:dialect; 251, if_statement; 251, 252; 251, 255; 251, 308; 252, comparison_operator:==; 252, 253; 252, 254; 253, identifier:support_module; 254, integer:1; 255, block; 255, 256; 255, 269; 255, 282; 255, 295; 256, expression_statement; 256, 257; 257, assignment; 257, 258; 257, 263; 258, subscript; 258, 259; 258, 260; 259, identifier:env; 260, binary_operator:%; 260, 261; 260, 262; 261, string:'%sCOM'; 262, identifier:dialect; 263, binary_operator:%; 263, 264; 263, 265; 264, string:'$%s -o $TARGET -c $%sFLAGS $_%sINCFLAGS $_FORTRANMODFLAG $SOURCES'; 265, tuple; 265, 266; 265, 267; 265, 268; 266, identifier:dialect; 267, identifier:dialect; 268, identifier:dialect; 269, expression_statement; 269, 270; 270, assignment; 270, 271; 270, 276; 271, subscript; 271, 272; 271, 273; 272, identifier:env; 273, binary_operator:%; 273, 274; 273, 275; 274, string:'%sPPCOM'; 275, identifier:dialect; 276, binary_operator:%; 276, 277; 276, 278; 277, string:'$%s -o $TARGET -c $%sFLAGS $CPPFLAGS $_CPPDEFFLAGS $_%sINCFLAGS $_FORTRANMODFLAG $SOURCES'; 278, tuple; 278, 279; 278, 280; 278, 281; 279, identifier:dialect; 280, identifier:dialect; 281, identifier:dialect; 282, expression_statement; 282, 283; 283, assignment; 283, 284; 283, 289; 284, subscript; 284, 285; 284, 286; 285, identifier:env; 286, binary_operator:%; 286, 287; 286, 288; 287, string:'SH%sCOM'; 288, identifier:dialect; 289, binary_operator:%; 289, 290; 289, 291; 290, string:'$SH%s -o $TARGET -c $SH%sFLAGS $_%sINCFLAGS $_FORTRANMODFLAG $SOURCES'; 291, tuple; 291, 292; 291, 293; 291, 294; 292, identifier:dialect; 293, identifier:dialect; 294, identifier:dialect; 295, expression_statement; 295, 296; 296, assignment; 296, 297; 296, 302; 297, subscript; 297, 298; 297, 299; 298, identifier:env; 299, binary_operator:%; 299, 300; 299, 301; 300, string:'SH%sPPCOM'; 301, identifier:dialect; 302, binary_operator:%; 302, 303; 302, 304; 303, string:'$SH%s -o $TARGET -c $SH%sFLAGS $CPPFLAGS $_CPPDEFFLAGS $_%sINCFLAGS $_FORTRANMODFLAG $SOURCES'; 304, tuple; 304, 305; 304, 306; 304, 307; 305, identifier:dialect; 306, identifier:dialect; 307, identifier:dialect; 308, else_clause; 308, 309; 309, block; 309, 310; 309, 323; 309, 336; 309, 349; 310, expression_statement; 310, 311; 311, assignment; 311, 312; 311, 317; 312, subscript; 312, 313; 312, 314; 313, identifier:env; 314, binary_operator:%; 314, 315; 314, 316; 315, string:'%sCOM'; 316, identifier:dialect; 317, binary_operator:%; 317, 318; 317, 319; 318, string:'$%s -o $TARGET -c $%sFLAGS $_%sINCFLAGS $SOURCES'; 319, tuple; 319, 320; 319, 321; 319, 322; 320, identifier:dialect; 321, identifier:dialect; 322, identifier:dialect; 323, expression_statement; 323, 324; 324, assignment; 324, 325; 324, 330; 325, subscript; 325, 326; 325, 327; 326, identifier:env; 327, binary_operator:%; 327, 328; 327, 329; 328, string:'%sPPCOM'; 329, identifier:dialect; 330, binary_operator:%; 330, 331; 330, 332; 331, string:'$%s -o $TARGET -c $%sFLAGS $CPPFLAGS $_CPPDEFFLAGS $_%sINCFLAGS $SOURCES'; 332, tuple; 332, 333; 332, 334; 332, 335; 333, identifier:dialect; 334, identifier:dialect; 335, identifier:dialect; 336, expression_statement; 336, 337; 337, assignment; 337, 338; 337, 343; 338, subscript; 338, 339; 338, 340; 339, identifier:env; 340, binary_operator:%; 340, 341; 340, 342; 341, string:'SH%sCOM'; 342, identifier:dialect; 343, binary_operator:%; 343, 344; 343, 345; 344, string:'$SH%s -o $TARGET -c $SH%sFLAGS $_%sINCFLAGS $SOURCES'; 345, tuple; 345, 346; 345, 347; 345, 348; 346, identifier:dialect; 347, identifier:dialect; 348, identifier:dialect; 349, expression_statement; 349, 350; 350, assignment; 350, 351; 350, 356; 351, subscript; 351, 352; 351, 353; 352, identifier:env; 353, binary_operator:%; 353, 354; 353, 355; 354, string:'SH%sPPCOM'; 355, identifier:dialect; 356, binary_operator:%; 356, 357; 356, 358; 357, string:'$SH%s -o $TARGET -c $SH%sFLAGS $CPPFLAGS $_CPPDEFFLAGS $_%sINCFLAGS $SOURCES'; 358, tuple; 358, 359; 358, 360; 358, 361; 359, identifier:dialect; 360, identifier:dialect; 361, identifier:dialect | def DialectAddToEnv(env, dialect, suffixes, ppsuffixes, support_module = 0):
"""Add dialect specific construction variables."""
ComputeFortranSuffixes(suffixes, ppsuffixes)
fscan = SCons.Scanner.Fortran.FortranScan("%sPATH" % dialect)
for suffix in suffixes + ppsuffixes:
SCons.Tool.SourceFileScanner.add_scanner(suffix, fscan)
env.AppendUnique(FORTRANSUFFIXES = suffixes + ppsuffixes)
compaction, compppaction, shcompaction, shcompppaction = \
CreateDialectActions(dialect)
static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
for suffix in suffixes:
static_obj.add_action(suffix, compaction)
shared_obj.add_action(suffix, shcompaction)
static_obj.add_emitter(suffix, FortranEmitter)
shared_obj.add_emitter(suffix, ShFortranEmitter)
for suffix in ppsuffixes:
static_obj.add_action(suffix, compppaction)
shared_obj.add_action(suffix, shcompppaction)
static_obj.add_emitter(suffix, FortranEmitter)
shared_obj.add_emitter(suffix, ShFortranEmitter)
if '%sFLAGS' % dialect not in env:
env['%sFLAGS' % dialect] = SCons.Util.CLVar('')
if 'SH%sFLAGS' % dialect not in env:
env['SH%sFLAGS' % dialect] = SCons.Util.CLVar('$%sFLAGS' % dialect)
# If a tool does not define fortran prefix/suffix for include path, use C ones
if 'INC%sPREFIX' % dialect not in env:
env['INC%sPREFIX' % dialect] = '$INCPREFIX'
if 'INC%sSUFFIX' % dialect not in env:
env['INC%sSUFFIX' % dialect] = '$INCSUFFIX'
env['_%sINCFLAGS' % dialect] = '$( ${_concat(INC%sPREFIX, %sPATH, INC%sSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)' % (dialect, dialect, dialect)
if support_module == 1:
env['%sCOM' % dialect] = '$%s -o $TARGET -c $%sFLAGS $_%sINCFLAGS $_FORTRANMODFLAG $SOURCES' % (dialect, dialect, dialect)
env['%sPPCOM' % dialect] = '$%s -o $TARGET -c $%sFLAGS $CPPFLAGS $_CPPDEFFLAGS $_%sINCFLAGS $_FORTRANMODFLAG $SOURCES' % (dialect, dialect, dialect)
env['SH%sCOM' % dialect] = '$SH%s -o $TARGET -c $SH%sFLAGS $_%sINCFLAGS $_FORTRANMODFLAG $SOURCES' % (dialect, dialect, dialect)
env['SH%sPPCOM' % dialect] = '$SH%s -o $TARGET -c $SH%sFLAGS $CPPFLAGS $_CPPDEFFLAGS $_%sINCFLAGS $_FORTRANMODFLAG $SOURCES' % (dialect, dialect, dialect)
else:
env['%sCOM' % dialect] = '$%s -o $TARGET -c $%sFLAGS $_%sINCFLAGS $SOURCES' % (dialect, dialect, dialect)
env['%sPPCOM' % dialect] = '$%s -o $TARGET -c $%sFLAGS $CPPFLAGS $_CPPDEFFLAGS $_%sINCFLAGS $SOURCES' % (dialect, dialect, dialect)
env['SH%sCOM' % dialect] = '$SH%s -o $TARGET -c $SH%sFLAGS $_%sINCFLAGS $SOURCES' % (dialect, dialect, dialect)
env['SH%sPPCOM' % dialect] = '$SH%s -o $TARGET -c $SH%sFLAGS $CPPFLAGS $_CPPDEFFLAGS $_%sINCFLAGS $SOURCES' % (dialect, dialect, dialect) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:MergeFlags; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:self; 5, identifier:args; 6, default_parameter; 6, 7; 6, 8; 7, identifier:unique; 8, integer:1; 9, default_parameter; 9, 10; 9, 11; 10, identifier:dict; 11, None; 12, block; 12, 13; 12, 15; 12, 24; 12, 44; 12, 58; 12, 213; 13, expression_statement; 13, 14; 14, comment; 15, if_statement; 15, 16; 15, 19; 16, comparison_operator:is; 16, 17; 16, 18; 17, identifier:dict; 18, None; 19, block; 19, 20; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:dict; 23, identifier:self; 24, if_statement; 24, 25; 24, 34; 25, not_operator; 25, 26; 26, call; 26, 27; 26, 32; 27, attribute; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:SCons; 30, identifier:Util; 31, identifier:is_Dict; 32, argument_list; 32, 33; 33, identifier:args; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:args; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:ParseFlags; 42, argument_list; 42, 43; 43, identifier:args; 44, if_statement; 44, 45; 44, 47; 45, not_operator; 45, 46; 46, identifier:unique; 47, block; 47, 48; 47, 56; 48, expression_statement; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:Append; 53, argument_list; 53, 54; 54, dictionary_splat; 54, 55; 55, identifier:args; 56, return_statement; 56, 57; 57, identifier:self; 58, for_statement; 58, 59; 58, 62; 58, 67; 59, pattern_list; 59, 60; 59, 61; 60, identifier:key; 61, identifier:value; 62, call; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:args; 65, identifier:items; 66, argument_list; 67, block; 67, 68; 67, 73; 67, 150; 67, 154; 67, 207; 68, if_statement; 68, 69; 68, 71; 69, not_operator; 69, 70; 70, identifier:value; 71, block; 71, 72; 72, continue_statement; 73, try_statement; 73, 74; 73, 81; 73, 88; 74, block; 74, 75; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:orig; 78, subscript; 78, 79; 78, 80; 79, identifier:self; 80, identifier:key; 81, except_clause; 81, 82; 81, 83; 82, identifier:KeyError; 83, block; 83, 84; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:orig; 87, identifier:value; 88, else_clause; 88, 89; 89, block; 89, 90; 90, if_statement; 90, 91; 90, 93; 90, 98; 91, not_operator; 91, 92; 92, identifier:orig; 93, block; 93, 94; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 97; 96, identifier:orig; 97, identifier:value; 98, elif_clause; 98, 99; 98, 100; 98, 101; 98, 102; 98, 103; 98, 104; 98, 105; 98, 106; 99, identifier:value; 100, comment; 101, comment; 102, comment; 103, comment; 104, comment; 105, comment; 106, block; 106, 107; 107, try_statement; 107, 108; 107, 115; 108, block; 108, 109; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:orig; 112, binary_operator:+; 112, 113; 112, 114; 113, identifier:orig; 114, identifier:value; 115, except_clause; 115, 116; 115, 119; 116, tuple; 116, 117; 116, 118; 117, identifier:KeyError; 118, identifier:TypeError; 119, block; 119, 120; 120, try_statement; 120, 121; 120, 128; 120, 143; 121, block; 121, 122; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 125; 124, identifier:add_to_orig; 125, attribute; 125, 126; 125, 127; 126, identifier:orig; 127, identifier:append; 128, except_clause; 128, 129; 128, 130; 129, identifier:AttributeError; 130, block; 130, 131; 130, 139; 131, expression_statement; 131, 132; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:value; 135, identifier:insert; 136, argument_list; 136, 137; 136, 138; 137, integer:0; 138, identifier:orig; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:orig; 142, identifier:value; 143, else_clause; 143, 144; 144, block; 144, 145; 145, expression_statement; 145, 146; 146, call; 146, 147; 146, 148; 147, identifier:add_to_orig; 148, argument_list; 148, 149; 149, identifier:value; 150, expression_statement; 150, 151; 151, assignment; 151, 152; 151, 153; 152, identifier:t; 153, list:[]; 154, if_statement; 154, 155; 154, 163; 154, 164; 154, 181; 155, comparison_operator:==; 155, 156; 155, 162; 156, subscript; 156, 157; 156, 158; 157, identifier:key; 158, slice; 158, 159; 158, 161; 159, unary_operator:-; 159, 160; 160, integer:4; 161, colon; 162, string:'PATH'; 163, comment; 164, block; 164, 165; 165, for_statement; 165, 166; 165, 167; 165, 168; 166, identifier:v; 167, identifier:orig; 168, block; 168, 169; 169, if_statement; 169, 170; 169, 173; 170, comparison_operator:not; 170, 171; 170, 172; 171, identifier:v; 172, identifier:t; 173, block; 173, 174; 174, expression_statement; 174, 175; 175, call; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:t; 178, identifier:append; 179, argument_list; 179, 180; 180, identifier:v; 181, else_clause; 181, 182; 181, 183; 182, comment; 183, block; 183, 184; 183, 190; 184, expression_statement; 184, 185; 185, call; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:orig; 188, identifier:reverse; 189, argument_list; 190, for_statement; 190, 191; 190, 192; 190, 193; 191, identifier:v; 192, identifier:orig; 193, block; 193, 194; 194, if_statement; 194, 195; 194, 198; 195, comparison_operator:not; 195, 196; 195, 197; 196, identifier:v; 197, identifier:t; 198, block; 198, 199; 199, expression_statement; 199, 200; 200, call; 200, 201; 200, 204; 201, attribute; 201, 202; 201, 203; 202, identifier:t; 203, identifier:insert; 204, argument_list; 204, 205; 204, 206; 205, integer:0; 206, identifier:v; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 212; 209, subscript; 209, 210; 209, 211; 210, identifier:self; 211, identifier:key; 212, identifier:t; 213, return_statement; 213, 214; 214, identifier:self | def MergeFlags(self, args, unique=1, dict=None):
"""
Merge the dict in args into the construction variables of this
env, or the passed-in dict. If args is not a dict, it is
converted into a dict using ParseFlags. If unique is not set,
the flags are appended rather than merged.
"""
if dict is None:
dict = self
if not SCons.Util.is_Dict(args):
args = self.ParseFlags(args)
if not unique:
self.Append(**args)
return self
for key, value in args.items():
if not value:
continue
try:
orig = self[key]
except KeyError:
orig = value
else:
if not orig:
orig = value
elif value:
# Add orig and value. The logic here was lifted from
# part of env.Append() (see there for a lot of comments
# about the order in which things are tried) and is
# used mainly to handle coercion of strings to CLVar to
# "do the right thing" given (e.g.) an original CCFLAGS
# string variable like '-pipe -Wall'.
try:
orig = orig + value
except (KeyError, TypeError):
try:
add_to_orig = orig.append
except AttributeError:
value.insert(0, orig)
orig = value
else:
add_to_orig(value)
t = []
if key[-4:] == 'PATH':
### keep left-most occurence
for v in orig:
if v not in t:
t.append(v)
else:
### keep right-most occurence
orig.reverse()
for v in orig:
if v not in t:
t.insert(0, v)
self[key] = t
return self |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:Append; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, dictionary_splat_pattern; 5, 6; 6, identifier:kw; 7, block; 7, 8; 7, 10; 7, 17; 7, 330; 8, expression_statement; 8, 9; 9, comment; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:kw; 13, call; 13, 14; 13, 15; 14, identifier:copy_non_reserved_keywords; 15, argument_list; 15, 16; 16, identifier:kw; 17, for_statement; 17, 18; 17, 21; 17, 26; 17, 27; 17, 28; 17, 29; 17, 30; 18, pattern_list; 18, 19; 18, 20; 19, identifier:key; 20, identifier:val; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:kw; 24, identifier:items; 25, argument_list; 26, comment; 27, comment; 28, comment; 29, comment; 30, block; 30, 31; 31, try_statement; 31, 32; 31, 72; 31, 110; 32, block; 32, 33; 32, 64; 33, if_statement; 33, 34; 33, 50; 34, boolean_operator:and; 34, 35; 34, 38; 35, comparison_operator:==; 35, 36; 35, 37; 36, identifier:key; 37, string:'CPPDEFINES'; 38, call; 38, 39; 38, 44; 39, attribute; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:SCons; 42, identifier:Util; 43, identifier:is_String; 44, argument_list; 44, 45; 45, subscript; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:_dict; 49, identifier:key; 50, block; 50, 51; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 58; 53, subscript; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:_dict; 57, identifier:key; 58, list:[self._dict[key]]; 58, 59; 59, subscript; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:_dict; 63, identifier:key; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:orig; 67, subscript; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:self; 70, identifier:_dict; 71, identifier:key; 72, except_clause; 72, 73; 72, 74; 72, 75; 72, 76; 73, identifier:KeyError; 74, comment; 75, comment; 76, block; 76, 77; 77, if_statement; 77, 78; 77, 90; 77, 100; 78, boolean_operator:and; 78, 79; 78, 82; 79, comparison_operator:==; 79, 80; 79, 81; 80, identifier:key; 81, string:'CPPDEFINES'; 82, call; 82, 83; 82, 88; 83, attribute; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:SCons; 86, identifier:Util; 87, identifier:is_String; 88, argument_list; 88, 89; 89, identifier:val; 90, block; 90, 91; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 98; 93, subscript; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:self; 96, identifier:_dict; 97, identifier:key; 98, list:[val]; 98, 99; 99, identifier:val; 100, else_clause; 100, 101; 101, block; 101, 102; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 109; 104, subscript; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:self; 107, identifier:_dict; 108, identifier:key; 109, identifier:val; 110, else_clause; 110, 111; 111, block; 111, 112; 112, try_statement; 112, 113; 112, 114; 112, 115; 112, 116; 112, 117; 112, 118; 112, 125; 112, 196; 113, comment; 114, comment; 115, comment; 116, comment; 117, comment; 118, block; 118, 119; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:update_dict; 122, attribute; 122, 123; 122, 124; 123, identifier:orig; 124, identifier:update; 125, except_clause; 125, 126; 125, 127; 126, identifier:AttributeError; 127, block; 127, 128; 128, try_statement; 128, 129; 128, 130; 128, 131; 128, 132; 128, 143; 129, comment; 130, comment; 131, comment; 132, block; 132, 133; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 140; 135, subscript; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:self; 138, identifier:_dict; 139, identifier:key; 140, binary_operator:+; 140, 141; 140, 142; 141, identifier:orig; 142, identifier:val; 143, except_clause; 143, 144; 143, 147; 144, tuple; 144, 145; 144, 146; 145, identifier:KeyError; 146, identifier:TypeError; 147, block; 147, 148; 148, try_statement; 148, 149; 148, 150; 148, 157; 148, 184; 149, comment; 150, block; 150, 151; 151, expression_statement; 151, 152; 152, assignment; 152, 153; 152, 154; 153, identifier:add_to_orig; 154, attribute; 154, 155; 154, 156; 155, identifier:orig; 156, identifier:append; 157, except_clause; 157, 158; 157, 159; 157, 160; 157, 161; 157, 162; 157, 163; 157, 164; 158, identifier:AttributeError; 159, comment; 160, comment; 161, comment; 162, comment; 163, comment; 164, block; 164, 165; 164, 176; 165, if_statement; 165, 166; 165, 167; 166, identifier:orig; 167, block; 167, 168; 168, expression_statement; 168, 169; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:val; 172, identifier:insert; 173, argument_list; 173, 174; 173, 175; 174, integer:0; 175, identifier:orig; 176, expression_statement; 176, 177; 177, assignment; 177, 178; 177, 183; 178, subscript; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:self; 181, identifier:_dict; 182, identifier:key; 183, identifier:val; 184, else_clause; 184, 185; 184, 186; 184, 187; 185, comment; 186, comment; 187, block; 187, 188; 188, if_statement; 188, 189; 188, 190; 189, identifier:val; 190, block; 190, 191; 191, expression_statement; 191, 192; 192, call; 192, 193; 192, 194; 193, identifier:add_to_orig; 194, argument_list; 194, 195; 195, identifier:val; 196, else_clause; 196, 197; 196, 198; 196, 199; 197, comment; 198, comment; 199, block; 199, 200; 200, if_statement; 200, 201; 200, 209; 200, 281; 201, call; 201, 202; 201, 207; 202, attribute; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, identifier:SCons; 205, identifier:Util; 206, identifier:is_List; 207, argument_list; 207, 208; 208, identifier:val; 209, block; 209, 210; 210, if_statement; 210, 211; 210, 214; 210, 269; 211, comparison_operator:==; 211, 212; 211, 213; 212, identifier:key; 213, string:'CPPDEFINES'; 214, block; 214, 215; 214, 219; 214, 253; 214, 257; 214, 261; 215, expression_statement; 215, 216; 216, assignment; 216, 217; 216, 218; 217, identifier:tmp; 218, list:[]; 219, for_statement; 219, 220; 219, 223; 219, 228; 220, tuple_pattern; 220, 221; 220, 222; 221, identifier:k; 222, identifier:v; 223, call; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:orig; 226, identifier:items; 227, argument_list; 228, block; 228, 229; 229, if_statement; 229, 230; 229, 233; 229, 243; 230, comparison_operator:is; 230, 231; 230, 232; 231, identifier:v; 232, None; 233, block; 233, 234; 234, expression_statement; 234, 235; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:tmp; 238, identifier:append; 239, argument_list; 239, 240; 240, tuple; 240, 241; 240, 242; 241, identifier:k; 242, identifier:v; 243, else_clause; 243, 244; 244, block; 244, 245; 245, expression_statement; 245, 246; 246, call; 246, 247; 246, 250; 247, attribute; 247, 248; 247, 249; 248, identifier:tmp; 249, identifier:append; 250, argument_list; 250, 251; 251, tuple; 251, 252; 252, identifier:k; 253, expression_statement; 253, 254; 254, assignment; 254, 255; 254, 256; 255, identifier:orig; 256, identifier:tmp; 257, expression_statement; 257, 258; 258, augmented_assignment:+=; 258, 259; 258, 260; 259, identifier:orig; 260, identifier:val; 261, expression_statement; 261, 262; 262, assignment; 262, 263; 262, 268; 263, subscript; 263, 264; 263, 267; 264, attribute; 264, 265; 264, 266; 265, identifier:self; 266, identifier:_dict; 267, identifier:key; 268, identifier:orig; 269, else_clause; 269, 270; 270, block; 270, 271; 271, for_statement; 271, 272; 271, 273; 271, 274; 272, identifier:v; 273, identifier:val; 274, block; 274, 275; 275, expression_statement; 275, 276; 276, assignment; 276, 277; 276, 280; 277, subscript; 277, 278; 277, 279; 278, identifier:orig; 279, identifier:v; 280, None; 281, else_clause; 281, 282; 282, block; 282, 283; 283, try_statement; 283, 284; 283, 290; 284, block; 284, 285; 285, expression_statement; 285, 286; 286, call; 286, 287; 286, 288; 287, identifier:update_dict; 288, argument_list; 288, 289; 289, identifier:val; 290, except_clause; 290, 291; 290, 295; 291, tuple; 291, 292; 291, 293; 291, 294; 292, identifier:AttributeError; 293, identifier:TypeError; 294, identifier:ValueError; 295, block; 295, 296; 296, if_statement; 296, 297; 296, 305; 296, 322; 297, call; 297, 298; 297, 303; 298, attribute; 298, 299; 298, 302; 299, attribute; 299, 300; 299, 301; 300, identifier:SCons; 301, identifier:Util; 302, identifier:is_Dict; 303, argument_list; 303, 304; 304, identifier:val; 305, block; 305, 306; 306, for_statement; 306, 307; 306, 310; 306, 315; 307, pattern_list; 307, 308; 307, 309; 308, identifier:k; 309, identifier:v; 310, call; 310, 311; 310, 314; 311, attribute; 311, 312; 311, 313; 312, identifier:val; 313, identifier:items; 314, argument_list; 315, block; 315, 316; 316, expression_statement; 316, 317; 317, assignment; 317, 318; 317, 321; 318, subscript; 318, 319; 318, 320; 319, identifier:orig; 320, identifier:k; 321, identifier:v; 322, else_clause; 322, 323; 323, block; 323, 324; 324, expression_statement; 324, 325; 325, assignment; 325, 326; 325, 329; 326, subscript; 326, 327; 326, 328; 327, identifier:orig; 328, identifier:val; 329, None; 330, expression_statement; 330, 331; 331, call; 331, 332; 331, 335; 332, attribute; 332, 333; 332, 334; 333, identifier:self; 334, identifier:scanner_map_delete; 335, argument_list; 335, 336; 336, identifier:kw | def Append(self, **kw):
"""Append values to existing construction variables
in an Environment.
"""
kw = copy_non_reserved_keywords(kw)
for key, val in kw.items():
# It would be easier on the eyes to write this using
# "continue" statements whenever we finish processing an item,
# but Python 1.5.2 apparently doesn't let you use "continue"
# within try:-except: blocks, so we have to nest our code.
try:
if key == 'CPPDEFINES' and SCons.Util.is_String(self._dict[key]):
self._dict[key] = [self._dict[key]]
orig = self._dict[key]
except KeyError:
# No existing variable in the environment, so just set
# it to the new value.
if key == 'CPPDEFINES' and SCons.Util.is_String(val):
self._dict[key] = [val]
else:
self._dict[key] = val
else:
try:
# Check if the original looks like a dictionary.
# If it is, we can't just try adding the value because
# dictionaries don't have __add__() methods, and
# things like UserList will incorrectly coerce the
# original dict to a list (which we don't want).
update_dict = orig.update
except AttributeError:
try:
# Most straightforward: just try to add them
# together. This will work in most cases, when the
# original and new values are of compatible types.
self._dict[key] = orig + val
except (KeyError, TypeError):
try:
# Check if the original is a list.
add_to_orig = orig.append
except AttributeError:
# The original isn't a list, but the new
# value is (by process of elimination),
# so insert the original in the new value
# (if there's one to insert) and replace
# the variable with it.
if orig:
val.insert(0, orig)
self._dict[key] = val
else:
# The original is a list, so append the new
# value to it (if there's a value to append).
if val:
add_to_orig(val)
else:
# The original looks like a dictionary, so update it
# based on what we think the value looks like.
if SCons.Util.is_List(val):
if key == 'CPPDEFINES':
tmp = []
for (k, v) in orig.items():
if v is not None:
tmp.append((k, v))
else:
tmp.append((k,))
orig = tmp
orig += val
self._dict[key] = orig
else:
for v in val:
orig[v] = None
else:
try:
update_dict(val)
except (AttributeError, TypeError, ValueError):
if SCons.Util.is_Dict(val):
for k, v in val.items():
orig[k] = v
else:
orig[val] = None
self.scanner_map_delete(kw) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:ParseDepends; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:self; 5, identifier:filename; 6, default_parameter; 6, 7; 6, 8; 7, identifier:must_exist; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:only_one; 11, integer:0; 12, block; 12, 13; 12, 15; 12, 24; 12, 42; 12, 57; 12, 71; 12, 75; 12, 120; 12, 161; 13, expression_statement; 13, 14; 14, comment; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:filename; 18, call; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:subst; 22, argument_list; 22, 23; 23, identifier:filename; 24, try_statement; 24, 25; 24, 34; 25, block; 25, 26; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:fp; 29, call; 29, 30; 29, 31; 30, identifier:open; 31, argument_list; 31, 32; 31, 33; 32, identifier:filename; 33, string:'r'; 34, except_clause; 34, 35; 34, 36; 35, identifier:IOError; 36, block; 36, 37; 36, 41; 37, if_statement; 37, 38; 37, 39; 38, identifier:must_exist; 39, block; 39, 40; 40, raise_statement; 41, return_statement; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:lines; 45, call; 45, 46; 45, 56; 46, attribute; 46, 47; 46, 55; 47, call; 47, 48; 47, 53; 48, attribute; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:SCons; 51, identifier:Util; 52, identifier:LogicalLines; 53, argument_list; 53, 54; 54, identifier:fp; 55, identifier:readlines; 56, argument_list; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:lines; 60, list_comprehension; 60, 61; 60, 62; 60, 65; 61, identifier:l; 62, for_in_clause; 62, 63; 62, 64; 63, identifier:l; 64, identifier:lines; 65, if_clause; 65, 66; 66, comparison_operator:!=; 66, 67; 66, 70; 67, subscript; 67, 68; 67, 69; 68, identifier:l; 69, integer:0; 70, string:'#'; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:tdlist; 74, list:[]; 75, for_statement; 75, 76; 75, 77; 75, 78; 76, identifier:line; 77, identifier:lines; 78, block; 78, 79; 79, try_statement; 79, 80; 79, 93; 79, 101; 80, block; 80, 81; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 86; 83, pattern_list; 83, 84; 83, 85; 84, identifier:target; 85, identifier:depends; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:line; 89, identifier:split; 90, argument_list; 90, 91; 90, 92; 91, string:':'; 92, integer:1; 93, except_clause; 93, 94; 93, 97; 93, 98; 93, 99; 94, tuple; 94, 95; 94, 96; 95, identifier:AttributeError; 96, identifier:ValueError; 97, comment; 98, comment; 99, block; 99, 100; 100, pass_statement; 101, else_clause; 101, 102; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:tdlist; 107, identifier:append; 108, argument_list; 108, 109; 109, tuple; 109, 110; 109, 115; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:target; 113, identifier:split; 114, argument_list; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:depends; 118, identifier:split; 119, argument_list; 120, if_statement; 120, 121; 120, 122; 121, identifier:only_one; 122, block; 122, 123; 122, 127; 122, 140; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 126; 125, identifier:targets; 126, list:[]; 127, for_statement; 127, 128; 127, 129; 127, 130; 128, identifier:td; 129, identifier:tdlist; 130, block; 130, 131; 131, expression_statement; 131, 132; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:targets; 135, identifier:extend; 136, argument_list; 136, 137; 137, subscript; 137, 138; 137, 139; 138, identifier:td; 139, integer:0; 140, if_statement; 140, 141; 140, 147; 141, comparison_operator:>; 141, 142; 141, 146; 142, call; 142, 143; 142, 144; 143, identifier:len; 144, argument_list; 144, 145; 145, identifier:targets; 146, integer:1; 147, block; 147, 148; 148, raise_statement; 148, 149; 149, call; 149, 150; 149, 155; 150, attribute; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:SCons; 153, identifier:Errors; 154, identifier:UserError; 155, argument_list; 155, 156; 156, binary_operator:%; 156, 157; 156, 158; 157, string:"More than one dependency target found in `%s': %s"; 158, tuple; 158, 159; 158, 160; 159, identifier:filename; 160, identifier:targets; 161, for_statement; 161, 162; 161, 165; 161, 166; 162, pattern_list; 162, 163; 162, 164; 163, identifier:target; 164, identifier:depends; 165, identifier:tdlist; 166, block; 166, 167; 167, expression_statement; 167, 168; 168, call; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:self; 171, identifier:Depends; 172, argument_list; 172, 173; 172, 174; 173, identifier:target; 174, identifier:depends | def ParseDepends(self, filename, must_exist=None, only_one=0):
"""
Parse a mkdep-style file for explicit dependencies. This is
completely abusable, and should be unnecessary in the "normal"
case of proper SCons configuration, but it may help make
the transition from a Make hierarchy easier for some people
to swallow. It can also be genuinely useful when using a tool
that can write a .d file, but for which writing a scanner would
be too complicated.
"""
filename = self.subst(filename)
try:
fp = open(filename, 'r')
except IOError:
if must_exist:
raise
return
lines = SCons.Util.LogicalLines(fp).readlines()
lines = [l for l in lines if l[0] != '#']
tdlist = []
for line in lines:
try:
target, depends = line.split(':', 1)
except (AttributeError, ValueError):
# Throws AttributeError if line isn't a string. Can throw
# ValueError if line doesn't split into two or more elements.
pass
else:
tdlist.append((target.split(), depends.split()))
if only_one:
targets = []
for td in tdlist:
targets.extend(td[0])
if len(targets) > 1:
raise SCons.Errors.UserError(
"More than one dependency target found in `%s': %s"
% (filename, targets))
for target, depends in tdlist:
self.Depends(target, depends) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:Prepend; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, dictionary_splat_pattern; 5, 6; 6, identifier:kw; 7, block; 7, 8; 7, 10; 7, 17; 7, 213; 8, expression_statement; 8, 9; 9, comment; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:kw; 13, call; 13, 14; 13, 15; 14, identifier:copy_non_reserved_keywords; 15, argument_list; 15, 16; 16, identifier:kw; 17, for_statement; 17, 18; 17, 21; 17, 26; 17, 27; 17, 28; 17, 29; 17, 30; 18, pattern_list; 18, 19; 18, 20; 19, identifier:key; 20, identifier:val; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:kw; 24, identifier:items; 25, argument_list; 26, comment; 27, comment; 28, comment; 29, comment; 30, block; 30, 31; 31, try_statement; 31, 32; 31, 41; 31, 54; 32, block; 32, 33; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:orig; 36, subscript; 36, 37; 36, 40; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:_dict; 40, identifier:key; 41, except_clause; 41, 42; 41, 43; 41, 44; 41, 45; 42, identifier:KeyError; 43, comment; 44, comment; 45, block; 45, 46; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 53; 48, subscript; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:_dict; 52, identifier:key; 53, identifier:val; 54, else_clause; 54, 55; 55, block; 55, 56; 56, try_statement; 56, 57; 56, 58; 56, 59; 56, 60; 56, 61; 56, 62; 56, 69; 56, 140; 57, comment; 58, comment; 59, comment; 60, comment; 61, comment; 62, block; 62, 63; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:update_dict; 66, attribute; 66, 67; 66, 68; 67, identifier:orig; 68, identifier:update; 69, except_clause; 69, 70; 69, 71; 70, identifier:AttributeError; 71, block; 71, 72; 72, try_statement; 72, 73; 72, 74; 72, 75; 72, 76; 72, 87; 73, comment; 74, comment; 75, comment; 76, block; 76, 77; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 84; 79, subscript; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:_dict; 83, identifier:key; 84, binary_operator:+; 84, 85; 84, 86; 85, identifier:val; 86, identifier:orig; 87, except_clause; 87, 88; 87, 91; 88, tuple; 88, 89; 88, 90; 89, identifier:KeyError; 90, identifier:TypeError; 91, block; 91, 92; 92, try_statement; 92, 93; 92, 94; 92, 101; 92, 119; 93, comment; 94, block; 94, 95; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:add_to_val; 98, attribute; 98, 99; 98, 100; 99, identifier:val; 100, identifier:append; 101, except_clause; 101, 102; 101, 103; 101, 104; 101, 105; 101, 106; 101, 107; 102, identifier:AttributeError; 103, comment; 104, comment; 105, comment; 106, comment; 107, block; 107, 108; 108, if_statement; 108, 109; 108, 110; 109, identifier:val; 110, block; 110, 111; 111, expression_statement; 111, 112; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:orig; 115, identifier:insert; 116, argument_list; 116, 117; 116, 118; 117, integer:0; 118, identifier:val; 119, else_clause; 119, 120; 119, 121; 119, 122; 119, 123; 120, comment; 121, comment; 122, comment; 123, block; 123, 124; 123, 132; 124, if_statement; 124, 125; 124, 126; 125, identifier:orig; 126, block; 126, 127; 127, expression_statement; 127, 128; 128, call; 128, 129; 128, 130; 129, identifier:add_to_val; 130, argument_list; 130, 131; 131, identifier:orig; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 139; 134, subscript; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:self; 137, identifier:_dict; 138, identifier:key; 139, identifier:val; 140, else_clause; 140, 141; 140, 142; 140, 143; 141, comment; 142, comment; 143, block; 143, 144; 144, if_statement; 144, 145; 144, 153; 144, 164; 145, call; 145, 146; 145, 151; 146, attribute; 146, 147; 146, 150; 147, attribute; 147, 148; 147, 149; 148, identifier:SCons; 149, identifier:Util; 150, identifier:is_List; 151, argument_list; 151, 152; 152, identifier:val; 153, block; 153, 154; 154, for_statement; 154, 155; 154, 156; 154, 157; 155, identifier:v; 156, identifier:val; 157, block; 157, 158; 158, expression_statement; 158, 159; 159, assignment; 159, 160; 159, 163; 160, subscript; 160, 161; 160, 162; 161, identifier:orig; 162, identifier:v; 163, None; 164, else_clause; 164, 165; 165, block; 165, 166; 166, try_statement; 166, 167; 166, 173; 167, block; 167, 168; 168, expression_statement; 168, 169; 169, call; 169, 170; 169, 171; 170, identifier:update_dict; 171, argument_list; 171, 172; 172, identifier:val; 173, except_clause; 173, 174; 173, 178; 174, tuple; 174, 175; 174, 176; 174, 177; 175, identifier:AttributeError; 176, identifier:TypeError; 177, identifier:ValueError; 178, block; 178, 179; 179, if_statement; 179, 180; 179, 188; 179, 205; 180, call; 180, 181; 180, 186; 181, attribute; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:SCons; 184, identifier:Util; 185, identifier:is_Dict; 186, argument_list; 186, 187; 187, identifier:val; 188, block; 188, 189; 189, for_statement; 189, 190; 189, 193; 189, 198; 190, pattern_list; 190, 191; 190, 192; 191, identifier:k; 192, identifier:v; 193, call; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:val; 196, identifier:items; 197, argument_list; 198, block; 198, 199; 199, expression_statement; 199, 200; 200, assignment; 200, 201; 200, 204; 201, subscript; 201, 202; 201, 203; 202, identifier:orig; 203, identifier:k; 204, identifier:v; 205, else_clause; 205, 206; 206, block; 206, 207; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 212; 209, subscript; 209, 210; 209, 211; 210, identifier:orig; 211, identifier:val; 212, None; 213, expression_statement; 213, 214; 214, call; 214, 215; 214, 218; 215, attribute; 215, 216; 215, 217; 216, identifier:self; 217, identifier:scanner_map_delete; 218, argument_list; 218, 219; 219, identifier:kw | def Prepend(self, **kw):
"""Prepend values to existing construction variables
in an Environment.
"""
kw = copy_non_reserved_keywords(kw)
for key, val in kw.items():
# It would be easier on the eyes to write this using
# "continue" statements whenever we finish processing an item,
# but Python 1.5.2 apparently doesn't let you use "continue"
# within try:-except: blocks, so we have to nest our code.
try:
orig = self._dict[key]
except KeyError:
# No existing variable in the environment, so just set
# it to the new value.
self._dict[key] = val
else:
try:
# Check if the original looks like a dictionary.
# If it is, we can't just try adding the value because
# dictionaries don't have __add__() methods, and
# things like UserList will incorrectly coerce the
# original dict to a list (which we don't want).
update_dict = orig.update
except AttributeError:
try:
# Most straightforward: just try to add them
# together. This will work in most cases, when the
# original and new values are of compatible types.
self._dict[key] = val + orig
except (KeyError, TypeError):
try:
# Check if the added value is a list.
add_to_val = val.append
except AttributeError:
# The added value isn't a list, but the
# original is (by process of elimination),
# so insert the the new value in the original
# (if there's one to insert).
if val:
orig.insert(0, val)
else:
# The added value is a list, so append
# the original to it (if there's a value
# to append).
if orig:
add_to_val(orig)
self._dict[key] = val
else:
# The original looks like a dictionary, so update it
# based on what we think the value looks like.
if SCons.Util.is_List(val):
for v in val:
orig[v] = None
else:
try:
update_dict(val)
except (AttributeError, TypeError, ValueError):
if SCons.Util.is_Dict(val):
for k, v in val.items():
orig[k] = v
else:
orig[val] = None
self.scanner_map_delete(kw) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:PrependUnique; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:delete_existing; 7, integer:0; 8, dictionary_splat_pattern; 8, 9; 9, identifier:kw; 10, block; 10, 11; 10, 13; 10, 20; 10, 276; 11, expression_statement; 11, 12; 12, comment; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:kw; 16, call; 16, 17; 16, 18; 17, identifier:copy_non_reserved_keywords; 18, argument_list; 18, 19; 19, identifier:kw; 20, for_statement; 20, 21; 20, 24; 20, 29; 21, pattern_list; 21, 22; 21, 23; 22, identifier:key; 23, identifier:val; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:kw; 27, identifier:items; 28, argument_list; 29, block; 29, 30; 29, 49; 30, if_statement; 30, 31; 30, 39; 31, call; 31, 32; 31, 37; 32, attribute; 32, 33; 32, 36; 33, attribute; 33, 34; 33, 35; 34, identifier:SCons; 35, identifier:Util; 36, identifier:is_List; 37, argument_list; 37, 38; 38, identifier:val; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:val; 43, call; 43, 44; 43, 45; 44, identifier:_delete_duplicates; 45, argument_list; 45, 46; 45, 47; 46, identifier:val; 47, not_operator; 47, 48; 48, identifier:delete_existing; 49, if_statement; 49, 50; 49, 65; 49, 74; 49, 109; 49, 182; 50, boolean_operator:or; 50, 51; 50, 56; 51, comparison_operator:not; 51, 52; 51, 53; 52, identifier:key; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:_dict; 56, comparison_operator:in; 56, 57; 56, 62; 57, subscript; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:_dict; 61, identifier:key; 62, tuple; 62, 63; 62, 64; 63, string:''; 64, None; 65, block; 65, 66; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 73; 68, subscript; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:self; 71, identifier:_dict; 72, identifier:key; 73, identifier:val; 74, elif_clause; 74, 75; 74, 97; 75, boolean_operator:and; 75, 76; 75, 88; 75, 89; 76, call; 76, 77; 76, 82; 77, attribute; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:SCons; 80, identifier:Util; 81, identifier:is_Dict; 82, argument_list; 82, 83; 83, subscript; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:self; 86, identifier:_dict; 87, identifier:key; 88, line_continuation:\; 89, call; 89, 90; 89, 95; 90, attribute; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:SCons; 93, identifier:Util; 94, identifier:is_Dict; 95, argument_list; 95, 96; 96, identifier:val; 97, block; 97, 98; 98, expression_statement; 98, 99; 99, call; 99, 100; 99, 107; 100, attribute; 100, 101; 100, 106; 101, subscript; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:self; 104, identifier:_dict; 105, identifier:key; 106, identifier:update; 107, argument_list; 107, 108; 108, identifier:val; 109, elif_clause; 109, 110; 109, 118; 110, call; 110, 111; 110, 116; 111, attribute; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:SCons; 114, identifier:Util; 115, identifier:is_List; 116, argument_list; 116, 117; 117, identifier:val; 118, block; 118, 119; 118, 127; 118, 143; 118, 172; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:dk; 122, subscript; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:self; 125, identifier:_dict; 126, identifier:key; 127, if_statement; 127, 128; 127, 137; 128, not_operator; 128, 129; 129, call; 129, 130; 129, 135; 130, attribute; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:SCons; 133, identifier:Util; 134, identifier:is_List; 135, argument_list; 135, 136; 136, identifier:dk; 137, block; 137, 138; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:dk; 141, list:[dk]; 141, 142; 142, identifier:dk; 143, if_statement; 143, 144; 143, 145; 143, 158; 144, identifier:delete_existing; 145, block; 145, 146; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:dk; 149, list_comprehension; 149, 150; 149, 151; 149, 154; 150, identifier:x; 151, for_in_clause; 151, 152; 151, 153; 152, identifier:x; 153, identifier:dk; 154, if_clause; 154, 155; 155, comparison_operator:not; 155, 156; 155, 157; 156, identifier:x; 157, identifier:val; 158, else_clause; 158, 159; 159, block; 159, 160; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:val; 163, list_comprehension; 163, 164; 163, 165; 163, 168; 164, identifier:x; 165, for_in_clause; 165, 166; 165, 167; 166, identifier:x; 167, identifier:val; 168, if_clause; 168, 169; 169, comparison_operator:not; 169, 170; 169, 171; 170, identifier:x; 171, identifier:dk; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 179; 174, subscript; 174, 175; 174, 178; 175, attribute; 175, 176; 175, 177; 176, identifier:self; 177, identifier:_dict; 178, identifier:key; 179, binary_operator:+; 179, 180; 179, 181; 180, identifier:val; 181, identifier:dk; 182, else_clause; 182, 183; 183, block; 183, 184; 183, 192; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 187; 186, identifier:dk; 187, subscript; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:self; 190, identifier:_dict; 191, identifier:key; 192, if_statement; 192, 193; 192, 201; 192, 202; 192, 203; 192, 249; 193, call; 193, 194; 193, 199; 194, attribute; 194, 195; 194, 198; 195, attribute; 195, 196; 195, 197; 196, identifier:SCons; 197, identifier:Util; 198, identifier:is_List; 199, argument_list; 199, 200; 200, identifier:dk; 201, comment; 202, comment; 203, block; 203, 204; 204, if_statement; 204, 205; 204, 206; 204, 230; 205, identifier:delete_existing; 206, block; 206, 207; 206, 219; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 210; 209, identifier:dk; 210, list_comprehension; 210, 211; 210, 212; 210, 215; 211, identifier:x; 212, for_in_clause; 212, 213; 212, 214; 213, identifier:x; 214, identifier:dk; 215, if_clause; 215, 216; 216, comparison_operator:not; 216, 217; 216, 218; 217, identifier:x; 218, identifier:val; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 226; 221, subscript; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:self; 224, identifier:_dict; 225, identifier:key; 226, binary_operator:+; 226, 227; 226, 229; 227, list:[val]; 227, 228; 228, identifier:val; 229, identifier:dk; 230, else_clause; 230, 231; 231, block; 231, 232; 232, if_statement; 232, 233; 232, 237; 233, not_operator; 233, 234; 234, comparison_operator:in; 234, 235; 234, 236; 235, identifier:val; 236, identifier:dk; 237, block; 237, 238; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 245; 240, subscript; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:self; 243, identifier:_dict; 244, identifier:key; 245, binary_operator:+; 245, 246; 245, 248; 246, list:[val]; 246, 247; 247, identifier:val; 248, identifier:dk; 249, else_clause; 249, 250; 250, block; 250, 251; 250, 266; 251, if_statement; 251, 252; 251, 253; 252, identifier:delete_existing; 253, block; 253, 254; 254, expression_statement; 254, 255; 255, assignment; 255, 256; 255, 257; 256, identifier:dk; 257, list_comprehension; 257, 258; 257, 259; 257, 262; 258, identifier:x; 259, for_in_clause; 259, 260; 259, 261; 260, identifier:x; 261, identifier:dk; 262, if_clause; 262, 263; 263, comparison_operator:not; 263, 264; 263, 265; 264, identifier:x; 265, identifier:val; 266, expression_statement; 266, 267; 267, assignment; 267, 268; 267, 273; 268, subscript; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:self; 271, identifier:_dict; 272, identifier:key; 273, binary_operator:+; 273, 274; 273, 275; 274, identifier:val; 275, identifier:dk; 276, expression_statement; 276, 277; 277, call; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, identifier:self; 280, identifier:scanner_map_delete; 281, argument_list; 281, 282; 282, identifier:kw | def PrependUnique(self, delete_existing=0, **kw):
"""Prepend values to existing construction variables
in an Environment, if they're not already there.
If delete_existing is 1, removes existing values first, so
values move to front.
"""
kw = copy_non_reserved_keywords(kw)
for key, val in kw.items():
if SCons.Util.is_List(val):
val = _delete_duplicates(val, not delete_existing)
if key not in self._dict or self._dict[key] in ('', None):
self._dict[key] = val
elif SCons.Util.is_Dict(self._dict[key]) and \
SCons.Util.is_Dict(val):
self._dict[key].update(val)
elif SCons.Util.is_List(val):
dk = self._dict[key]
if not SCons.Util.is_List(dk):
dk = [dk]
if delete_existing:
dk = [x for x in dk if x not in val]
else:
val = [x for x in val if x not in dk]
self._dict[key] = val + dk
else:
dk = self._dict[key]
if SCons.Util.is_List(dk):
# By elimination, val is not a list. Since dk is a
# list, wrap val in a list first.
if delete_existing:
dk = [x for x in dk if x not in val]
self._dict[key] = [val] + dk
else:
if not val in dk:
self._dict[key] = [val] + dk
else:
if delete_existing:
dk = [x for x in dk if x not in val]
self._dict[key] = val + dk
self.scanner_map_delete(kw) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:wait_idle; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:timeout; 7, float:1.0; 8, block; 8, 9; 8, 11; 8, 85; 8, 104; 8, 113; 9, expression_statement; 9, 10; 10, comment; 11, function_definition; 11, 12; 11, 13; 11, 14; 12, function_name:_awaiter; 13, parameters; 14, block; 14, 15; 14, 29; 14, 54; 14, 69; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:background_work; 18, set_comprehension; 18, 19; 18, 24; 19, call; 19, 20; 19, 23; 20, attribute; 20, 21; 20, 22; 21, identifier:x; 22, identifier:join; 23, argument_list; 24, for_in_clause; 24, 25; 24, 26; 25, identifier:x; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:_work_queues; 29, for_statement; 29, 30; 29, 31; 29, 34; 30, identifier:event; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:_events; 34, block; 34, 35; 35, if_statement; 35, 36; 35, 42; 36, not_operator; 36, 37; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:event; 40, identifier:is_set; 41, argument_list; 42, block; 42, 43; 43, expression_statement; 43, 44; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:background_work; 47, identifier:add; 48, argument_list; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:event; 52, identifier:wait; 53, argument_list; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 59; 56, pattern_list; 56, 57; 56, 58; 57, identifier:_done; 58, identifier:pending; 59, await; 59, 60; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:asyncio; 63, identifier:wait; 64, argument_list; 64, 65; 64, 66; 65, identifier:background_work; 66, keyword_argument; 66, 67; 66, 68; 67, identifier:timeout; 68, identifier:timeout; 69, if_statement; 69, 70; 69, 76; 70, comparison_operator:>; 70, 71; 70, 75; 71, call; 71, 72; 71, 73; 72, identifier:len; 73, argument_list; 73, 74; 74, identifier:pending; 75, integer:0; 76, block; 76, 77; 77, raise_statement; 77, 78; 78, call; 78, 79; 78, 80; 79, identifier:TimeoutExpiredError; 80, argument_list; 80, 81; 80, 82; 81, string:"Timeout waiting for event loop to become idle"; 82, keyword_argument; 82, 83; 82, 84; 83, identifier:pending; 84, identifier:pending; 85, if_statement; 85, 86; 85, 91; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:self; 89, identifier:_on_emulation_thread; 90, argument_list; 91, block; 91, 92; 92, return_statement; 92, 93; 93, call; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:asyncio; 96, identifier:wait_for; 97, argument_list; 97, 98; 97, 101; 98, call; 98, 99; 98, 100; 99, identifier:_awaiter; 100, argument_list; 101, keyword_argument; 101, 102; 101, 103; 102, identifier:timeout; 103, identifier:timeout; 104, expression_statement; 104, 105; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:self; 108, identifier:run_task_external; 109, argument_list; 109, 110; 110, call; 110, 111; 110, 112; 111, identifier:_awaiter; 112, argument_list; 113, return_statement; 113, 114; 114, None | def wait_idle(self, timeout=1.0):
"""Wait until the rpc queue is empty.
This method may be called either from within the event loop or from
outside of it. If it is called outside of the event loop it will
block the calling thread until the rpc queue is temporarily empty.
If it is called from within the event loop it will return an awaitable
object that can be used to wait for the same condition.
The awaitable object will already have a timeout if the timeout
parameter is passed.
Args:
timeout (float): The maximum number of seconds to wait.
"""
async def _awaiter():
background_work = {x.join() for x in self._work_queues}
for event in self._events:
if not event.is_set():
background_work.add(event.wait())
_done, pending = await asyncio.wait(background_work, timeout=timeout)
if len(pending) > 0:
raise TimeoutExpiredError("Timeout waiting for event loop to become idle", pending=pending)
if self._on_emulation_thread():
return asyncio.wait_for(_awaiter(), timeout=timeout)
self.run_task_external(_awaiter())
return None |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_process_long_opt; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:rargs; 6, identifier:values; 7, block; 7, 8; 7, 10; 7, 19; 7, 20; 7, 21; 7, 60; 7, 106; 7, 114; 7, 289; 8, expression_statement; 8, 9; 9, comment; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:arg; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:rargs; 16, identifier:pop; 17, argument_list; 17, 18; 18, integer:0; 19, comment; 20, comment; 21, if_statement; 21, 22; 21, 25; 21, 50; 22, comparison_operator:in; 22, 23; 22, 24; 23, string:"="; 24, identifier:arg; 25, block; 25, 26; 25, 38; 25, 46; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 31; 28, tuple_pattern; 28, 29; 28, 30; 29, identifier:opt; 30, identifier:next_arg; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:arg; 34, identifier:split; 35, argument_list; 35, 36; 35, 37; 36, string:"="; 37, integer:1; 38, expression_statement; 38, 39; 39, call; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:rargs; 42, identifier:insert; 43, argument_list; 43, 44; 43, 45; 44, integer:0; 45, identifier:next_arg; 46, expression_statement; 46, 47; 47, assignment; 47, 48; 47, 49; 48, identifier:had_explicit_value; 49, True; 50, else_clause; 50, 51; 51, block; 51, 52; 51, 56; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:opt; 55, identifier:arg; 56, expression_statement; 56, 57; 57, assignment; 57, 58; 57, 59; 58, identifier:had_explicit_value; 59, False; 60, try_statement; 60, 61; 60, 71; 61, block; 61, 62; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:opt; 65, call; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:_match_long_opt; 69, argument_list; 69, 70; 70, identifier:opt; 71, except_clause; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:optparse; 74, identifier:BadOptionError; 75, block; 75, 76; 75, 105; 76, if_statement; 76, 77; 76, 80; 76, 81; 76, 82; 77, attribute; 77, 78; 77, 79; 78, identifier:self; 79, identifier:preserve_unknown_options; 80, comment; 81, comment; 82, block; 82, 83; 82, 92; 82, 104; 83, expression_statement; 83, 84; 84, call; 84, 85; 84, 90; 85, attribute; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:self; 88, identifier:largs; 89, identifier:append; 90, argument_list; 90, 91; 91, identifier:arg; 92, if_statement; 92, 93; 92, 94; 92, 95; 92, 96; 93, identifier:had_explicit_value; 94, comment; 95, comment; 96, block; 96, 97; 97, expression_statement; 97, 98; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:rargs; 101, identifier:pop; 102, argument_list; 102, 103; 103, integer:0; 104, return_statement; 105, raise_statement; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:option; 109, subscript; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:self; 112, identifier:_long_opt; 113, identifier:opt; 114, if_statement; 114, 115; 114, 120; 114, 268; 114, 283; 115, call; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:option; 118, identifier:takes_value; 119, argument_list; 120, block; 120, 121; 120, 127; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:nargs; 124, attribute; 124, 125; 124, 126; 125, identifier:option; 126, identifier:nargs; 127, if_statement; 127, 128; 127, 131; 127, 152; 127, 233; 127, 247; 128, comparison_operator:==; 128, 129; 128, 130; 129, identifier:nargs; 130, string:'?'; 131, block; 131, 132; 132, if_statement; 132, 133; 132, 134; 132, 144; 133, identifier:had_explicit_value; 134, block; 134, 135; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:value; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:rargs; 141, identifier:pop; 142, argument_list; 142, 143; 143, integer:0; 144, else_clause; 144, 145; 145, block; 145, 146; 146, expression_statement; 146, 147; 147, assignment; 147, 148; 147, 149; 148, identifier:value; 149, attribute; 149, 150; 149, 151; 150, identifier:option; 151, identifier:const; 152, elif_clause; 152, 153; 152, 159; 153, comparison_operator:<; 153, 154; 153, 158; 154, call; 154, 155; 154, 156; 155, identifier:len; 156, argument_list; 156, 157; 157, identifier:rargs; 158, identifier:nargs; 159, block; 159, 160; 160, if_statement; 160, 161; 160, 164; 160, 217; 161, comparison_operator:==; 161, 162; 161, 163; 162, identifier:nargs; 163, integer:1; 164, block; 164, 165; 165, if_statement; 165, 166; 165, 170; 165, 183; 166, not_operator; 166, 167; 167, attribute; 167, 168; 167, 169; 168, identifier:option; 169, identifier:choices; 170, block; 170, 171; 171, expression_statement; 171, 172; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:self; 175, identifier:error; 176, argument_list; 176, 177; 177, binary_operator:%; 177, 178; 177, 182; 178, call; 178, 179; 178, 180; 179, identifier:_; 180, argument_list; 180, 181; 181, string:"%s option requires an argument"; 182, identifier:opt; 183, else_clause; 183, 184; 184, block; 184, 185; 184, 194; 184, 210; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:msg; 188, call; 188, 189; 188, 190; 189, identifier:_; 190, argument_list; 190, 191; 191, binary_operator:%; 191, 192; 191, 193; 192, string:"%s option requires an argument "; 193, identifier:opt; 194, expression_statement; 194, 195; 195, augmented_assignment:+=; 195, 196; 195, 197; 196, identifier:msg; 197, call; 197, 198; 197, 199; 198, identifier:_; 199, argument_list; 199, 200; 200, binary_operator:%; 200, 201; 200, 202; 201, string:"(choose from %s)"; 202, call; 202, 203; 202, 206; 203, attribute; 203, 204; 203, 205; 204, string:', '; 205, identifier:join; 206, argument_list; 206, 207; 207, attribute; 207, 208; 207, 209; 208, identifier:option; 209, identifier:choices; 210, expression_statement; 210, 211; 211, call; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:self; 214, identifier:error; 215, argument_list; 215, 216; 216, identifier:msg; 217, else_clause; 217, 218; 218, block; 218, 219; 219, expression_statement; 219, 220; 220, call; 220, 221; 220, 224; 221, attribute; 221, 222; 221, 223; 222, identifier:self; 223, identifier:error; 224, argument_list; 224, 225; 225, binary_operator:%; 225, 226; 225, 230; 226, call; 226, 227; 226, 228; 227, identifier:_; 228, argument_list; 228, 229; 229, string:"%s option requires %d arguments"; 230, tuple; 230, 231; 230, 232; 231, identifier:opt; 232, identifier:nargs; 233, elif_clause; 233, 234; 233, 237; 234, comparison_operator:==; 234, 235; 234, 236; 235, identifier:nargs; 236, integer:1; 237, block; 237, 238; 238, expression_statement; 238, 239; 239, assignment; 239, 240; 239, 241; 240, identifier:value; 241, call; 241, 242; 241, 245; 242, attribute; 242, 243; 242, 244; 243, identifier:rargs; 244, identifier:pop; 245, argument_list; 245, 246; 246, integer:0; 247, else_clause; 247, 248; 248, block; 248, 249; 248, 261; 249, expression_statement; 249, 250; 250, assignment; 250, 251; 250, 252; 251, identifier:value; 252, call; 252, 253; 252, 254; 253, identifier:tuple; 254, argument_list; 254, 255; 255, subscript; 255, 256; 255, 257; 256, identifier:rargs; 257, slice; 257, 258; 257, 259; 257, 260; 258, integer:0; 259, colon; 260, identifier:nargs; 261, delete_statement; 261, 262; 262, subscript; 262, 263; 262, 264; 263, identifier:rargs; 264, slice; 264, 265; 264, 266; 264, 267; 265, integer:0; 266, colon; 267, identifier:nargs; 268, elif_clause; 268, 269; 268, 270; 269, identifier:had_explicit_value; 270, block; 270, 271; 271, expression_statement; 271, 272; 272, call; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:self; 275, identifier:error; 276, argument_list; 276, 277; 277, binary_operator:%; 277, 278; 277, 282; 278, call; 278, 279; 278, 280; 279, identifier:_; 280, argument_list; 280, 281; 281, string:"%s option does not take a value"; 282, identifier:opt; 283, else_clause; 283, 284; 284, block; 284, 285; 285, expression_statement; 285, 286; 286, assignment; 286, 287; 286, 288; 287, identifier:value; 288, None; 289, expression_statement; 289, 290; 290, call; 290, 291; 290, 294; 291, attribute; 291, 292; 291, 293; 292, identifier:option; 293, identifier:process; 294, argument_list; 294, 295; 294, 296; 294, 297; 294, 298; 295, identifier:opt; 296, identifier:value; 297, identifier:values; 298, identifier:self | def _process_long_opt(self, rargs, values):
"""
SCons-specific processing of long options.
This is copied directly from the normal
optparse._process_long_opt() method, except that, if configured
to do so, we catch the exception thrown when an unknown option
is encountered and just stick it back on the "leftover" arguments
for later (re-)processing.
"""
arg = rargs.pop(0)
# Value explicitly attached to arg? Pretend it's the next
# argument.
if "=" in arg:
(opt, next_arg) = arg.split("=", 1)
rargs.insert(0, next_arg)
had_explicit_value = True
else:
opt = arg
had_explicit_value = False
try:
opt = self._match_long_opt(opt)
except optparse.BadOptionError:
if self.preserve_unknown_options:
# SCons-specific: if requested, add unknown options to
# the "leftover arguments" list for later processing.
self.largs.append(arg)
if had_explicit_value:
# The unknown option will be re-processed later,
# so undo the insertion of the explicit value.
rargs.pop(0)
return
raise
option = self._long_opt[opt]
if option.takes_value():
nargs = option.nargs
if nargs == '?':
if had_explicit_value:
value = rargs.pop(0)
else:
value = option.const
elif len(rargs) < nargs:
if nargs == 1:
if not option.choices:
self.error(_("%s option requires an argument") % opt)
else:
msg = _("%s option requires an argument " % opt)
msg += _("(choose from %s)"
% ', '.join(option.choices))
self.error(msg)
else:
self.error(_("%s option requires %d arguments")
% (opt, nargs))
elif nargs == 1:
value = rargs.pop(0)
else:
value = tuple(rargs[0:nargs])
del rargs[0:nargs]
elif had_explicit_value:
self.error(_("%s option does not take a value") % opt)
else:
value = None
option.process(opt, value, values, self) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:Tag; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 9; 4, identifier:env; 5, identifier:target; 6, identifier:source; 7, list_splat_pattern; 7, 8; 8, identifier:more_tags; 9, dictionary_splat_pattern; 9, 10; 10, identifier:kw_tags; 11, block; 11, 12; 11, 14; 11, 32; 11, 43; 11, 63; 11, 64; 11, 74; 11, 104; 12, expression_statement; 12, 13; 13, comment; 14, if_statement; 14, 15; 14, 17; 14, 26; 15, not_operator; 15, 16; 16, identifier:target; 17, block; 17, 18; 17, 22; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:target; 21, identifier:source; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:first_tag; 25, None; 26, else_clause; 26, 27; 27, block; 27, 28; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:first_tag; 31, identifier:source; 32, if_statement; 32, 33; 32, 34; 33, identifier:first_tag; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 42; 37, subscript; 37, 38; 37, 39; 38, identifier:kw_tags; 39, subscript; 39, 40; 39, 41; 40, identifier:first_tag; 41, integer:0; 42, string:''; 43, if_statement; 43, 44; 43, 57; 44, boolean_operator:and; 44, 45; 44, 51; 45, comparison_operator:==; 45, 46; 45, 50; 46, call; 46, 47; 46, 48; 47, identifier:len; 48, argument_list; 48, 49; 49, identifier:kw_tags; 50, integer:0; 51, comparison_operator:==; 51, 52; 51, 56; 52, call; 52, 53; 52, 54; 53, identifier:len; 54, argument_list; 54, 55; 55, identifier:more_tags; 56, integer:0; 57, block; 57, 58; 58, raise_statement; 58, 59; 59, call; 59, 60; 59, 61; 60, identifier:UserError; 61, argument_list; 61, 62; 62, string:"No tags given."; 63, comment; 64, for_statement; 64, 65; 64, 66; 64, 67; 65, identifier:x; 66, identifier:more_tags; 67, block; 67, 68; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 73; 70, subscript; 70, 71; 70, 72; 71, identifier:kw_tags; 72, identifier:x; 73, string:''; 74, if_statement; 74, 75; 74, 84; 74, 90; 75, not_operator; 75, 76; 76, call; 76, 77; 76, 82; 77, attribute; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:SCons; 80, identifier:Util; 81, identifier:is_List; 82, argument_list; 82, 83; 83, identifier:target; 84, block; 84, 85; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:target; 88, list:[target]; 88, 89; 89, identifier:target; 90, else_clause; 90, 91; 90, 92; 90, 93; 90, 94; 91, comment; 92, comment; 93, comment; 94, block; 94, 95; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:target; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:env; 101, identifier:Flatten; 102, argument_list; 102, 103; 103, identifier:target; 104, for_statement; 104, 105; 104, 106; 104, 107; 105, identifier:t; 106, identifier:target; 107, block; 107, 108; 108, for_statement; 108, 109; 108, 112; 108, 117; 108, 118; 108, 119; 108, 120; 108, 121; 109, tuple_pattern; 109, 110; 109, 111; 110, identifier:k; 111, identifier:v; 112, call; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:kw_tags; 115, identifier:items; 116, argument_list; 117, comment; 118, comment; 119, comment; 120, comment; 121, block; 121, 122; 121, 137; 122, if_statement; 122, 123; 122, 130; 123, comparison_operator:!=; 123, 124; 123, 129; 124, subscript; 124, 125; 124, 126; 125, identifier:k; 126, slice; 126, 127; 126, 128; 127, colon; 128, integer:10; 129, string:'PACKAGING_'; 130, block; 130, 131; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:k; 134, binary_operator:+; 134, 135; 134, 136; 135, string:'PACKAGING_'; 136, identifier:k; 137, expression_statement; 137, 138; 138, call; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:t; 141, identifier:Tag; 142, argument_list; 142, 143; 142, 144; 143, identifier:k; 144, identifier:v | def Tag(env, target, source, *more_tags, **kw_tags):
""" Tag a file with the given arguments, just sets the accordingly named
attribute on the file object.
TODO: FIXME
"""
if not target:
target=source
first_tag=None
else:
first_tag=source
if first_tag:
kw_tags[first_tag[0]] = ''
if len(kw_tags) == 0 and len(more_tags) == 0:
raise UserError("No tags given.")
# XXX: sanity checks
for x in more_tags:
kw_tags[x] = ''
if not SCons.Util.is_List(target):
target=[target]
else:
# hmm, sometimes the target list, is a list of a list
# make sure it is flattened prior to processing.
# TODO: perhaps some bug ?!?
target=env.Flatten(target)
for t in target:
for (k,v) in kw_tags.items():
# all file tags have to start with PACKAGING_, so we can later
# differentiate between "normal" object attributes and the
# packaging attributes. As the user should not be bothered with
# that, the prefix will be added here if missing.
if k[:10] != 'PACKAGING_':
k='PACKAGING_'+k
t.Tag(k, v) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:find_vc_pdir; 3, parameters; 3, 4; 4, identifier:msvc_version; 5, block; 5, 6; 5, 8; 5, 12; 5, 37; 5, 207; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:root; 11, string:'Software\\'; 12, try_statement; 12, 13; 12, 20; 13, block; 13, 14; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:hkeys; 17, subscript; 17, 18; 17, 19; 18, identifier:_VCVER_TO_PRODUCT_DIR; 19, identifier:msvc_version; 20, except_clause; 20, 21; 20, 22; 21, identifier:KeyError; 22, block; 22, 23; 22, 30; 23, expression_statement; 23, 24; 24, call; 24, 25; 24, 26; 25, identifier:debug; 26, argument_list; 26, 27; 27, binary_operator:%; 27, 28; 27, 29; 28, string:"Unknown version of MSVC: %s"; 29, identifier:msvc_version; 30, raise_statement; 30, 31; 31, call; 31, 32; 31, 33; 32, identifier:UnsupportedVersion; 33, argument_list; 33, 34; 34, binary_operator:%; 34, 35; 34, 36; 35, string:"Unknown version %s"; 36, identifier:msvc_version; 37, for_statement; 37, 38; 37, 41; 37, 42; 38, pattern_list; 38, 39; 38, 40; 39, identifier:hkroot; 40, identifier:key; 41, identifier:hkeys; 42, block; 42, 43; 43, try_statement; 43, 44; 43, 138; 43, 161; 44, block; 44, 45; 44, 49; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:comps; 48, None; 49, if_statement; 49, 50; 49, 52; 49, 83; 50, not_operator; 50, 51; 51, identifier:key; 52, block; 52, 53; 52, 60; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:comps; 56, call; 56, 57; 56, 58; 57, identifier:find_vc_pdir_vswhere; 58, argument_list; 58, 59; 59, identifier:msvc_version; 60, if_statement; 60, 61; 60, 63; 61, not_operator; 61, 62; 62, identifier:comps; 63, block; 63, 64; 63, 77; 64, expression_statement; 64, 65; 65, call; 65, 66; 65, 67; 66, identifier:debug; 67, argument_list; 67, 68; 68, call; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, string:'find_vc_dir(): no VC found via vswhere for version {}'; 71, identifier:format; 72, argument_list; 72, 73; 73, call; 73, 74; 73, 75; 74, identifier:repr; 75, argument_list; 75, 76; 76, identifier:key; 77, raise_statement; 77, 78; 78, attribute; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:SCons; 81, identifier:Util; 82, identifier:WinError; 83, else_clause; 83, 84; 84, block; 84, 85; 84, 121; 85, if_statement; 85, 86; 85, 91; 86, call; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:common; 89, identifier:is_win64; 90, argument_list; 91, block; 91, 92; 92, try_statement; 92, 93; 92, 94; 92, 109; 93, comment; 94, block; 94, 95; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:comps; 98, call; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:common; 101, identifier:read_reg; 102, argument_list; 102, 103; 102, 108; 103, binary_operator:+; 103, 104; 103, 107; 104, binary_operator:+; 104, 105; 104, 106; 105, identifier:root; 106, string:'Wow6432Node\\'; 107, identifier:key; 108, identifier:hkroot; 109, except_clause; 109, 110; 109, 118; 109, 119; 110, as_pattern; 110, 111; 110, 116; 111, attribute; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:SCons; 114, identifier:Util; 115, identifier:WinError; 116, as_pattern_target; 116, 117; 117, identifier:e; 118, comment; 119, block; 119, 120; 120, pass_statement; 121, if_statement; 121, 122; 121, 124; 121, 125; 122, not_operator; 122, 123; 123, identifier:comps; 124, comment; 125, block; 125, 126; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:comps; 129, call; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:common; 132, identifier:read_reg; 133, argument_list; 133, 134; 133, 137; 134, binary_operator:+; 134, 135; 134, 136; 135, identifier:root; 136, identifier:key; 137, identifier:hkroot; 138, except_clause; 138, 139; 138, 147; 139, as_pattern; 139, 140; 139, 145; 140, attribute; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:SCons; 143, identifier:Util; 144, identifier:WinError; 145, as_pattern_target; 145, 146; 146, identifier:e; 147, block; 147, 148; 148, expression_statement; 148, 149; 149, call; 149, 150; 149, 151; 150, identifier:debug; 151, argument_list; 151, 152; 152, call; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, string:'find_vc_dir(): no VC registry key {}'; 155, identifier:format; 156, argument_list; 156, 157; 157, call; 157, 158; 157, 159; 158, identifier:repr; 159, argument_list; 159, 160; 160, identifier:key; 161, else_clause; 161, 162; 162, block; 162, 163; 162, 173; 163, expression_statement; 163, 164; 164, call; 164, 165; 164, 166; 165, identifier:debug; 166, argument_list; 166, 167; 167, call; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, string:'find_vc_dir(): found VC in registry: {}'; 170, identifier:format; 171, argument_list; 171, 172; 172, identifier:comps; 173, if_statement; 173, 174; 173, 182; 173, 185; 174, call; 174, 175; 174, 180; 175, attribute; 175, 176; 175, 179; 176, attribute; 176, 177; 176, 178; 177, identifier:os; 178, identifier:path; 179, identifier:exists; 180, argument_list; 180, 181; 181, identifier:comps; 182, block; 182, 183; 183, return_statement; 183, 184; 184, identifier:comps; 185, else_clause; 185, 186; 186, block; 186, 187; 186, 197; 187, expression_statement; 187, 188; 188, call; 188, 189; 188, 190; 189, identifier:debug; 190, argument_list; 190, 191; 191, call; 191, 192; 191, 195; 192, attribute; 192, 193; 192, 194; 193, string:'find_vc_dir(): reg says dir is {}, but it does not exist. (ignoring)'; 194, identifier:format; 195, argument_list; 195, 196; 196, identifier:comps; 197, raise_statement; 197, 198; 198, call; 198, 199; 198, 200; 199, identifier:MissingConfiguration; 200, argument_list; 200, 201; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, string:"registry dir {} not found on the filesystem"; 204, identifier:format; 205, argument_list; 205, 206; 206, identifier:comps; 207, return_statement; 207, 208; 208, None | def find_vc_pdir(msvc_version):
"""Try to find the product directory for the given
version.
Note
----
If for some reason the requested version could not be found, an
exception which inherits from VisualCException will be raised."""
root = 'Software\\'
try:
hkeys = _VCVER_TO_PRODUCT_DIR[msvc_version]
except KeyError:
debug("Unknown version of MSVC: %s" % msvc_version)
raise UnsupportedVersion("Unknown version %s" % msvc_version)
for hkroot, key in hkeys:
try:
comps = None
if not key:
comps = find_vc_pdir_vswhere(msvc_version)
if not comps:
debug('find_vc_dir(): no VC found via vswhere for version {}'.format(repr(key)))
raise SCons.Util.WinError
else:
if common.is_win64():
try:
# ordinally at win64, try Wow6432Node first.
comps = common.read_reg(root + 'Wow6432Node\\' + key, hkroot)
except SCons.Util.WinError as e:
# at Microsoft Visual Studio for Python 2.7, value is not in Wow6432Node
pass
if not comps:
# not Win64, or Microsoft Visual Studio for Python 2.7
comps = common.read_reg(root + key, hkroot)
except SCons.Util.WinError as e:
debug('find_vc_dir(): no VC registry key {}'.format(repr(key)))
else:
debug('find_vc_dir(): found VC in registry: {}'.format(comps))
if os.path.exists(comps):
return comps
else:
debug('find_vc_dir(): reg says dir is {}, but it does not exist. (ignoring)'.format(comps))
raise MissingConfiguration("registry dir {} not found on the filesystem".format(comps))
return None |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:allocate_stream; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:self; 5, identifier:stream_type; 6, default_parameter; 6, 7; 6, 8; 7, identifier:stream_id; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:previous; 11, None; 12, default_parameter; 12, 13; 12, 14; 13, identifier:attach; 14, False; 15, block; 15, 16; 15, 18; 15, 33; 15, 57; 15, 58; 15, 59; 15, 97; 15, 98; 15, 99; 15, 107; 15, 125; 15, 137; 16, expression_statement; 16, 17; 17, comment; 18, if_statement; 18, 19; 18, 24; 19, comparison_operator:not; 19, 20; 19, 21; 20, identifier:stream_type; 21, attribute; 21, 22; 21, 23; 22, identifier:DataStream; 23, identifier:TypeToString; 24, block; 24, 25; 25, raise_statement; 25, 26; 26, call; 26, 27; 26, 28; 27, identifier:ArgumentError; 28, argument_list; 28, 29; 28, 30; 29, string:"Unknown stream type in allocate_stream"; 30, keyword_argument; 30, 31; 30, 32; 31, identifier:stream_type; 32, identifier:stream_type; 33, if_statement; 33, 34; 33, 43; 34, boolean_operator:and; 34, 35; 34, 38; 35, comparison_operator:is; 35, 36; 35, 37; 36, identifier:stream_id; 37, None; 38, comparison_operator:>=; 38, 39; 38, 40; 39, identifier:stream_id; 40, attribute; 40, 41; 40, 42; 41, identifier:StreamAllocator; 42, identifier:StartingID; 43, block; 43, 44; 44, raise_statement; 44, 45; 45, call; 45, 46; 45, 47; 46, identifier:ArgumentError; 47, argument_list; 47, 48; 47, 49; 47, 52; 48, string:"Attempted to explicitly allocate a stream id in the internally managed id range"; 49, keyword_argument; 49, 50; 49, 51; 50, identifier:stream_id; 51, identifier:stream_id; 52, keyword_argument; 52, 53; 52, 54; 53, identifier:started_id; 54, attribute; 54, 55; 54, 56; 55, identifier:StreamAllocator; 56, identifier:StartingID; 57, comment; 58, comment; 59, if_statement; 59, 60; 59, 63; 60, comparison_operator:is; 60, 61; 60, 62; 61, identifier:stream_id; 62, None; 63, block; 63, 64; 63, 81; 63, 89; 64, if_statement; 64, 65; 64, 70; 65, comparison_operator:not; 65, 66; 65, 67; 66, identifier:stream_type; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:_next_id; 70, block; 70, 71; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 78; 73, subscript; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:self; 76, identifier:_next_id; 77, identifier:stream_type; 78, attribute; 78, 79; 78, 80; 79, identifier:StreamAllocator; 80, identifier:StartingID; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:stream_id; 84, subscript; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:self; 87, identifier:_next_id; 88, identifier:stream_type; 89, expression_statement; 89, 90; 90, augmented_assignment:+=; 90, 91; 90, 96; 91, subscript; 91, 92; 91, 95; 92, attribute; 92, 93; 92, 94; 93, identifier:self; 94, identifier:_next_id; 95, identifier:stream_type; 96, integer:1; 97, comment; 98, comment; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:stream; 102, call; 102, 103; 102, 104; 103, identifier:DataStream; 104, argument_list; 104, 105; 104, 106; 105, identifier:stream_type; 106, identifier:stream_id; 107, if_statement; 107, 108; 107, 113; 108, comparison_operator:not; 108, 109; 108, 110; 109, identifier:stream; 110, attribute; 110, 111; 110, 112; 111, identifier:self; 112, identifier:_allocated_streams; 113, block; 113, 114; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 121; 116, subscript; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:self; 119, identifier:_allocated_streams; 120, identifier:stream; 121, tuple; 121, 122; 121, 123; 121, 124; 122, identifier:stream; 123, integer:0; 124, identifier:previous; 125, if_statement; 125, 126; 125, 127; 126, identifier:attach; 127, block; 127, 128; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:stream; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:self; 134, identifier:attach_stream; 135, argument_list; 135, 136; 136, identifier:stream; 137, return_statement; 137, 138; 138, identifier:stream | def allocate_stream(self, stream_type, stream_id=None, previous=None, attach=False):
"""Allocate a new stream of the given type.
The stream is allocated with an incremental ID starting at
StreamAllocator.StartingID. The returned data stream can always
be used to to attach a NodeInput to this stream, however the
attach_stream() function should always be called first since this
stream's output may need to be split and a logically equivalent
stream used instead to satisfy a device specific constraint on the
maximum number of outputs attached to a given stream.
You can call allocate_stream on the same stream multiple times without
issue. Subsequent calls to allocate_stream are noops.
Args:
stream_type (int): A stream type specified in the DataStream class
like DataStream.ConstantType
stream_id (int): The ID we would like to use for this stream, if
this is not specified, an ID is automatically allocated.
previous (DataStream): If this stream was automatically derived from
another stream, this parameter should be a link to the old
stream.
attach (bool): Call attach_stream immediately before returning. Convenience
routine for streams that should immediately be attached to something.
Returns:
DataStream: The allocated data stream.
"""
if stream_type not in DataStream.TypeToString:
raise ArgumentError("Unknown stream type in allocate_stream", stream_type=stream_type)
if stream_id is not None and stream_id >= StreamAllocator.StartingID:
raise ArgumentError("Attempted to explicitly allocate a stream id in the internally managed id range", stream_id=stream_id, started_id=StreamAllocator.StartingID)
# If the stream id is not explicitly given, we need to manage and track it
# from our autoallocate range
if stream_id is None:
if stream_type not in self._next_id:
self._next_id[stream_type] = StreamAllocator.StartingID
stream_id = self._next_id[stream_type]
self._next_id[stream_type] += 1
# Keep track of how many downstream nodes are attached to this stream so
# that we know when we need to split it into two.
stream = DataStream(stream_type, stream_id)
if stream not in self._allocated_streams:
self._allocated_streams[stream] = (stream, 0, previous)
if attach:
stream = self.attach_stream(stream)
return stream |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:find_products; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:product_type; 6, block; 6, 7; 6, 9; 6, 28; 6, 85; 6, 98; 6, 109; 6, 128; 7, expression_statement; 7, 8; 8, comment; 9, if_statement; 9, 10; 9, 25; 10, boolean_operator:and; 10, 11; 10, 20; 11, boolean_operator:and; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:filter_prods; 15, comparison_operator:in; 15, 16; 15, 17; 16, identifier:product_type; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:LIST_PRODUCTS; 20, comparison_operator:not; 20, 21; 20, 22; 21, identifier:product_type; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:desired_prods; 25, block; 25, 26; 26, return_statement; 26, 27; 27, list:[]; 28, if_statement; 28, 29; 28, 34; 28, 47; 29, comparison_operator:in; 29, 30; 29, 31; 30, identifier:product_type; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:LIST_PRODUCTS; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:found_products; 38, call; 38, 39; 38, 44; 39, attribute; 39, 40; 39, 43; 40, attribute; 40, 41; 40, 42; 41, identifier:self; 42, identifier:products; 43, identifier:get; 44, argument_list; 44, 45; 44, 46; 45, identifier:product_type; 46, list:[]; 47, else_clause; 47, 48; 48, block; 48, 49; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:found_products; 52, list_comprehension; 52, 53; 52, 56; 52, 65; 53, subscript; 53, 54; 53, 55; 54, identifier:x; 55, integer:0; 56, for_in_clause; 56, 57; 56, 58; 57, identifier:x; 58, call; 58, 59; 58, 64; 59, attribute; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:products; 63, identifier:items; 64, argument_list; 65, if_clause; 65, 66; 66, boolean_operator:and; 66, 67; 66, 72; 67, comparison_operator:==; 67, 68; 67, 71; 68, subscript; 68, 69; 68, 70; 69, identifier:x; 70, integer:1; 71, identifier:product_type; 72, parenthesized_expression; 72, 73; 73, boolean_operator:or; 73, 74; 73, 78; 74, not_operator; 74, 75; 75, attribute; 75, 76; 75, 77; 76, identifier:self; 77, identifier:filter_prods; 78, comparison_operator:in; 78, 79; 78, 82; 79, subscript; 79, 80; 79, 81; 80, identifier:x; 81, integer:0; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:desired_prods; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:found_products; 88, list_comprehension; 88, 89; 88, 95; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:_ensure_product_string; 93, argument_list; 93, 94; 94, identifier:x; 95, for_in_clause; 95, 96; 95, 97; 96, identifier:x; 97, identifier:found_products; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:declaration; 101, call; 101, 102; 101, 107; 102, attribute; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:self; 105, identifier:PATH_PRODUCTS; 106, identifier:get; 107, argument_list; 107, 108; 108, identifier:product_type; 109, if_statement; 109, 110; 109, 113; 110, comparison_operator:is; 110, 111; 110, 112; 111, identifier:declaration; 112, None; 113, block; 113, 114; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:found_products; 117, list_comprehension; 117, 118; 117, 125; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:self; 121, identifier:_process_product_path; 122, argument_list; 122, 123; 122, 124; 123, identifier:x; 124, identifier:declaration; 125, for_in_clause; 125, 126; 125, 127; 126, identifier:x; 127, identifier:found_products; 128, return_statement; 128, 129; 129, identifier:found_products | def find_products(self, product_type):
"""Search for products of a given type.
Search through the products declared by this IOTile component and
return only those matching the given type. If the product is described
by the path to a file, a complete normalized path will be returned.
The path could be different depending on whether this IOTile component
is in development or release mode.
The behavior of this function when filter_products has been called is
slightly different based on whether product_type is in LIST_PRODUCTS
or not. If product type is in LIST_PRODUCTS, then all matching
products are returned if product_type itself was passed. So to get
all tilebus_definitions you would call
``filter_products('tilebus_definitions')``
By contrast, other products are filtered product-by-product. So there
is no way to filter and get **all libraries**. Instead you pass the
specific product names of the libraries that you want to
``filter_products`` and those specific libraries are returned.
Passing the literal string ``library`` to ``filter_products`` will not
return only the libraries, it will return nothing since no library is
named ``library``.
Args:
product_type (str): The type of product that we wish to return.
Returns:
list of str: The list of all products of the given type.
If no such products are found, an empty list will be returned.
If filter_products() has been called and the filter does not include
this product type, an empty list will be returned.
"""
if self.filter_prods and product_type in self.LIST_PRODUCTS and product_type not in self.desired_prods:
return []
if product_type in self.LIST_PRODUCTS:
found_products = self.products.get(product_type, [])
else:
found_products = [x[0] for x in self.products.items()
if x[1] == product_type and (not self.filter_prods or x[0] in self.desired_prods)]
found_products = [self._ensure_product_string(x) for x in found_products]
declaration = self.PATH_PRODUCTS.get(product_type)
if declaration is not None:
found_products = [self._process_product_path(x, declaration) for x in found_products]
return found_products |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:add_node; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:node_descriptor; 6, block; 6, 7; 6, 9; 6, 37; 6, 50; 6, 54; 6, 194; 6, 195; 6, 196; 6, 197; 6, 228; 6, 229; 6, 238; 6, 251; 6, 259; 7, expression_statement; 7, 8; 8, comment; 9, if_statement; 9, 10; 9, 26; 10, boolean_operator:and; 10, 11; 10, 16; 11, comparison_operator:is; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:_max_nodes; 15, None; 16, comparison_operator:>=; 16, 17; 16, 23; 17, call; 17, 18; 17, 19; 18, identifier:len; 19, argument_list; 19, 20; 20, attribute; 20, 21; 20, 22; 21, identifier:self; 22, identifier:nodes; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:_max_nodes; 26, block; 26, 27; 27, raise_statement; 27, 28; 28, call; 28, 29; 28, 30; 29, identifier:ResourceUsageError; 30, argument_list; 30, 31; 30, 32; 31, string:"Maximum number of nodes exceeded"; 32, keyword_argument; 32, 33; 32, 34; 33, identifier:max_nodes; 34, attribute; 34, 35; 34, 36; 35, identifier:self; 36, identifier:_max_nodes; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 43; 39, pattern_list; 39, 40; 39, 41; 39, 42; 40, identifier:node; 41, identifier:inputs; 42, identifier:processor; 43, call; 43, 44; 43, 45; 44, identifier:parse_node_descriptor; 45, argument_list; 45, 46; 45, 47; 46, identifier:node_descriptor; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:model; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:in_root; 53, False; 54, for_statement; 54, 55; 54, 58; 54, 62; 55, pattern_list; 55, 56; 55, 57; 56, identifier:i; 57, identifier:input_data; 58, call; 58, 59; 58, 60; 59, identifier:enumerate; 60, argument_list; 60, 61; 61, identifier:inputs; 62, block; 62, 63; 62, 69; 62, 80; 62, 81; 62, 105; 62, 114; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 68; 65, pattern_list; 65, 66; 65, 67; 66, identifier:selector; 67, identifier:trigger; 68, identifier:input_data; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:walker; 72, call; 72, 73; 72, 78; 73, attribute; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:self; 76, identifier:sensor_log; 77, identifier:create_walker; 78, argument_list; 78, 79; 79, identifier:selector; 80, comment; 81, if_statement; 81, 82; 81, 87; 82, attribute; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:walker; 85, identifier:selector; 86, identifier:inexhaustible; 87, block; 87, 88; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:walker; 92, identifier:reading; 93, call; 93, 94; 93, 95; 94, identifier:IOTileReading; 95, argument_list; 95, 96; 95, 97; 95, 104; 96, integer:0xFFFFFFFF; 97, call; 97, 98; 97, 103; 98, attribute; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:walker; 101, identifier:selector; 102, identifier:as_stream; 103, argument_list; 104, integer:0; 105, expression_statement; 105, 106; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:node; 109, identifier:connect_input; 110, argument_list; 110, 111; 110, 112; 110, 113; 111, identifier:i; 112, identifier:walker; 113, identifier:trigger; 114, if_statement; 114, 115; 114, 121; 114, 136; 115, boolean_operator:and; 115, 116; 115, 119; 116, attribute; 116, 117; 116, 118; 117, identifier:selector; 118, identifier:input; 119, not_operator; 119, 120; 120, identifier:in_root; 121, block; 121, 122; 121, 131; 121, 135; 122, expression_statement; 122, 123; 123, call; 123, 124; 123, 129; 124, attribute; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:self; 127, identifier:roots; 128, identifier:append; 129, argument_list; 129, 130; 130, identifier:node; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:in_root; 134, True; 135, comment; 136, else_clause; 136, 137; 137, block; 137, 138; 137, 142; 137, 169; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:found; 141, False; 142, for_statement; 142, 143; 142, 144; 142, 147; 143, identifier:other; 144, attribute; 144, 145; 144, 146; 145, identifier:self; 146, identifier:nodes; 147, block; 147, 148; 148, if_statement; 148, 149; 148, 157; 149, call; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:selector; 152, identifier:matches; 153, argument_list; 153, 154; 154, attribute; 154, 155; 154, 156; 155, identifier:other; 156, identifier:stream; 157, block; 157, 158; 157, 165; 158, expression_statement; 158, 159; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:other; 162, identifier:connect_output; 163, argument_list; 163, 164; 164, identifier:node; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:found; 168, True; 169, if_statement; 169, 170; 169, 176; 170, boolean_operator:and; 170, 171; 170, 173; 171, not_operator; 171, 172; 172, identifier:found; 173, attribute; 173, 174; 173, 175; 174, identifier:selector; 175, identifier:buffered; 176, block; 176, 177; 177, raise_statement; 177, 178; 178, call; 178, 179; 178, 180; 179, identifier:NodeConnectionError; 180, argument_list; 180, 181; 180, 182; 180, 185; 180, 191; 181, string:"Node has input that refers to another node that has not been created yet"; 182, keyword_argument; 182, 183; 182, 184; 183, identifier:node_descriptor; 184, identifier:node_descriptor; 185, keyword_argument; 185, 186; 185, 187; 186, identifier:input_selector; 187, call; 187, 188; 187, 189; 188, identifier:str; 189, argument_list; 189, 190; 190, identifier:selector; 191, keyword_argument; 191, 192; 191, 193; 192, identifier:input_index; 193, identifier:i; 194, comment; 195, comment; 196, comment; 197, for_statement; 197, 198; 197, 199; 197, 202; 198, identifier:other_node; 199, attribute; 199, 200; 199, 201; 200, identifier:self; 201, identifier:nodes; 202, block; 202, 203; 203, for_statement; 203, 204; 203, 207; 203, 210; 204, pattern_list; 204, 205; 204, 206; 205, identifier:selector; 206, identifier:trigger; 207, attribute; 207, 208; 207, 209; 208, identifier:other_node; 209, identifier:inputs; 210, block; 210, 211; 211, if_statement; 211, 212; 211, 220; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:selector; 215, identifier:matches; 216, argument_list; 216, 217; 217, attribute; 217, 218; 217, 219; 218, identifier:node; 219, identifier:stream; 220, block; 220, 221; 221, expression_statement; 221, 222; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:node; 225, identifier:connect_output; 226, argument_list; 226, 227; 227, identifier:other_node; 228, comment; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 232; 231, identifier:func; 232, call; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:self; 235, identifier:find_processing_function; 236, argument_list; 236, 237; 237, identifier:processor; 238, if_statement; 238, 239; 238, 242; 239, comparison_operator:is; 239, 240; 239, 241; 240, identifier:func; 241, None; 242, block; 242, 243; 243, raise_statement; 243, 244; 244, call; 244, 245; 244, 246; 245, identifier:ProcessingFunctionError; 246, argument_list; 246, 247; 246, 248; 247, string:"Could not find processing function in installed packages"; 248, keyword_argument; 248, 249; 248, 250; 249, identifier:func_name; 250, identifier:processor; 251, expression_statement; 251, 252; 252, call; 252, 253; 252, 256; 253, attribute; 253, 254; 253, 255; 254, identifier:node; 255, identifier:set_func; 256, argument_list; 256, 257; 256, 258; 257, identifier:processor; 258, identifier:func; 259, expression_statement; 259, 260; 260, call; 260, 261; 260, 266; 261, attribute; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:self; 264, identifier:nodes; 265, identifier:append; 266, argument_list; 266, 267; 267, identifier:node | def add_node(self, node_descriptor):
"""Add a node to the sensor graph based on the description given.
The node_descriptor must follow the sensor graph DSL and describe
a node whose input nodes already exist.
Args:
node_descriptor (str): A description of the node to be added
including its inputs, triggering conditions, processing function
and output stream.
"""
if self._max_nodes is not None and len(self.nodes) >= self._max_nodes:
raise ResourceUsageError("Maximum number of nodes exceeded", max_nodes=self._max_nodes)
node, inputs, processor = parse_node_descriptor(node_descriptor, self.model)
in_root = False
for i, input_data in enumerate(inputs):
selector, trigger = input_data
walker = self.sensor_log.create_walker(selector)
# Constant walkers begin life initialized to 0 so they always read correctly
if walker.selector.inexhaustible:
walker.reading = IOTileReading(0xFFFFFFFF, walker.selector.as_stream(), 0)
node.connect_input(i, walker, trigger)
if selector.input and not in_root:
self.roots.append(node)
in_root = True # Make sure we only add to root list once
else:
found = False
for other in self.nodes:
if selector.matches(other.stream):
other.connect_output(node)
found = True
if not found and selector.buffered:
raise NodeConnectionError("Node has input that refers to another node that has not been created yet", node_descriptor=node_descriptor, input_selector=str(selector), input_index=i)
# Also make sure we add this node's output to any other existing node's inputs
# this is important for constant nodes that may be written from multiple places
# FIXME: Make sure when we emit nodes, they are topologically sorted
for other_node in self.nodes:
for selector, trigger in other_node.inputs:
if selector.matches(node.stream):
node.connect_output(other_node)
# Find and load the processing function for this node
func = self.find_processing_function(processor)
if func is None:
raise ProcessingFunctionError("Could not find processing function in installed packages", func_name=processor)
node.set_func(processor, func)
self.nodes.append(node) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:check_streamers; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:blacklist; 7, None; 8, block; 8, 9; 8, 11; 8, 15; 8, 21; 8, 164; 9, expression_statement; 9, 10; 10, comment; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:ready; 14, list:[]; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:selected; 18, call; 18, 19; 18, 20; 19, identifier:set; 20, argument_list; 21, for_statement; 21, 22; 21, 25; 21, 31; 22, pattern_list; 22, 23; 22, 24; 23, identifier:i; 24, identifier:streamer; 25, call; 25, 26; 25, 27; 26, identifier:enumerate; 27, argument_list; 27, 28; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:streamers; 31, block; 31, 32; 31, 42; 31, 48; 31, 52; 31, 72; 32, if_statement; 32, 33; 32, 40; 33, boolean_operator:and; 33, 34; 33, 37; 34, comparison_operator:is; 34, 35; 34, 36; 35, identifier:blacklist; 36, None; 37, comparison_operator:in; 37, 38; 37, 39; 38, identifier:i; 39, identifier:blacklist; 40, block; 40, 41; 41, continue_statement; 42, if_statement; 42, 43; 42, 46; 43, comparison_operator:in; 43, 44; 43, 45; 44, identifier:i; 45, identifier:selected; 46, block; 46, 47; 47, continue_statement; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:marked; 51, False; 52, if_statement; 52, 53; 52, 58; 53, comparison_operator:in; 53, 54; 53, 55; 54, identifier:i; 55, attribute; 55, 56; 55, 57; 56, identifier:self; 57, identifier:_manually_triggered_streamers; 58, block; 58, 59; 58, 63; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:marked; 62, True; 63, expression_statement; 63, 64; 64, call; 64, 65; 64, 70; 65, attribute; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:_manually_triggered_streamers; 69, identifier:remove; 70, argument_list; 70, 71; 71, identifier:i; 72, if_statement; 72, 73; 72, 79; 73, call; 73, 74; 73, 77; 74, attribute; 74, 75; 74, 76; 75, identifier:streamer; 76, identifier:triggered; 77, argument_list; 77, 78; 78, identifier:marked; 79, block; 79, 80; 79, 91; 79, 98; 79, 105; 79, 106; 80, expression_statement; 80, 81; 81, call; 81, 82; 81, 87; 82, attribute; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:self; 85, identifier:_logger; 86, identifier:debug; 87, argument_list; 87, 88; 87, 89; 87, 90; 88, string:"Streamer %d triggered, manual=%s"; 89, identifier:i; 90, identifier:marked; 91, expression_statement; 91, 92; 92, call; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:ready; 95, identifier:append; 96, argument_list; 96, 97; 97, identifier:streamer; 98, expression_statement; 98, 99; 99, call; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:selected; 102, identifier:add; 103, argument_list; 103, 104; 104, identifier:i; 105, comment; 106, for_statement; 106, 107; 106, 110; 106, 120; 107, pattern_list; 107, 108; 107, 109; 108, identifier:j; 109, identifier:streamer2; 110, call; 110, 111; 110, 112; 111, identifier:enumerate; 112, argument_list; 112, 113; 113, subscript; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:self; 116, identifier:streamers; 117, slice; 117, 118; 117, 119; 118, identifier:i; 119, colon; 120, block; 120, 121; 121, if_statement; 121, 122; 121, 138; 122, boolean_operator:and; 122, 123; 122, 132; 123, boolean_operator:and; 123, 124; 123, 129; 124, comparison_operator:==; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:streamer2; 127, identifier:with_other; 128, identifier:i; 129, comparison_operator:not; 129, 130; 129, 131; 130, identifier:j; 131, identifier:selected; 132, call; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:streamer2; 135, identifier:triggered; 136, argument_list; 136, 137; 137, True; 138, block; 138, 139; 138, 150; 138, 157; 139, expression_statement; 139, 140; 140, call; 140, 141; 140, 146; 141, attribute; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:self; 144, identifier:_logger; 145, identifier:debug; 146, argument_list; 146, 147; 146, 148; 146, 149; 147, string:"Streamer %d triggered due to with-other on %d"; 148, identifier:j; 149, identifier:i; 150, expression_statement; 150, 151; 151, call; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:ready; 154, identifier:append; 155, argument_list; 155, 156; 156, identifier:streamer2; 157, expression_statement; 157, 158; 158, call; 158, 159; 158, 162; 159, attribute; 159, 160; 159, 161; 160, identifier:selected; 161, identifier:add; 162, argument_list; 162, 163; 163, identifier:j; 164, return_statement; 164, 165; 165, identifier:ready | def check_streamers(self, blacklist=None):
"""Check if any streamers are ready to produce a report.
You can limit what streamers are checked by passing a set-like
object into blacklist.
This method is the primary way to see when you should poll a given
streamer for its next report.
Note, this function is not idempotent. If a streamer is marked as
manual and it is triggered from a node rule inside the sensor_graph,
that trigger will only last as long as the next call to
check_streamers() so you need to explicitly build a report on all
ready streamers before calling check_streamers again.
Args:
blacklist (set): Optional set of streamer indices that should
not be checked right now.
Returns:
list of DataStreamer: A list of the ready streamers.
"""
ready = []
selected = set()
for i, streamer in enumerate(self.streamers):
if blacklist is not None and i in blacklist:
continue
if i in selected:
continue
marked = False
if i in self._manually_triggered_streamers:
marked = True
self._manually_triggered_streamers.remove(i)
if streamer.triggered(marked):
self._logger.debug("Streamer %d triggered, manual=%s", i, marked)
ready.append(streamer)
selected.add(i)
# Handle streamers triggered with another
for j, streamer2 in enumerate(self.streamers[i:]):
if streamer2.with_other == i and j not in selected and streamer2.triggered(True):
self._logger.debug("Streamer %d triggered due to with-other on %d", j, i)
ready.append(streamer2)
selected.add(j)
return ready |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:sort_nodes; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 28; 5, 32; 5, 71; 5, 72; 5, 73; 5, 80; 5, 94; 5, 95; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:node_map; 11, dictionary_comprehension; 11, 12; 11, 18; 12, pair; 12, 13; 12, 17; 13, call; 13, 14; 13, 15; 14, identifier:id; 15, argument_list; 15, 16; 16, identifier:node; 17, identifier:i; 18, for_in_clause; 18, 19; 18, 22; 19, pattern_list; 19, 20; 19, 21; 20, identifier:i; 21, identifier:node; 22, call; 22, 23; 22, 24; 23, identifier:enumerate; 24, argument_list; 24, 25; 25, attribute; 25, 26; 25, 27; 26, identifier:self; 27, identifier:nodes; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 31; 30, identifier:node_deps; 31, dictionary; 32, for_statement; 32, 33; 32, 37; 32, 42; 33, pattern_list; 33, 34; 33, 35; 33, 36; 34, identifier:node; 35, identifier:inputs; 36, identifier:_outputs; 37, call; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:iterate_bfs; 41, argument_list; 42, block; 42, 43; 42, 52; 42, 65; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:node_index; 46, subscript; 46, 47; 46, 48; 47, identifier:node_map; 48, call; 48, 49; 48, 50; 49, identifier:id; 50, argument_list; 50, 51; 51, identifier:node; 52, expression_statement; 52, 53; 53, assignment; 53, 54; 53, 55; 54, identifier:deps; 55, set_comprehension; 55, 56; 55, 62; 56, subscript; 56, 57; 56, 58; 57, identifier:node_map; 58, call; 58, 59; 58, 60; 59, identifier:id; 60, argument_list; 60, 61; 61, identifier:x; 62, for_in_clause; 62, 63; 62, 64; 63, identifier:x; 64, identifier:inputs; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 70; 67, subscript; 67, 68; 67, 69; 68, identifier:node_deps; 69, identifier:node_index; 70, identifier:deps; 71, comment; 72, comment; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:node_order; 76, call; 76, 77; 76, 78; 77, identifier:toposort_flatten; 78, argument_list; 78, 79; 79, identifier:node_deps; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:nodes; 85, list_comprehension; 85, 86; 85, 91; 86, subscript; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:self; 89, identifier:nodes; 90, identifier:x; 91, for_in_clause; 91, 92; 91, 93; 92, identifier:x; 93, identifier:node_order; 94, comment; 95, for_statement; 95, 96; 95, 97; 95, 100; 96, identifier:root; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:roots; 100, block; 100, 101; 101, if_statement; 101, 102; 101, 117; 102, comparison_operator:not; 102, 103; 102, 104; 103, identifier:root; 104, subscript; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:self; 107, identifier:nodes; 108, slice; 108, 109; 108, 110; 108, 111; 109, integer:0; 110, colon; 111, call; 111, 112; 111, 113; 112, identifier:len; 113, argument_list; 113, 114; 114, attribute; 114, 115; 114, 116; 115, identifier:self; 116, identifier:roots; 117, block; 117, 118; 118, raise_statement; 118, 119; 119, call; 119, 120; 119, 121; 120, identifier:NodeConnectionError; 121, argument_list; 121, 122; 121, 123; 121, 129; 122, string:"Inputs not sorted in the beginning"; 123, keyword_argument; 123, 124; 123, 125; 124, identifier:node; 125, call; 125, 126; 125, 127; 126, identifier:str; 127, argument_list; 127, 128; 128, identifier:root; 129, keyword_argument; 129, 130; 129, 131; 130, identifier:node_position; 131, call; 131, 132; 131, 137; 132, attribute; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:self; 135, identifier:nodes; 136, identifier:index; 137, argument_list; 137, 138; 138, identifier:root | def sort_nodes(self):
"""Topologically sort all of our nodes.
Topologically sorting our nodes makes nodes that are inputs to other
nodes come first in the list of nodes. This is important to do before
programming a sensorgraph into an embedded device whose engine assumes
a topologically sorted graph.
The sorting is done in place on self.nodes
"""
node_map = {id(node): i for i, node in enumerate(self.nodes)}
node_deps = {}
for node, inputs, _outputs in self.iterate_bfs():
node_index = node_map[id(node)]
deps = {node_map[id(x)] for x in inputs}
node_deps[node_index] = deps
# Now that we have our dependency tree properly built, topologically
# sort the nodes and reorder them.
node_order = toposort_flatten(node_deps)
self.nodes = [self.nodes[x] for x in node_order]
#Check root nodes all topographically sorted to the beginning
for root in self.roots:
if root not in self.nodes[0:len(self.roots)]:
raise NodeConnectionError("Inputs not sorted in the beginning", node=str(root), node_position=self.nodes.index(root)) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:mark_typed_list; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:name; 6, identifier:type_object; 7, block; 7, 8; 7, 10; 7, 25; 7, 40; 7, 82; 7, 105; 8, expression_statement; 8, 9; 9, comment; 10, if_statement; 10, 11; 10, 17; 11, not_operator; 11, 12; 12, call; 12, 13; 12, 14; 13, identifier:hasattr; 14, argument_list; 14, 15; 14, 16; 15, identifier:type_object; 16, string:'dump'; 17, block; 17, 18; 18, raise_statement; 18, 19; 19, call; 19, 20; 19, 21; 20, identifier:ArgumentError; 21, argument_list; 21, 22; 22, binary_operator:%; 22, 23; 22, 24; 23, string:"The passed type object %s is missing required method: dump()"; 24, identifier:type_object; 25, if_statement; 25, 26; 25, 32; 26, not_operator; 26, 27; 27, call; 27, 28; 27, 29; 28, identifier:hasattr; 29, argument_list; 29, 30; 29, 31; 30, identifier:type_object; 31, string:'Restore'; 32, block; 32, 33; 33, raise_statement; 33, 34; 34, call; 34, 35; 34, 36; 35, identifier:ArgumentError; 36, argument_list; 36, 37; 37, binary_operator:%; 37, 38; 37, 39; 38, string:"The passed type object %s is missing required method: Restore()"; 39, identifier:type_object; 40, function_definition; 40, 41; 40, 42; 40, 44; 41, function_name:_dump_list; 42, parameters; 42, 43; 43, identifier:obj; 44, block; 44, 45; 44, 52; 44, 72; 45, if_statement; 45, 46; 45, 49; 46, comparison_operator:is; 46, 47; 46, 48; 47, identifier:obj; 48, None; 49, block; 49, 50; 50, return_statement; 50, 51; 51, None; 52, if_statement; 52, 53; 52, 59; 53, not_operator; 53, 54; 54, call; 54, 55; 54, 56; 55, identifier:isinstance; 56, argument_list; 56, 57; 56, 58; 57, identifier:obj; 58, identifier:list; 59, block; 59, 60; 60, raise_statement; 60, 61; 61, call; 61, 62; 61, 63; 62, identifier:DataError; 63, argument_list; 63, 64; 64, binary_operator:%; 64, 65; 64, 66; 65, string:"Property %s marked as list was not a list: %s"; 66, tuple; 66, 67; 66, 68; 67, identifier:name; 68, call; 68, 69; 68, 70; 69, identifier:repr; 70, argument_list; 70, 71; 71, identifier:obj; 72, return_statement; 72, 73; 73, list_comprehension; 73, 74; 73, 79; 74, call; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:x; 77, identifier:dump; 78, argument_list; 79, for_in_clause; 79, 80; 79, 81; 80, identifier:x; 81, identifier:obj; 82, function_definition; 82, 83; 82, 84; 82, 86; 83, function_name:_restore_list; 84, parameters; 84, 85; 85, identifier:obj; 86, block; 86, 87; 86, 94; 87, if_statement; 87, 88; 87, 91; 88, comparison_operator:is; 88, 89; 88, 90; 89, identifier:obj; 90, None; 91, block; 91, 92; 92, return_statement; 92, 93; 93, identifier:obj; 94, return_statement; 94, 95; 95, list_comprehension; 95, 96; 95, 102; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:type_object; 99, identifier:Restore; 100, argument_list; 100, 101; 101, identifier:x; 102, for_in_clause; 102, 103; 102, 104; 103, identifier:x; 104, identifier:obj; 105, expression_statement; 105, 106; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:self; 109, identifier:mark_complex; 110, argument_list; 110, 111; 110, 112; 110, 113; 111, identifier:name; 112, identifier:_dump_list; 113, identifier:_restore_list | def mark_typed_list(self, name, type_object):
"""Mark a property as containing serializable objects of a given type.
This convenience method allows you to avoid having to call
``mark_complex()`` whenever you need to serialize a list of objects.
This method requires that all members of the given list be of a single
class that contains a dump() method and a Restore() class method where
type_object.Restore(x.dump()) == x.
Args:
name (str): The name of the complex property.
type_object: The class object that will be contained inside
this list.
"""
if not hasattr(type_object, 'dump'):
raise ArgumentError("The passed type object %s is missing required method: dump()" % type_object)
if not hasattr(type_object, 'Restore'):
raise ArgumentError("The passed type object %s is missing required method: Restore()" % type_object)
def _dump_list(obj):
if obj is None:
return None
if not isinstance(obj, list):
raise DataError("Property %s marked as list was not a list: %s" % (name, repr(obj)))
return [x.dump() for x in obj]
def _restore_list(obj):
if obj is None:
return obj
return [type_object.Restore(x) for x in obj]
self.mark_complex(name, _dump_list, _restore_list) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:mark_typed_map; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:name; 6, identifier:type_object; 7, block; 7, 8; 7, 10; 7, 25; 7, 40; 7, 90; 7, 121; 8, expression_statement; 8, 9; 9, comment; 10, if_statement; 10, 11; 10, 17; 11, not_operator; 11, 12; 12, call; 12, 13; 12, 14; 13, identifier:hasattr; 14, argument_list; 14, 15; 14, 16; 15, identifier:type_object; 16, string:'dump'; 17, block; 17, 18; 18, raise_statement; 18, 19; 19, call; 19, 20; 19, 21; 20, identifier:ArgumentError; 21, argument_list; 21, 22; 22, binary_operator:%; 22, 23; 22, 24; 23, string:"The passed type object %s is missing required method: dump()"; 24, identifier:type_object; 25, if_statement; 25, 26; 25, 32; 26, not_operator; 26, 27; 27, call; 27, 28; 27, 29; 28, identifier:hasattr; 29, argument_list; 29, 30; 29, 31; 30, identifier:type_object; 31, string:'Restore'; 32, block; 32, 33; 33, raise_statement; 33, 34; 34, call; 34, 35; 34, 36; 35, identifier:ArgumentError; 36, argument_list; 36, 37; 37, binary_operator:%; 37, 38; 37, 39; 38, string:"The passed type object %s is missing required method: Restore()"; 39, identifier:type_object; 40, function_definition; 40, 41; 40, 42; 40, 44; 41, function_name:_dump_map; 42, parameters; 42, 43; 43, identifier:obj; 44, block; 44, 45; 44, 52; 44, 72; 45, if_statement; 45, 46; 45, 49; 46, comparison_operator:is; 46, 47; 46, 48; 47, identifier:obj; 48, None; 49, block; 49, 50; 50, return_statement; 50, 51; 51, None; 52, if_statement; 52, 53; 52, 59; 53, not_operator; 53, 54; 54, call; 54, 55; 54, 56; 55, identifier:isinstance; 56, argument_list; 56, 57; 56, 58; 57, identifier:obj; 58, identifier:dict; 59, block; 59, 60; 60, raise_statement; 60, 61; 61, call; 61, 62; 61, 63; 62, identifier:DataError; 63, argument_list; 63, 64; 64, binary_operator:%; 64, 65; 64, 66; 65, string:"Property %s marked as list was not a dict: %s"; 66, tuple; 66, 67; 66, 68; 67, identifier:name; 68, call; 68, 69; 68, 70; 69, identifier:repr; 70, argument_list; 70, 71; 71, identifier:obj; 72, return_statement; 72, 73; 73, dictionary_comprehension; 73, 74; 73, 81; 74, pair; 74, 75; 74, 76; 75, identifier:key; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:val; 79, identifier:dump; 80, argument_list; 81, for_in_clause; 81, 82; 81, 85; 82, pattern_list; 82, 83; 82, 84; 83, identifier:key; 84, identifier:val; 85, call; 85, 86; 85, 89; 86, attribute; 86, 87; 86, 88; 87, identifier:obj; 88, identifier:items; 89, argument_list; 90, function_definition; 90, 91; 90, 92; 90, 94; 91, function_name:_restore_map; 92, parameters; 92, 93; 93, identifier:obj; 94, block; 94, 95; 94, 102; 95, if_statement; 95, 96; 95, 99; 96, comparison_operator:is; 96, 97; 96, 98; 97, identifier:obj; 98, None; 99, block; 99, 100; 100, return_statement; 100, 101; 101, identifier:obj; 102, return_statement; 102, 103; 103, dictionary_comprehension; 103, 104; 103, 112; 104, pair; 104, 105; 104, 106; 105, identifier:key; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:type_object; 109, identifier:Restore; 110, argument_list; 110, 111; 111, identifier:val; 112, for_in_clause; 112, 113; 112, 116; 113, pattern_list; 113, 114; 113, 115; 114, identifier:key; 115, identifier:val; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:obj; 119, identifier:items; 120, argument_list; 121, expression_statement; 121, 122; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:self; 125, identifier:mark_complex; 126, argument_list; 126, 127; 126, 128; 126, 129; 127, identifier:name; 128, identifier:_dump_map; 129, identifier:_restore_map | def mark_typed_map(self, name, type_object):
"""Mark a property as containing a map str to serializable object.
This convenience method allows you to avoid having to call
``mark_complex()`` whenever you need to serialize a dict of objects.
This method requires that all members of the given dict be of a single
class that contains a dump() method and a Restore() class method where
type_object.Restore(x.dump()) == x.
Args:
name (str): The name of the complex property.
type_object: The class object that will be contained inside
this dict.
"""
if not hasattr(type_object, 'dump'):
raise ArgumentError("The passed type object %s is missing required method: dump()" % type_object)
if not hasattr(type_object, 'Restore'):
raise ArgumentError("The passed type object %s is missing required method: Restore()" % type_object)
def _dump_map(obj):
if obj is None:
return None
if not isinstance(obj, dict):
raise DataError("Property %s marked as list was not a dict: %s" % (name, repr(obj)))
return {key: val.dump() for key, val in obj.items()}
def _restore_map(obj):
if obj is None:
return obj
return {key: type_object.Restore(val) for key, val in obj.items()}
self.mark_complex(name, _dump_map, _restore_map) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:mark_typed_object; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:name; 6, identifier:type_object; 7, block; 7, 8; 7, 10; 7, 25; 7, 40; 7, 58; 7, 77; 8, expression_statement; 8, 9; 9, comment; 10, if_statement; 10, 11; 10, 17; 11, not_operator; 11, 12; 12, call; 12, 13; 12, 14; 13, identifier:hasattr; 14, argument_list; 14, 15; 14, 16; 15, identifier:type_object; 16, string:'dump'; 17, block; 17, 18; 18, raise_statement; 18, 19; 19, call; 19, 20; 19, 21; 20, identifier:ArgumentError; 21, argument_list; 21, 22; 22, binary_operator:%; 22, 23; 22, 24; 23, string:"The passed type object %s is missing required method: dump()"; 24, identifier:type_object; 25, if_statement; 25, 26; 25, 32; 26, not_operator; 26, 27; 27, call; 27, 28; 27, 29; 28, identifier:hasattr; 29, argument_list; 29, 30; 29, 31; 30, identifier:type_object; 31, string:'Restore'; 32, block; 32, 33; 33, raise_statement; 33, 34; 34, call; 34, 35; 34, 36; 35, identifier:ArgumentError; 36, argument_list; 36, 37; 37, binary_operator:%; 37, 38; 37, 39; 38, string:"The passed type object %s is missing required method: Restore()"; 39, identifier:type_object; 40, function_definition; 40, 41; 40, 42; 40, 44; 41, function_name:_dump_obj; 42, parameters; 42, 43; 43, identifier:obj; 44, block; 44, 45; 44, 52; 45, if_statement; 45, 46; 45, 49; 46, comparison_operator:is; 46, 47; 46, 48; 47, identifier:obj; 48, None; 49, block; 49, 50; 50, return_statement; 50, 51; 51, None; 52, return_statement; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:obj; 56, identifier:dump; 57, argument_list; 58, function_definition; 58, 59; 58, 60; 58, 62; 59, function_name:_restore_obj; 60, parameters; 60, 61; 61, identifier:obj; 62, block; 62, 63; 62, 70; 63, if_statement; 63, 64; 63, 67; 64, comparison_operator:is; 64, 65; 64, 66; 65, identifier:obj; 66, None; 67, block; 67, 68; 68, return_statement; 68, 69; 69, identifier:obj; 70, return_statement; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:type_object; 74, identifier:Restore; 75, argument_list; 75, 76; 76, identifier:obj; 77, expression_statement; 77, 78; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:self; 81, identifier:mark_complex; 82, argument_list; 82, 83; 82, 84; 82, 85; 83, identifier:name; 84, identifier:_dump_obj; 85, identifier:_restore_obj | def mark_typed_object(self, name, type_object):
"""Mark a property as containing a serializable object.
This convenience method allows you to avoid having to call
``mark_complex()`` whenever you need to serialize a complex object.
This method requires that property ``name`` be a single class that
contains a dump() method and a Restore() class method where
type_object.Restore(x.dump()) == x.
Args:
name (str): The name of the complex property.
type_object: The class object that will be contained inside
this property.
"""
if not hasattr(type_object, 'dump'):
raise ArgumentError("The passed type object %s is missing required method: dump()" % type_object)
if not hasattr(type_object, 'Restore'):
raise ArgumentError("The passed type object %s is missing required method: Restore()" % type_object)
def _dump_obj(obj):
if obj is None:
return None
return obj.dump()
def _restore_obj(obj):
if obj is None:
return obj
return type_object.Restore(obj)
self.mark_complex(name, _dump_obj, _restore_obj) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:scan; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:node; 5, identifier:env; 6, default_parameter; 6, 7; 6, 8; 7, identifier:libpath; 8, tuple; 9, block; 9, 10; 9, 12; 9, 26; 9, 34; 9, 66; 9, 98; 9, 102; 9, 131; 9, 135; 9, 147; 9, 157; 9, 165; 9, 224; 10, expression_statement; 10, 11; 11, comment; 12, try_statement; 12, 13; 12, 20; 13, block; 13, 14; 14, expression_statement; 14, 15; 15, assignment; 15, 16; 15, 17; 16, identifier:libs; 17, subscript; 17, 18; 17, 19; 18, identifier:env; 19, string:'LIBS'; 20, except_clause; 20, 21; 20, 22; 20, 23; 21, identifier:KeyError; 22, comment; 23, block; 23, 24; 24, return_statement; 24, 25; 25, list:[]; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:libs; 29, call; 29, 30; 29, 31; 30, identifier:_subst_libs; 31, argument_list; 31, 32; 31, 33; 32, identifier:env; 33, identifier:libs; 34, try_statement; 34, 35; 34, 58; 35, block; 35, 36; 35, 42; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:prefix; 39, subscript; 39, 40; 39, 41; 40, identifier:env; 41, string:'LIBPREFIXES'; 42, if_statement; 42, 43; 42, 52; 43, not_operator; 43, 44; 44, call; 44, 45; 44, 50; 45, attribute; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:SCons; 48, identifier:Util; 49, identifier:is_List; 50, argument_list; 50, 51; 51, identifier:prefix; 52, block; 52, 53; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:prefix; 56, list:[ prefix ]; 56, 57; 57, identifier:prefix; 58, except_clause; 58, 59; 58, 60; 59, identifier:KeyError; 60, block; 60, 61; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:prefix; 64, list:[ '' ]; 64, 65; 65, string:''; 66, try_statement; 66, 67; 66, 90; 67, block; 67, 68; 67, 74; 68, expression_statement; 68, 69; 69, assignment; 69, 70; 69, 71; 70, identifier:suffix; 71, subscript; 71, 72; 71, 73; 72, identifier:env; 73, string:'LIBSUFFIXES'; 74, if_statement; 74, 75; 74, 84; 75, not_operator; 75, 76; 76, call; 76, 77; 76, 82; 77, attribute; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:SCons; 80, identifier:Util; 81, identifier:is_List; 82, argument_list; 82, 83; 83, identifier:suffix; 84, block; 84, 85; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:suffix; 88, list:[ suffix ]; 88, 89; 89, identifier:suffix; 90, except_clause; 90, 91; 90, 92; 91, identifier:KeyError; 92, block; 92, 93; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:suffix; 96, list:[ '' ]; 96, 97; 97, string:''; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 101; 100, identifier:pairs; 101, list:[]; 102, for_statement; 102, 103; 102, 104; 102, 111; 103, identifier:suf; 104, call; 104, 105; 104, 106; 105, identifier:map; 106, argument_list; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:env; 109, identifier:subst; 110, identifier:suffix; 111, block; 111, 112; 112, for_statement; 112, 113; 112, 114; 112, 121; 113, identifier:pref; 114, call; 114, 115; 114, 116; 115, identifier:map; 116, argument_list; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:env; 119, identifier:subst; 120, identifier:prefix; 121, block; 121, 122; 122, expression_statement; 122, 123; 123, call; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:pairs; 126, identifier:append; 127, argument_list; 127, 128; 128, tuple; 128, 129; 128, 130; 129, identifier:pref; 130, identifier:suf; 131, expression_statement; 131, 132; 132, assignment; 132, 133; 132, 134; 133, identifier:result; 134, list:[]; 135, if_statement; 135, 136; 135, 140; 136, call; 136, 137; 136, 138; 137, identifier:callable; 138, argument_list; 138, 139; 139, identifier:libpath; 140, block; 140, 141; 141, expression_statement; 141, 142; 142, assignment; 142, 143; 142, 144; 143, identifier:libpath; 144, call; 144, 145; 144, 146; 145, identifier:libpath; 146, argument_list; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:find_file; 150, attribute; 150, 151; 150, 156; 151, attribute; 151, 152; 151, 155; 152, attribute; 152, 153; 152, 154; 153, identifier:SCons; 154, identifier:Node; 155, identifier:FS; 156, identifier:find_file; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:adjustixes; 160, attribute; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:SCons; 163, identifier:Util; 164, identifier:adjustixes; 165, for_statement; 165, 166; 165, 167; 165, 168; 166, identifier:lib; 167, identifier:libs; 168, block; 168, 169; 169, if_statement; 169, 170; 169, 178; 169, 215; 170, call; 170, 171; 170, 176; 171, attribute; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:SCons; 174, identifier:Util; 175, identifier:is_String; 176, argument_list; 176, 177; 177, identifier:lib; 178, block; 178, 179; 179, for_statement; 179, 180; 179, 183; 179, 184; 180, pattern_list; 180, 181; 180, 182; 181, identifier:pref; 182, identifier:suf; 183, identifier:pairs; 184, block; 184, 185; 184, 194; 184, 205; 185, expression_statement; 185, 186; 186, assignment; 186, 187; 186, 188; 187, identifier:l; 188, call; 188, 189; 188, 190; 189, identifier:adjustixes; 190, argument_list; 190, 191; 190, 192; 190, 193; 191, identifier:lib; 192, identifier:pref; 193, identifier:suf; 194, expression_statement; 194, 195; 195, assignment; 195, 196; 195, 197; 196, identifier:l; 197, call; 197, 198; 197, 199; 198, identifier:find_file; 199, argument_list; 199, 200; 199, 201; 199, 202; 200, identifier:l; 201, identifier:libpath; 202, keyword_argument; 202, 203; 202, 204; 203, identifier:verbose; 204, identifier:print_find_libs; 205, if_statement; 205, 206; 205, 207; 206, identifier:l; 207, block; 207, 208; 208, expression_statement; 208, 209; 209, call; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:result; 212, identifier:append; 213, argument_list; 213, 214; 214, identifier:l; 215, else_clause; 215, 216; 216, block; 216, 217; 217, expression_statement; 217, 218; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:result; 221, identifier:append; 222, argument_list; 222, 223; 223, identifier:lib; 224, return_statement; 224, 225; 225, identifier:result | def scan(node, env, libpath = ()):
"""
This scanner scans program files for static-library
dependencies. It will search the LIBPATH environment variable
for libraries specified in the LIBS variable, returning any
files it finds as dependencies.
"""
try:
libs = env['LIBS']
except KeyError:
# There are no LIBS in this environment, so just return a null list:
return []
libs = _subst_libs(env, libs)
try:
prefix = env['LIBPREFIXES']
if not SCons.Util.is_List(prefix):
prefix = [ prefix ]
except KeyError:
prefix = [ '' ]
try:
suffix = env['LIBSUFFIXES']
if not SCons.Util.is_List(suffix):
suffix = [ suffix ]
except KeyError:
suffix = [ '' ]
pairs = []
for suf in map(env.subst, suffix):
for pref in map(env.subst, prefix):
pairs.append((pref, suf))
result = []
if callable(libpath):
libpath = libpath()
find_file = SCons.Node.FS.find_file
adjustixes = SCons.Util.adjustixes
for lib in libs:
if SCons.Util.is_String(lib):
for pref, suf in pairs:
l = adjustixes(lib, pref, suf)
l = find_file(l, libpath, verbose=print_find_libs)
if l:
result.append(l)
else:
result.append(lib)
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:render_recursive_template; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 4, identifier:template_folder; 5, identifier:info; 6, identifier:out_folder; 7, default_parameter; 7, 8; 7, 9; 8, identifier:preserve; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:dry_run; 12, False; 13, block; 13, 14; 13, 16; 13, 31; 13, 40; 13, 47; 13, 57; 13, 69; 13, 113; 13, 117; 13, 121; 13, 122; 13, 248; 13, 249; 13, 367; 14, expression_statement; 14, 15; 15, comment; 16, if_statement; 16, 17; 16, 22; 17, call; 17, 18; 17, 19; 18, identifier:isinstance; 19, argument_list; 19, 20; 19, 21; 20, identifier:preserve; 21, identifier:str; 22, block; 22, 23; 23, raise_statement; 23, 24; 24, call; 24, 25; 24, 26; 25, identifier:ArgumentError; 26, argument_list; 26, 27; 26, 28; 27, string:"You must pass a list of strings to preserve, not a string"; 28, keyword_argument; 28, 29; 28, 30; 29, identifier:preserve; 30, identifier:preserve; 31, if_statement; 31, 32; 31, 35; 32, comparison_operator:is; 32, 33; 32, 34; 33, identifier:preserve; 34, None; 35, block; 35, 36; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:preserve; 39, list:[]; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:preserve; 43, call; 43, 44; 43, 45; 44, identifier:set; 45, argument_list; 45, 46; 46, identifier:preserve; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:template_dir; 50, call; 50, 51; 50, 52; 51, identifier:resource_path; 52, argument_list; 52, 53; 52, 54; 53, string:'templates'; 54, keyword_argument; 54, 55; 54, 56; 55, identifier:expect; 56, string:'folder'; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:indir; 60, call; 60, 61; 60, 66; 61, attribute; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:os; 64, identifier:path; 65, identifier:join; 66, argument_list; 66, 67; 66, 68; 67, identifier:template_dir; 68, identifier:template_folder; 69, if_statement; 69, 70; 69, 79; 69, 91; 70, not_operator; 70, 71; 71, call; 71, 72; 71, 77; 72, attribute; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:os; 75, identifier:path; 76, identifier:exists; 77, argument_list; 77, 78; 78, identifier:indir; 79, block; 79, 80; 80, raise_statement; 80, 81; 81, call; 81, 82; 81, 83; 82, identifier:ArgumentError; 83, argument_list; 83, 84; 83, 85; 83, 88; 84, string:"Input template folder for recursive template not found"; 85, keyword_argument; 85, 86; 85, 87; 86, identifier:template_folder; 87, identifier:template_folder; 88, keyword_argument; 88, 89; 88, 90; 89, identifier:absolute_path; 90, identifier:indir; 91, elif_clause; 91, 92; 91, 101; 92, not_operator; 92, 93; 93, call; 93, 94; 93, 99; 94, attribute; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:os; 97, identifier:path; 98, identifier:isdir; 99, argument_list; 99, 100; 100, identifier:indir; 101, block; 101, 102; 102, raise_statement; 102, 103; 103, call; 103, 104; 103, 105; 104, identifier:ArgumentError; 105, argument_list; 105, 106; 105, 107; 105, 110; 106, string:"Input template folder is not a directory"; 107, keyword_argument; 107, 108; 107, 109; 108, identifier:template_folder; 109, identifier:template_folder; 110, keyword_argument; 110, 111; 110, 112; 111, identifier:absolute_path; 112, identifier:indir; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:create_dirs; 116, list:[]; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:file_map; 120, dictionary; 121, comment; 122, for_statement; 122, 123; 122, 127; 122, 133; 123, pattern_list; 123, 124; 123, 125; 123, 126; 124, identifier:dirpath; 125, identifier:dirs; 126, identifier:files; 127, call; 127, 128; 127, 131; 128, attribute; 128, 129; 128, 130; 129, identifier:os; 130, identifier:walk; 131, argument_list; 131, 132; 132, identifier:indir; 133, block; 133, 134; 134, for_statement; 134, 135; 134, 136; 134, 137; 135, identifier:file; 136, identifier:files; 137, block; 137, 138; 137, 157; 137, 179; 137, 207; 137, 215; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:in_abspath; 141, call; 141, 142; 141, 147; 142, attribute; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:os; 145, identifier:path; 146, identifier:abspath; 147, argument_list; 147, 148; 148, call; 148, 149; 148, 154; 149, attribute; 149, 150; 149, 153; 150, attribute; 150, 151; 150, 152; 151, identifier:os; 152, identifier:path; 153, identifier:join; 154, argument_list; 154, 155; 154, 156; 155, identifier:dirpath; 156, identifier:file; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:in_path; 160, call; 160, 161; 160, 166; 161, attribute; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:os; 164, identifier:path; 165, identifier:relpath; 166, argument_list; 166, 167; 166, 176; 167, call; 167, 168; 167, 173; 168, attribute; 168, 169; 168, 172; 169, attribute; 169, 170; 169, 171; 170, identifier:os; 171, identifier:path; 172, identifier:join; 173, argument_list; 173, 174; 173, 175; 174, identifier:dirpath; 175, identifier:file; 176, keyword_argument; 176, 177; 176, 178; 177, identifier:start; 178, identifier:indir; 179, if_statement; 179, 180; 179, 191; 179, 201; 180, boolean_operator:and; 180, 181; 180, 187; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:file; 184, identifier:endswith; 185, argument_list; 185, 186; 186, string:".tpl"; 187, not_operator; 187, 188; 188, comparison_operator:in; 188, 189; 188, 190; 189, identifier:in_path; 190, identifier:preserve; 191, block; 191, 192; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 195; 194, identifier:out_path; 195, subscript; 195, 196; 195, 197; 196, identifier:in_path; 197, slice; 197, 198; 197, 199; 198, colon; 199, unary_operator:-; 199, 200; 200, integer:4; 201, else_clause; 201, 202; 202, block; 202, 203; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 206; 205, identifier:out_path; 206, identifier:in_path; 207, expression_statement; 207, 208; 208, assignment; 208, 209; 208, 212; 209, subscript; 209, 210; 209, 211; 210, identifier:file_map; 211, identifier:out_path; 212, tuple; 212, 213; 212, 214; 213, identifier:in_path; 214, identifier:in_abspath; 215, for_statement; 215, 216; 215, 217; 215, 218; 216, identifier:folder; 217, identifier:dirs; 218, block; 218, 219; 218, 241; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 222; 221, identifier:dir_path; 222, call; 222, 223; 222, 228; 223, attribute; 223, 224; 223, 227; 224, attribute; 224, 225; 224, 226; 225, identifier:os; 226, identifier:path; 227, identifier:relpath; 228, argument_list; 228, 229; 228, 238; 229, call; 229, 230; 229, 235; 230, attribute; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:os; 233, identifier:path; 234, identifier:join; 235, argument_list; 235, 236; 235, 237; 236, identifier:dirpath; 237, identifier:folder; 238, keyword_argument; 238, 239; 238, 240; 239, identifier:start; 240, identifier:indir; 241, expression_statement; 241, 242; 242, call; 242, 243; 242, 246; 243, attribute; 243, 244; 243, 245; 244, identifier:create_dirs; 245, identifier:append; 246, argument_list; 246, 247; 247, identifier:dir_path; 248, comment; 249, if_statement; 249, 250; 249, 252; 250, not_operator; 250, 251; 251, identifier:dry_run; 252, block; 252, 253; 252, 287; 253, for_statement; 253, 254; 253, 255; 253, 256; 254, identifier:folder; 255, identifier:create_dirs; 256, block; 256, 257; 256, 269; 257, expression_statement; 257, 258; 258, assignment; 258, 259; 258, 260; 259, identifier:out_path; 260, call; 260, 261; 260, 266; 261, attribute; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:os; 264, identifier:path; 265, identifier:join; 266, argument_list; 266, 267; 266, 268; 267, identifier:out_folder; 268, identifier:folder; 269, if_statement; 269, 270; 269, 279; 270, not_operator; 270, 271; 271, call; 271, 272; 271, 277; 272, attribute; 272, 273; 272, 276; 273, attribute; 273, 274; 273, 275; 274, identifier:os; 275, identifier:path; 276, identifier:isdir; 277, argument_list; 277, 278; 278, identifier:out_path; 279, block; 279, 280; 280, expression_statement; 280, 281; 281, call; 281, 282; 281, 285; 282, attribute; 282, 283; 282, 284; 283, identifier:os; 284, identifier:makedirs; 285, argument_list; 285, 286; 286, identifier:out_path; 287, for_statement; 287, 288; 287, 293; 287, 298; 288, pattern_list; 288, 289; 288, 290; 289, identifier:out_rel; 290, tuple_pattern; 290, 291; 290, 292; 291, identifier:in_path; 292, identifier:in_abspath; 293, call; 293, 294; 293, 297; 294, attribute; 294, 295; 294, 296; 295, identifier:file_map; 296, identifier:items; 297, argument_list; 298, block; 298, 299; 298, 311; 299, expression_statement; 299, 300; 300, assignment; 300, 301; 300, 302; 301, identifier:out_path; 302, call; 302, 303; 302, 308; 303, attribute; 303, 304; 303, 307; 304, attribute; 304, 305; 304, 306; 305, identifier:os; 306, identifier:path; 307, identifier:join; 308, argument_list; 308, 309; 308, 310; 309, identifier:out_folder; 310, identifier:out_rel; 311, if_statement; 311, 312; 311, 323; 311, 332; 312, boolean_operator:or; 312, 313; 312, 316; 313, comparison_operator:in; 313, 314; 313, 315; 314, identifier:in_path; 315, identifier:preserve; 316, not_operator; 316, 317; 317, call; 317, 318; 317, 321; 318, attribute; 318, 319; 318, 320; 319, identifier:in_path; 320, identifier:endswith; 321, argument_list; 321, 322; 322, string:".tpl"; 323, block; 323, 324; 324, expression_statement; 324, 325; 325, call; 325, 326; 325, 329; 326, attribute; 326, 327; 326, 328; 327, identifier:shutil; 328, identifier:copyfile; 329, argument_list; 329, 330; 329, 331; 330, identifier:in_abspath; 331, identifier:out_path; 332, else_clause; 332, 333; 332, 334; 332, 335; 333, comment; 334, comment; 335, block; 335, 336; 335, 358; 336, expression_statement; 336, 337; 337, assignment; 337, 338; 337, 339; 338, identifier:in_template_path; 339, call; 339, 340; 339, 351; 340, attribute; 340, 341; 340, 350; 341, call; 341, 342; 341, 347; 342, attribute; 342, 343; 342, 346; 343, attribute; 343, 344; 343, 345; 344, identifier:os; 345, identifier:path; 346, identifier:join; 347, argument_list; 347, 348; 347, 349; 348, identifier:template_folder; 349, identifier:in_path; 350, identifier:replace; 351, argument_list; 351, 352; 351, 357; 352, attribute; 352, 353; 352, 356; 353, attribute; 353, 354; 353, 355; 354, identifier:os; 355, identifier:path; 356, identifier:sep; 357, string:'/'; 358, expression_statement; 358, 359; 359, call; 359, 360; 359, 361; 360, identifier:render_template; 361, argument_list; 361, 362; 361, 363; 361, 364; 362, identifier:in_template_path; 363, identifier:info; 364, keyword_argument; 364, 365; 364, 366; 365, identifier:out_path; 366, identifier:out_path; 367, return_statement; 367, 368; 368, expression_list; 368, 369; 368, 370; 369, identifier:file_map; 370, identifier:create_dirs | def render_recursive_template(template_folder, info, out_folder, preserve=None, dry_run=False):
"""Copy a directory tree rendering all templates found within.
This function inspects all of the files in template_folder recursively. If
any file ends .tpl, it is rendered using render_template and the .tpl
suffix is removed. All other files are copied without modification.
out_folder is not cleaned before rendering so you must delete its contents
yourself if you want that behavior.
If you just want to see all of the file paths that would be generated,
call with dry_run=True. This will not render anything but just inspect
what would be generated.
Args:
template_folder (str): A relative path from config/templates with the
folder that should be rendered recursively.
info (dict): A dictionary of variables to be substituted into any
templates found in template_folder.
out_folder (str): The path to the output folder where the template will
be generated.
dry_run (bool): Whether to actually render output files or just return
the files that would be generated.
preserve (list of str): A list of file names relative to the start of the
template folder that we are rendering that end in .tpl but should not
be rendered and should not have their .tpl suffix removed. This allows
you to partially render a template so that you can render a specific
file later.
Returns:
dict, list: The dict is map of output file path (relative to
out_folder) to the absolute path of the input file that it depends
on. This result is suitable for using in a dependency graph like
SCons. The list is a list of all of the directories that would need
to be created to hold these files (not including out_folder).
"""
if isinstance(preserve, str):
raise ArgumentError("You must pass a list of strings to preserve, not a string", preserve=preserve)
if preserve is None:
preserve = []
preserve = set(preserve)
template_dir = resource_path('templates', expect='folder')
indir = os.path.join(template_dir, template_folder)
if not os.path.exists(indir):
raise ArgumentError("Input template folder for recursive template not found",
template_folder=template_folder, absolute_path=indir)
elif not os.path.isdir(indir):
raise ArgumentError("Input template folder is not a directory",
template_folder=template_folder, absolute_path=indir)
create_dirs = []
file_map = {}
# Walk over all input files
for dirpath, dirs, files in os.walk(indir):
for file in files:
in_abspath = os.path.abspath(os.path.join(dirpath, file))
in_path = os.path.relpath(os.path.join(dirpath, file), start=indir)
if file.endswith(".tpl") and not in_path in preserve:
out_path = in_path[:-4]
else:
out_path = in_path
file_map[out_path] = (in_path, in_abspath)
for folder in dirs:
dir_path = os.path.relpath(os.path.join(dirpath, folder), start=indir)
create_dirs.append(dir_path)
# Actually render / copy all files if we are not doing a dry run
if not dry_run:
for folder in create_dirs:
out_path = os.path.join(out_folder, folder)
if not os.path.isdir(out_path):
os.makedirs(out_path)
for out_rel, (in_path, in_abspath) in file_map.items():
out_path = os.path.join(out_folder, out_rel)
if in_path in preserve or not in_path.endswith(".tpl"):
shutil.copyfile(in_abspath, out_path)
else:
# jinja needs to have unix path separators regardless of the platform and a relative path
# from the templates base directory
in_template_path = os.path.join(template_folder, in_path).replace(os.path.sep, '/')
render_template(in_template_path, info, out_path=out_path)
return file_map, create_dirs |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:Update; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:env; 6, default_parameter; 6, 7; 6, 8; 7, identifier:args; 8, None; 9, block; 9, 10; 9, 12; 9, 16; 9, 17; 9, 41; 9, 42; 9, 141; 9, 142; 9, 153; 9, 212; 9, 213; 9, 214; 9, 238; 9, 239; 9, 324; 9, 325; 10, expression_statement; 10, 11; 11, comment; 12, expression_statement; 12, 13; 13, assignment; 13, 14; 13, 15; 14, identifier:values; 15, dictionary; 16, comment; 17, for_statement; 17, 18; 17, 19; 17, 22; 18, identifier:option; 19, attribute; 19, 20; 19, 21; 20, identifier:self; 21, identifier:options; 22, block; 22, 23; 23, if_statement; 23, 24; 23, 30; 24, not_operator; 24, 25; 25, comparison_operator:is; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:option; 28, identifier:default; 29, None; 30, block; 30, 31; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 38; 33, subscript; 33, 34; 33, 35; 34, identifier:values; 35, attribute; 35, 36; 35, 37; 36, identifier:option; 37, identifier:key; 38, attribute; 38, 39; 38, 40; 39, identifier:option; 40, identifier:default; 41, comment; 42, for_statement; 42, 43; 42, 44; 42, 47; 43, identifier:filename; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:files; 47, block; 47, 48; 48, if_statement; 48, 49; 48, 57; 49, call; 49, 50; 49, 55; 50, attribute; 50, 51; 50, 54; 51, attribute; 51, 52; 51, 53; 52, identifier:os; 53, identifier:path; 54, identifier:exists; 55, argument_list; 55, 56; 56, identifier:filename; 57, block; 57, 58; 57, 78; 57, 91; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:dir; 61, subscript; 61, 62; 61, 77; 62, call; 62, 63; 62, 68; 63, attribute; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:os; 66, identifier:path; 67, identifier:split; 68, argument_list; 68, 69; 69, call; 69, 70; 69, 75; 70, attribute; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:os; 73, identifier:path; 74, identifier:abspath; 75, argument_list; 75, 76; 76, identifier:filename; 77, integer:0; 78, if_statement; 78, 79; 78, 80; 79, identifier:dir; 80, block; 80, 81; 81, expression_statement; 81, 82; 82, call; 82, 83; 82, 88; 83, attribute; 83, 84; 83, 87; 84, attribute; 84, 85; 84, 86; 85, identifier:sys; 86, identifier:path; 87, identifier:insert; 88, argument_list; 88, 89; 88, 90; 89, integer:0; 90, identifier:dir; 91, try_statement; 91, 92; 91, 126; 92, block; 92, 93; 92, 99; 92, 119; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 98; 95, subscript; 95, 96; 95, 97; 96, identifier:values; 97, string:'__name__'; 98, identifier:filename; 99, with_statement; 99, 100; 99, 110; 100, with_clause; 100, 101; 101, with_item; 101, 102; 102, as_pattern; 102, 103; 102, 108; 103, call; 103, 104; 103, 105; 104, identifier:open; 105, argument_list; 105, 106; 105, 107; 106, identifier:filename; 107, string:'r'; 108, as_pattern_target; 108, 109; 109, identifier:f; 110, block; 110, 111; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:contents; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:f; 117, identifier:read; 118, argument_list; 119, expression_statement; 119, 120; 120, call; 120, 121; 120, 122; 121, identifier:exec; 122, argument_list; 122, 123; 122, 124; 122, 125; 123, identifier:contents; 124, dictionary; 125, identifier:values; 126, finally_clause; 126, 127; 127, block; 127, 128; 127, 137; 128, if_statement; 128, 129; 128, 130; 129, identifier:dir; 130, block; 130, 131; 131, delete_statement; 131, 132; 132, subscript; 132, 133; 132, 136; 133, attribute; 133, 134; 133, 135; 134, identifier:sys; 135, identifier:path; 136, integer:0; 137, delete_statement; 137, 138; 138, subscript; 138, 139; 138, 140; 139, identifier:values; 140, string:'__name__'; 141, comment; 142, if_statement; 142, 143; 142, 146; 143, comparison_operator:is; 143, 144; 143, 145; 144, identifier:args; 145, None; 146, block; 146, 147; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:args; 150, attribute; 150, 151; 150, 152; 151, identifier:self; 152, identifier:args; 153, for_statement; 153, 154; 153, 157; 153, 162; 154, pattern_list; 154, 155; 154, 156; 155, identifier:arg; 156, identifier:value; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:args; 160, identifier:items; 161, argument_list; 162, block; 162, 163; 162, 167; 162, 200; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:added; 166, False; 167, for_statement; 167, 168; 167, 169; 167, 172; 168, identifier:option; 169, attribute; 169, 170; 169, 171; 170, identifier:self; 171, identifier:options; 172, block; 172, 173; 173, if_statement; 173, 174; 173, 187; 174, comparison_operator:in; 174, 175; 174, 176; 175, identifier:arg; 176, binary_operator:+; 176, 177; 176, 183; 177, call; 177, 178; 177, 179; 178, identifier:list; 179, argument_list; 179, 180; 180, attribute; 180, 181; 180, 182; 181, identifier:option; 182, identifier:aliases; 183, list:[ option.key ]; 183, 184; 184, attribute; 184, 185; 184, 186; 185, identifier:option; 186, identifier:key; 187, block; 187, 188; 187, 196; 188, expression_statement; 188, 189; 189, assignment; 189, 190; 189, 195; 190, subscript; 190, 191; 190, 192; 191, identifier:values; 192, attribute; 192, 193; 192, 194; 193, identifier:option; 194, identifier:key; 195, identifier:value; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 199; 198, identifier:added; 199, True; 200, if_statement; 200, 201; 200, 203; 201, not_operator; 201, 202; 202, identifier:added; 203, block; 203, 204; 204, expression_statement; 204, 205; 205, assignment; 205, 206; 205, 211; 206, subscript; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:self; 209, identifier:unknown; 210, identifier:arg; 211, identifier:value; 212, comment; 213, comment; 214, for_statement; 214, 215; 214, 216; 214, 219; 215, identifier:option; 216, attribute; 216, 217; 216, 218; 217, identifier:self; 218, identifier:options; 219, block; 219, 220; 220, try_statement; 220, 221; 220, 234; 221, block; 221, 222; 222, expression_statement; 222, 223; 223, assignment; 223, 224; 223, 229; 224, subscript; 224, 225; 224, 226; 225, identifier:env; 226, attribute; 226, 227; 226, 228; 227, identifier:option; 228, identifier:key; 229, subscript; 229, 230; 229, 231; 230, identifier:values; 231, attribute; 231, 232; 231, 233; 232, identifier:option; 233, identifier:key; 234, except_clause; 234, 235; 234, 236; 235, identifier:KeyError; 236, block; 236, 237; 237, pass_statement; 238, comment; 239, for_statement; 239, 240; 239, 241; 239, 244; 240, identifier:option; 241, attribute; 241, 242; 241, 243; 242, identifier:self; 243, identifier:options; 244, block; 244, 245; 245, if_statement; 245, 246; 245, 255; 246, boolean_operator:and; 246, 247; 246, 250; 247, attribute; 247, 248; 247, 249; 248, identifier:option; 249, identifier:converter; 250, comparison_operator:in; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:option; 253, identifier:key; 254, identifier:values; 255, block; 255, 256; 255, 269; 256, expression_statement; 256, 257; 257, assignment; 257, 258; 257, 259; 258, identifier:value; 259, call; 259, 260; 259, 263; 260, attribute; 260, 261; 260, 262; 261, identifier:env; 262, identifier:subst; 263, argument_list; 263, 264; 264, binary_operator:%; 264, 265; 264, 266; 265, string:'${%s}'; 266, attribute; 266, 267; 266, 268; 267, identifier:option; 268, identifier:key; 269, try_statement; 269, 270; 269, 303; 270, block; 270, 271; 271, try_statement; 271, 272; 271, 286; 272, block; 272, 273; 273, expression_statement; 273, 274; 274, assignment; 274, 275; 274, 280; 275, subscript; 275, 276; 275, 277; 276, identifier:env; 277, attribute; 277, 278; 277, 279; 278, identifier:option; 279, identifier:key; 280, call; 280, 281; 280, 284; 281, attribute; 281, 282; 281, 283; 282, identifier:option; 283, identifier:converter; 284, argument_list; 284, 285; 285, identifier:value; 286, except_clause; 286, 287; 286, 288; 287, identifier:TypeError; 288, block; 288, 289; 289, expression_statement; 289, 290; 290, assignment; 290, 291; 290, 296; 291, subscript; 291, 292; 291, 293; 292, identifier:env; 293, attribute; 293, 294; 293, 295; 294, identifier:option; 295, identifier:key; 296, call; 296, 297; 296, 300; 297, attribute; 297, 298; 297, 299; 298, identifier:option; 299, identifier:converter; 300, argument_list; 300, 301; 300, 302; 301, identifier:value; 302, identifier:env; 303, except_clause; 303, 304; 303, 308; 304, as_pattern; 304, 305; 304, 306; 305, identifier:ValueError; 306, as_pattern_target; 306, 307; 307, identifier:x; 308, block; 308, 309; 309, raise_statement; 309, 310; 310, call; 310, 311; 310, 316; 311, attribute; 311, 312; 311, 315; 312, attribute; 312, 313; 312, 314; 313, identifier:SCons; 314, identifier:Errors; 315, identifier:UserError; 316, argument_list; 316, 317; 317, binary_operator:%; 317, 318; 317, 319; 318, string:'Error converting option: %s\n%s'; 319, tuple; 319, 320; 319, 323; 320, attribute; 320, 321; 320, 322; 321, identifier:option; 322, identifier:key; 323, identifier:x; 324, comment; 325, for_statement; 325, 326; 325, 327; 325, 330; 326, identifier:option; 327, attribute; 327, 328; 327, 329; 328, identifier:self; 329, identifier:options; 330, block; 330, 331; 331, if_statement; 331, 332; 331, 341; 332, boolean_operator:and; 332, 333; 332, 336; 333, attribute; 333, 334; 333, 335; 334, identifier:option; 335, identifier:validator; 336, comparison_operator:in; 336, 337; 336, 340; 337, attribute; 337, 338; 337, 339; 338, identifier:option; 339, identifier:key; 340, identifier:values; 341, block; 341, 342; 342, expression_statement; 342, 343; 343, call; 343, 344; 343, 347; 344, attribute; 344, 345; 344, 346; 345, identifier:option; 346, identifier:validator; 347, argument_list; 347, 348; 347, 351; 347, 361; 348, attribute; 348, 349; 348, 350; 349, identifier:option; 350, identifier:key; 351, call; 351, 352; 351, 355; 352, attribute; 352, 353; 352, 354; 353, identifier:env; 354, identifier:subst; 355, argument_list; 355, 356; 356, binary_operator:%; 356, 357; 356, 358; 357, string:'${%s}'; 358, attribute; 358, 359; 358, 360; 359, identifier:option; 360, identifier:key; 361, identifier:env | def Update(self, env, args=None):
"""
Update an environment with the option variables.
env - the environment to update.
"""
values = {}
# first set the defaults:
for option in self.options:
if not option.default is None:
values[option.key] = option.default
# next set the value specified in the options file
for filename in self.files:
if os.path.exists(filename):
dir = os.path.split(os.path.abspath(filename))[0]
if dir:
sys.path.insert(0, dir)
try:
values['__name__'] = filename
with open(filename, 'r') as f:
contents = f.read()
exec(contents, {}, values)
finally:
if dir:
del sys.path[0]
del values['__name__']
# set the values specified on the command line
if args is None:
args = self.args
for arg, value in args.items():
added = False
for option in self.options:
if arg in list(option.aliases) + [ option.key ]:
values[option.key] = value
added = True
if not added:
self.unknown[arg] = value
# put the variables in the environment:
# (don't copy over variables that are not declared as options)
for option in self.options:
try:
env[option.key] = values[option.key]
except KeyError:
pass
# Call the convert functions:
for option in self.options:
if option.converter and option.key in values:
value = env.subst('${%s}'%option.key)
try:
try:
env[option.key] = option.converter(value)
except TypeError:
env[option.key] = option.converter(value, env)
except ValueError as x:
raise SCons.Errors.UserError('Error converting option: %s\n%s'%(option.key, x))
# Finally validate the values:
for option in self.options:
if option.validator and option.key in values:
option.validator(option.key, env.subst('${%s}'%option.key), env) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:GenerateHelpText; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:env; 6, default_parameter; 6, 7; 6, 8; 7, identifier:sort; 8, None; 9, block; 9, 10; 9, 12; 9, 75; 9, 132; 9, 146; 10, expression_statement; 10, 11; 11, comment; 12, if_statement; 12, 13; 12, 17; 12, 45; 12, 67; 13, call; 13, 14; 13, 15; 14, identifier:callable; 15, argument_list; 15, 16; 16, identifier:sort; 17, block; 17, 18; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:options; 21, call; 21, 22; 21, 23; 22, identifier:sorted; 23, argument_list; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:options; 27, keyword_argument; 27, 28; 27, 29; 28, identifier:key; 29, call; 29, 30; 29, 31; 30, identifier:cmp_to_key; 31, argument_list; 31, 32; 32, lambda; 32, 33; 32, 36; 33, lambda_parameters; 33, 34; 33, 35; 34, identifier:x; 35, identifier:y; 36, call; 36, 37; 36, 38; 37, identifier:sort; 38, argument_list; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:x; 41, identifier:key; 42, attribute; 42, 43; 42, 44; 43, identifier:y; 44, identifier:key; 45, elif_clause; 45, 46; 45, 49; 46, comparison_operator:is; 46, 47; 46, 48; 47, identifier:sort; 48, True; 49, block; 49, 50; 50, expression_statement; 50, 51; 51, assignment; 51, 52; 51, 53; 52, identifier:options; 53, call; 53, 54; 53, 55; 54, identifier:sorted; 55, argument_list; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:self; 58, identifier:options; 59, keyword_argument; 59, 60; 59, 61; 60, identifier:key; 61, lambda; 61, 62; 61, 64; 62, lambda_parameters; 62, 63; 63, identifier:x; 64, attribute; 64, 65; 64, 66; 65, identifier:x; 66, identifier:key; 67, else_clause; 67, 68; 68, block; 68, 69; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:options; 72, attribute; 72, 73; 72, 74; 73, identifier:self; 74, identifier:options; 75, function_definition; 75, 76; 75, 77; 75, 85; 76, function_name:format; 77, parameters; 77, 78; 77, 79; 77, 82; 78, identifier:opt; 79, default_parameter; 79, 80; 79, 81; 80, identifier:self; 81, identifier:self; 82, default_parameter; 82, 83; 82, 84; 83, identifier:env; 84, identifier:env; 85, block; 85, 86; 85, 112; 86, if_statement; 86, 87; 86, 92; 86, 106; 87, comparison_operator:in; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:opt; 90, identifier:key; 91, identifier:env; 92, block; 92, 93; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:actual; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:env; 99, identifier:subst; 100, argument_list; 100, 101; 101, binary_operator:%; 101, 102; 101, 103; 102, string:'${%s}'; 103, attribute; 103, 104; 103, 105; 104, identifier:opt; 105, identifier:key; 106, else_clause; 106, 107; 107, block; 107, 108; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 111; 110, identifier:actual; 111, None; 112, return_statement; 112, 113; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:self; 116, identifier:FormatVariableHelpText; 117, argument_list; 117, 118; 117, 119; 117, 122; 117, 125; 117, 128; 117, 129; 118, identifier:env; 119, attribute; 119, 120; 119, 121; 120, identifier:opt; 121, identifier:key; 122, attribute; 122, 123; 122, 124; 123, identifier:opt; 124, identifier:help; 125, attribute; 125, 126; 125, 127; 126, identifier:opt; 127, identifier:default; 128, identifier:actual; 129, attribute; 129, 130; 129, 131; 130, identifier:opt; 131, identifier:aliases; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:lines; 135, list_comprehension; 135, 136; 135, 137; 135, 144; 136, identifier:_f; 137, for_in_clause; 137, 138; 137, 139; 138, identifier:_f; 139, call; 139, 140; 139, 141; 140, identifier:map; 141, argument_list; 141, 142; 141, 143; 142, identifier:format; 143, identifier:options; 144, if_clause; 144, 145; 145, identifier:_f; 146, return_statement; 146, 147; 147, call; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, string:''; 150, identifier:join; 151, argument_list; 151, 152; 152, identifier:lines | def GenerateHelpText(self, env, sort=None):
"""
Generate the help text for the options.
env - an environment that is used to get the current values
of the options.
cmp - Either a function as follows: The specific sort function should take two arguments and return -1, 0 or 1
or a boolean to indicate if it should be sorted.
"""
if callable(sort):
options = sorted(self.options, key=cmp_to_key(lambda x,y: sort(x.key,y.key)))
elif sort is True:
options = sorted(self.options, key=lambda x: x.key)
else:
options = self.options
def format(opt, self=self, env=env):
if opt.key in env:
actual = env.subst('${%s}' % opt.key)
else:
actual = None
return self.FormatVariableHelpText(env, opt.key, opt.help, opt.default, actual, opt.aliases)
lines = [_f for _f in map(format, options) if _f]
return ''.join(lines) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 2, function_name:render_tree; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 13; 4, identifier:root; 5, identifier:child_func; 6, default_parameter; 6, 7; 6, 8; 7, identifier:prune; 8, integer:0; 9, default_parameter; 9, 10; 9, 11; 10, identifier:margin; 11, list:[0]; 11, 12; 12, integer:0; 13, default_parameter; 13, 14; 13, 15; 14, identifier:visited; 15, None; 16, block; 16, 17; 16, 19; 16, 26; 16, 27; 16, 36; 16, 43; 16, 47; 16, 73; 16, 86; 16, 96; 16, 109; 16, 115; 16, 160; 17, expression_statement; 17, 18; 18, comment; 19, expression_statement; 19, 20; 20, assignment; 20, 21; 20, 22; 21, identifier:rname; 22, call; 22, 23; 22, 24; 23, identifier:str; 24, argument_list; 24, 25; 25, identifier:root; 26, comment; 27, if_statement; 27, 28; 27, 31; 28, comparison_operator:is; 28, 29; 28, 30; 29, identifier:visited; 30, None; 31, block; 31, 32; 32, expression_statement; 32, 33; 33, assignment; 33, 34; 33, 35; 34, identifier:visited; 35, dictionary; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:children; 39, call; 39, 40; 39, 41; 40, identifier:child_func; 41, argument_list; 41, 42; 42, identifier:root; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:retval; 46, string:""; 47, for_statement; 47, 48; 47, 49; 47, 55; 48, identifier:pipe; 49, subscript; 49, 50; 49, 51; 50, identifier:margin; 51, slice; 51, 52; 51, 53; 52, colon; 53, unary_operator:-; 53, 54; 54, integer:1; 55, block; 55, 56; 56, if_statement; 56, 57; 56, 58; 56, 65; 57, identifier:pipe; 58, block; 58, 59; 59, expression_statement; 59, 60; 60, assignment; 60, 61; 60, 62; 61, identifier:retval; 62, binary_operator:+; 62, 63; 62, 64; 63, identifier:retval; 64, string:"| "; 65, else_clause; 65, 66; 66, block; 66, 67; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:retval; 70, binary_operator:+; 70, 71; 70, 72; 71, identifier:retval; 72, string:" "; 73, if_statement; 73, 74; 73, 77; 74, comparison_operator:in; 74, 75; 74, 76; 75, identifier:rname; 76, identifier:visited; 77, block; 77, 78; 78, return_statement; 78, 79; 79, binary_operator:+; 79, 80; 79, 85; 80, binary_operator:+; 80, 81; 80, 84; 81, binary_operator:+; 81, 82; 81, 83; 82, identifier:retval; 83, string:"+-["; 84, identifier:rname; 85, string:"]\n"; 86, expression_statement; 86, 87; 87, assignment; 87, 88; 87, 89; 88, identifier:retval; 89, binary_operator:+; 89, 90; 89, 95; 90, binary_operator:+; 90, 91; 90, 94; 91, binary_operator:+; 91, 92; 91, 93; 92, identifier:retval; 93, string:"+-"; 94, identifier:rname; 95, string:"\n"; 96, if_statement; 96, 97; 96, 99; 97, not_operator; 97, 98; 98, identifier:prune; 99, block; 99, 100; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:visited; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:copy; 106, identifier:copy; 107, argument_list; 107, 108; 108, identifier:visited; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 114; 111, subscript; 111, 112; 111, 113; 112, identifier:visited; 113, identifier:rname; 114, integer:1; 115, for_statement; 115, 116; 115, 117; 115, 124; 116, identifier:i; 117, call; 117, 118; 117, 119; 118, identifier:range; 119, argument_list; 119, 120; 120, call; 120, 121; 120, 122; 121, identifier:len; 122, argument_list; 122, 123; 123, identifier:children; 124, block; 124, 125; 124, 139; 124, 154; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:margin; 129, identifier:append; 130, argument_list; 130, 131; 131, comparison_operator:<; 131, 132; 131, 133; 132, identifier:i; 133, binary_operator:-; 133, 134; 133, 138; 134, call; 134, 135; 134, 136; 135, identifier:len; 136, argument_list; 136, 137; 137, identifier:children; 138, integer:1; 139, expression_statement; 139, 140; 140, assignment; 140, 141; 140, 142; 141, identifier:retval; 142, binary_operator:+; 142, 143; 142, 144; 143, identifier:retval; 144, call; 144, 145; 144, 146; 145, identifier:render_tree; 146, argument_list; 146, 147; 146, 150; 146, 151; 146, 152; 146, 153; 147, subscript; 147, 148; 147, 149; 148, identifier:children; 149, identifier:i; 150, identifier:child_func; 151, identifier:prune; 152, identifier:margin; 153, identifier:visited; 154, expression_statement; 154, 155; 155, call; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:margin; 158, identifier:pop; 159, argument_list; 160, return_statement; 160, 161; 161, identifier:retval | def render_tree(root, child_func, prune=0, margin=[0], visited=None):
"""
Render a tree of nodes into an ASCII tree view.
:Parameters:
- `root`: the root node of the tree
- `child_func`: the function called to get the children of a node
- `prune`: don't visit the same node twice
- `margin`: the format of the left margin to use for children of root. 1 results in a pipe, and 0 results in no pipe.
- `visited`: a dictionary of visited nodes in the current branch if not prune, or in the whole tree if prune.
"""
rname = str(root)
# Initialize 'visited' dict, if required
if visited is None:
visited = {}
children = child_func(root)
retval = ""
for pipe in margin[:-1]:
if pipe:
retval = retval + "| "
else:
retval = retval + " "
if rname in visited:
return retval + "+-[" + rname + "]\n"
retval = retval + "+-" + rname + "\n"
if not prune:
visited = copy.copy(visited)
visited[rname] = 1
for i in range(len(children)):
margin.append(i < len(children)-1)
retval = retval + render_tree(children[i], child_func, prune, margin, visited)
margin.pop()
return retval |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 19; 2, function_name:print_tree; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 16; 4, identifier:root; 5, identifier:child_func; 6, default_parameter; 6, 7; 6, 8; 7, identifier:prune; 8, integer:0; 9, default_parameter; 9, 10; 9, 11; 10, identifier:showtags; 11, integer:0; 12, default_parameter; 12, 13; 12, 14; 13, identifier:margin; 14, list:[0]; 14, 15; 15, integer:0; 16, default_parameter; 16, 17; 16, 18; 17, identifier:visited; 18, None; 19, block; 19, 20; 19, 22; 19, 29; 19, 30; 19, 39; 19, 257; 19, 268; 19, 284; 19, 291; 19, 324; 19, 346; 19, 352; 20, expression_statement; 20, 21; 21, comment; 22, expression_statement; 22, 23; 23, assignment; 23, 24; 23, 25; 24, identifier:rname; 25, call; 25, 26; 25, 27; 26, identifier:str; 27, argument_list; 27, 28; 28, identifier:root; 29, comment; 30, if_statement; 30, 31; 30, 34; 31, comparison_operator:is; 31, 32; 31, 33; 32, identifier:visited; 33, None; 34, block; 34, 35; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:visited; 38, dictionary; 39, if_statement; 39, 40; 39, 41; 39, 251; 40, identifier:showtags; 41, block; 41, 42; 41, 81; 41, 86; 41, 102; 41, 125; 41, 158; 41, 172; 41, 186; 41, 200; 41, 216; 41, 230; 41, 244; 42, if_statement; 42, 43; 42, 46; 43, comparison_operator:==; 43, 44; 43, 45; 44, identifier:showtags; 45, integer:2; 46, block; 46, 47; 46, 72; 47, expression_statement; 47, 48; 48, assignment; 48, 49; 48, 50; 49, identifier:legend; 50, parenthesized_expression; 50, 51; 51, binary_operator:+; 51, 52; 51, 71; 52, binary_operator:+; 52, 53; 52, 70; 53, binary_operator:+; 53, 54; 53, 69; 54, binary_operator:+; 54, 55; 54, 68; 55, binary_operator:+; 55, 56; 55, 67; 56, binary_operator:+; 56, 57; 56, 66; 57, binary_operator:+; 57, 58; 57, 65; 58, binary_operator:+; 58, 59; 58, 64; 59, binary_operator:+; 59, 60; 59, 63; 60, binary_operator:+; 60, 61; 60, 62; 61, string:' E = exists\n'; 62, string:' R = exists in repository only\n'; 63, string:' b = implicit builder\n'; 64, string:' B = explicit builder\n'; 65, string:' S = side effect\n'; 66, string:' P = precious\n'; 67, string:' A = always build\n'; 68, string:' C = current\n'; 69, string:' N = no clean\n'; 70, string:' H = no cache\n'; 71, string:'\n'; 72, expression_statement; 72, 73; 73, call; 73, 74; 73, 79; 74, attribute; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:sys; 77, identifier:stdout; 78, identifier:write; 79, argument_list; 79, 80; 80, identifier:legend; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:tags; 84, list:['[']; 84, 85; 85, string:'['; 86, expression_statement; 86, 87; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:tags; 90, identifier:append; 91, argument_list; 91, 92; 92, subscript; 92, 93; 92, 94; 93, string:' E'; 94, call; 94, 95; 94, 96; 95, identifier:IDX; 96, argument_list; 96, 97; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:root; 100, identifier:exists; 101, argument_list; 102, expression_statement; 102, 103; 103, call; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:tags; 106, identifier:append; 107, argument_list; 107, 108; 108, subscript; 108, 109; 108, 110; 109, string:' R'; 110, call; 110, 111; 110, 112; 111, identifier:IDX; 112, argument_list; 112, 113; 113, boolean_operator:and; 113, 114; 113, 119; 114, call; 114, 115; 114, 118; 115, attribute; 115, 116; 115, 117; 116, identifier:root; 117, identifier:rexists; 118, argument_list; 119, not_operator; 119, 120; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:root; 123, identifier:exists; 124, argument_list; 125, expression_statement; 125, 126; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:tags; 129, identifier:append; 130, argument_list; 130, 131; 131, subscript; 131, 132; 131, 133; 132, string:' BbB'; 133, binary_operator:+; 133, 134; 133, 146; 134, subscript; 134, 135; 134, 138; 135, list:[0,1]; 135, 136; 135, 137; 136, integer:0; 137, integer:1; 138, call; 138, 139; 138, 140; 139, identifier:IDX; 140, argument_list; 140, 141; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:root; 144, identifier:has_explicit_builder; 145, argument_list; 146, subscript; 146, 147; 146, 150; 147, list:[0,2]; 147, 148; 147, 149; 148, integer:0; 149, integer:2; 150, call; 150, 151; 150, 152; 151, identifier:IDX; 152, argument_list; 152, 153; 153, call; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:root; 156, identifier:has_builder; 157, argument_list; 158, expression_statement; 158, 159; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:tags; 162, identifier:append; 163, argument_list; 163, 164; 164, subscript; 164, 165; 164, 166; 165, string:' S'; 166, call; 166, 167; 166, 168; 167, identifier:IDX; 168, argument_list; 168, 169; 169, attribute; 169, 170; 169, 171; 170, identifier:root; 171, identifier:side_effect; 172, expression_statement; 172, 173; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:tags; 176, identifier:append; 177, argument_list; 177, 178; 178, subscript; 178, 179; 178, 180; 179, string:' P'; 180, call; 180, 181; 180, 182; 181, identifier:IDX; 182, argument_list; 182, 183; 183, attribute; 183, 184; 183, 185; 184, identifier:root; 185, identifier:precious; 186, expression_statement; 186, 187; 187, call; 187, 188; 187, 191; 188, attribute; 188, 189; 188, 190; 189, identifier:tags; 190, identifier:append; 191, argument_list; 191, 192; 192, subscript; 192, 193; 192, 194; 193, string:' A'; 194, call; 194, 195; 194, 196; 195, identifier:IDX; 196, argument_list; 196, 197; 197, attribute; 197, 198; 197, 199; 198, identifier:root; 199, identifier:always_build; 200, expression_statement; 200, 201; 201, call; 201, 202; 201, 205; 202, attribute; 202, 203; 202, 204; 203, identifier:tags; 204, identifier:append; 205, argument_list; 205, 206; 206, subscript; 206, 207; 206, 208; 207, string:' C'; 208, call; 208, 209; 208, 210; 209, identifier:IDX; 210, argument_list; 210, 211; 211, call; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:root; 214, identifier:is_up_to_date; 215, argument_list; 216, expression_statement; 216, 217; 217, call; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:tags; 220, identifier:append; 221, argument_list; 221, 222; 222, subscript; 222, 223; 222, 224; 223, string:' N'; 224, call; 224, 225; 224, 226; 225, identifier:IDX; 226, argument_list; 226, 227; 227, attribute; 227, 228; 227, 229; 228, identifier:root; 229, identifier:noclean; 230, expression_statement; 230, 231; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:tags; 234, identifier:append; 235, argument_list; 235, 236; 236, subscript; 236, 237; 236, 238; 237, string:' H'; 238, call; 238, 239; 238, 240; 239, identifier:IDX; 240, argument_list; 240, 241; 241, attribute; 241, 242; 241, 243; 242, identifier:root; 243, identifier:nocache; 244, expression_statement; 244, 245; 245, call; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:tags; 248, identifier:append; 249, argument_list; 249, 250; 250, string:']'; 251, else_clause; 251, 252; 252, block; 252, 253; 253, expression_statement; 253, 254; 254, assignment; 254, 255; 254, 256; 255, identifier:tags; 256, list:[]; 257, function_definition; 257, 258; 257, 259; 257, 261; 258, function_name:MMM; 259, parameters; 259, 260; 260, identifier:m; 261, block; 261, 262; 262, return_statement; 262, 263; 263, subscript; 263, 264; 263, 267; 264, list:[" ","| "]; 264, 265; 264, 266; 265, string:" "; 266, string:"| "; 267, identifier:m; 268, expression_statement; 268, 269; 269, assignment; 269, 270; 269, 271; 270, identifier:margins; 271, call; 271, 272; 271, 273; 272, identifier:list; 273, argument_list; 273, 274; 274, call; 274, 275; 274, 276; 275, identifier:map; 276, argument_list; 276, 277; 276, 278; 277, identifier:MMM; 278, subscript; 278, 279; 278, 280; 279, identifier:margin; 280, slice; 280, 281; 280, 282; 281, colon; 282, unary_operator:-; 282, 283; 283, integer:1; 284, expression_statement; 284, 285; 285, assignment; 285, 286; 285, 287; 286, identifier:children; 287, call; 287, 288; 287, 289; 288, identifier:child_func; 289, argument_list; 289, 290; 290, identifier:root; 291, if_statement; 291, 292; 291, 299; 292, boolean_operator:and; 292, 293; 292, 298; 293, boolean_operator:and; 293, 294; 293, 295; 294, identifier:prune; 295, comparison_operator:in; 295, 296; 295, 297; 296, identifier:rname; 297, identifier:visited; 298, identifier:children; 299, block; 299, 300; 299, 323; 300, expression_statement; 300, 301; 301, call; 301, 302; 301, 307; 302, attribute; 302, 303; 302, 306; 303, attribute; 303, 304; 303, 305; 304, identifier:sys; 305, identifier:stdout; 306, identifier:write; 307, argument_list; 307, 308; 308, binary_operator:+; 308, 309; 308, 322; 309, call; 309, 310; 309, 313; 310, attribute; 310, 311; 310, 312; 311, string:''; 312, identifier:join; 313, argument_list; 313, 314; 314, binary_operator:+; 314, 315; 314, 318; 315, binary_operator:+; 315, 316; 315, 317; 316, identifier:tags; 317, identifier:margins; 318, list:['+-[', rname, ']']; 318, 319; 318, 320; 318, 321; 319, string:'+-['; 320, identifier:rname; 321, string:']'; 322, string:'\n'; 323, return_statement; 324, expression_statement; 324, 325; 325, call; 325, 326; 325, 331; 326, attribute; 326, 327; 326, 330; 327, attribute; 327, 328; 327, 329; 328, identifier:sys; 329, identifier:stdout; 330, identifier:write; 331, argument_list; 331, 332; 332, binary_operator:+; 332, 333; 332, 345; 333, call; 333, 334; 333, 337; 334, attribute; 334, 335; 334, 336; 335, string:''; 336, identifier:join; 337, argument_list; 337, 338; 338, binary_operator:+; 338, 339; 338, 342; 339, binary_operator:+; 339, 340; 339, 341; 340, identifier:tags; 341, identifier:margins; 342, list:['+-', rname]; 342, 343; 342, 344; 343, string:'+-'; 344, identifier:rname; 345, string:'\n'; 346, expression_statement; 346, 347; 347, assignment; 347, 348; 347, 351; 348, subscript; 348, 349; 348, 350; 349, identifier:visited; 350, identifier:rname; 351, integer:1; 352, if_statement; 352, 353; 352, 354; 353, identifier:children; 354, block; 354, 355; 354, 362; 354, 369; 354, 388; 354, 395; 354, 408; 355, expression_statement; 355, 356; 356, call; 356, 357; 356, 360; 357, attribute; 357, 358; 357, 359; 358, identifier:margin; 359, identifier:append; 360, argument_list; 360, 361; 361, integer:1; 362, expression_statement; 362, 363; 363, assignment; 363, 364; 363, 365; 364, identifier:idx; 365, call; 365, 366; 365, 367; 366, identifier:IDX; 367, argument_list; 367, 368; 368, identifier:showtags; 369, for_statement; 369, 370; 369, 371; 369, 377; 370, identifier:C; 371, subscript; 371, 372; 371, 373; 372, identifier:children; 373, slice; 373, 374; 373, 375; 374, colon; 375, unary_operator:-; 375, 376; 376, integer:1; 377, block; 377, 378; 378, expression_statement; 378, 379; 379, call; 379, 380; 379, 381; 380, identifier:print_tree; 381, argument_list; 381, 382; 381, 383; 381, 384; 381, 385; 381, 386; 381, 387; 382, identifier:C; 383, identifier:child_func; 384, identifier:prune; 385, identifier:idx; 386, identifier:margin; 387, identifier:visited; 388, expression_statement; 388, 389; 389, assignment; 389, 390; 389, 394; 390, subscript; 390, 391; 390, 392; 391, identifier:margin; 392, unary_operator:-; 392, 393; 393, integer:1; 394, integer:0; 395, expression_statement; 395, 396; 396, call; 396, 397; 396, 398; 397, identifier:print_tree; 398, argument_list; 398, 399; 398, 403; 398, 404; 398, 405; 398, 406; 398, 407; 399, subscript; 399, 400; 399, 401; 400, identifier:children; 401, unary_operator:-; 401, 402; 402, integer:1; 403, identifier:child_func; 404, identifier:prune; 405, identifier:idx; 406, identifier:margin; 407, identifier:visited; 408, expression_statement; 408, 409; 409, call; 409, 410; 409, 413; 410, attribute; 410, 411; 410, 412; 411, identifier:margin; 412, identifier:pop; 413, argument_list | def print_tree(root, child_func, prune=0, showtags=0, margin=[0], visited=None):
"""
Print a tree of nodes. This is like render_tree, except it prints
lines directly instead of creating a string representation in memory,
so that huge trees can be printed.
:Parameters:
- `root` - the root node of the tree
- `child_func` - the function called to get the children of a node
- `prune` - don't visit the same node twice
- `showtags` - print status information to the left of each node line
- `margin` - the format of the left margin to use for children of root. 1 results in a pipe, and 0 results in no pipe.
- `visited` - a dictionary of visited nodes in the current branch if not prune, or in the whole tree if prune.
"""
rname = str(root)
# Initialize 'visited' dict, if required
if visited is None:
visited = {}
if showtags:
if showtags == 2:
legend = (' E = exists\n' +
' R = exists in repository only\n' +
' b = implicit builder\n' +
' B = explicit builder\n' +
' S = side effect\n' +
' P = precious\n' +
' A = always build\n' +
' C = current\n' +
' N = no clean\n' +
' H = no cache\n' +
'\n')
sys.stdout.write(legend)
tags = ['[']
tags.append(' E'[IDX(root.exists())])
tags.append(' R'[IDX(root.rexists() and not root.exists())])
tags.append(' BbB'[[0,1][IDX(root.has_explicit_builder())] +
[0,2][IDX(root.has_builder())]])
tags.append(' S'[IDX(root.side_effect)])
tags.append(' P'[IDX(root.precious)])
tags.append(' A'[IDX(root.always_build)])
tags.append(' C'[IDX(root.is_up_to_date())])
tags.append(' N'[IDX(root.noclean)])
tags.append(' H'[IDX(root.nocache)])
tags.append(']')
else:
tags = []
def MMM(m):
return [" ","| "][m]
margins = list(map(MMM, margin[:-1]))
children = child_func(root)
if prune and rname in visited and children:
sys.stdout.write(''.join(tags + margins + ['+-[', rname, ']']) + '\n')
return
sys.stdout.write(''.join(tags + margins + ['+-', rname]) + '\n')
visited[rname] = 1
if children:
margin.append(1)
idx = IDX(showtags)
for C in children[:-1]:
print_tree(C, child_func, prune, idx, margin, visited)
margin[-1] = 0
print_tree(children[-1], child_func, prune, idx, margin, visited)
margin.pop() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:unique; 3, parameters; 3, 4; 4, identifier:s; 5, block; 5, 6; 5, 8; 5, 15; 5, 22; 5, 23; 5, 24; 5, 25; 5, 26; 5, 30; 5, 58; 5, 60; 5, 61; 5, 62; 5, 63; 5, 64; 5, 65; 5, 66; 5, 67; 5, 139; 5, 141; 5, 142; 5, 146; 5, 162; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:n; 11, call; 11, 12; 11, 13; 12, identifier:len; 13, argument_list; 13, 14; 14, identifier:s; 15, if_statement; 15, 16; 15, 19; 16, comparison_operator:==; 16, 17; 16, 18; 17, identifier:n; 18, integer:0; 19, block; 19, 20; 20, return_statement; 20, 21; 21, list:[]; 22, comment; 23, comment; 24, comment; 25, comment; 26, expression_statement; 26, 27; 27, assignment; 27, 28; 27, 29; 28, identifier:u; 29, dictionary; 30, try_statement; 30, 31; 30, 42; 30, 47; 31, block; 31, 32; 32, for_statement; 32, 33; 32, 34; 32, 35; 33, identifier:x; 34, identifier:s; 35, block; 35, 36; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 41; 38, subscript; 38, 39; 38, 40; 39, identifier:u; 40, identifier:x; 41, integer:1; 42, except_clause; 42, 43; 42, 44; 43, identifier:TypeError; 44, block; 44, 45; 44, 46; 45, pass_statement; 46, comment; 47, else_clause; 47, 48; 48, block; 48, 49; 49, return_statement; 49, 50; 50, call; 50, 51; 50, 52; 51, identifier:list; 52, argument_list; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:u; 56, identifier:keys; 57, argument_list; 58, delete_statement; 58, 59; 59, identifier:u; 60, comment; 61, comment; 62, comment; 63, comment; 64, comment; 65, comment; 66, comment; 67, try_statement; 67, 68; 67, 76; 67, 81; 68, block; 68, 69; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:t; 72, call; 72, 73; 72, 74; 73, identifier:sorted; 74, argument_list; 74, 75; 75, identifier:s; 76, except_clause; 76, 77; 76, 78; 77, identifier:TypeError; 78, block; 78, 79; 78, 80; 79, pass_statement; 80, comment; 81, else_clause; 81, 82; 82, block; 82, 83; 82, 87; 82, 93; 82, 99; 82, 133; 83, assert_statement; 83, 84; 84, comparison_operator:>; 84, 85; 84, 86; 85, identifier:n; 86, integer:0; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 90; 89, identifier:last; 90, subscript; 90, 91; 90, 92; 91, identifier:t; 92, integer:0; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:lasti; 96, assignment; 96, 97; 96, 98; 97, identifier:i; 98, integer:1; 99, while_statement; 99, 100; 99, 103; 100, comparison_operator:<; 100, 101; 100, 102; 101, identifier:i; 102, identifier:n; 103, block; 103, 104; 103, 127; 104, if_statement; 104, 105; 104, 110; 105, comparison_operator:!=; 105, 106; 105, 109; 106, subscript; 106, 107; 106, 108; 107, identifier:t; 108, identifier:i; 109, identifier:last; 110, block; 110, 111; 110, 121; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 116; 113, subscript; 113, 114; 113, 115; 114, identifier:t; 115, identifier:lasti; 116, assignment; 116, 117; 116, 118; 117, identifier:last; 118, subscript; 118, 119; 118, 120; 119, identifier:t; 120, identifier:i; 121, expression_statement; 121, 122; 122, assignment; 122, 123; 122, 124; 123, identifier:lasti; 124, binary_operator:+; 124, 125; 124, 126; 125, identifier:lasti; 126, integer:1; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:i; 130, binary_operator:+; 130, 131; 130, 132; 131, identifier:i; 132, integer:1; 133, return_statement; 133, 134; 134, subscript; 134, 135; 134, 136; 135, identifier:t; 136, slice; 136, 137; 136, 138; 137, colon; 138, identifier:lasti; 139, delete_statement; 139, 140; 140, identifier:t; 141, comment; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:u; 145, list:[]; 146, for_statement; 146, 147; 146, 148; 146, 149; 147, identifier:x; 148, identifier:s; 149, block; 149, 150; 150, if_statement; 150, 151; 150, 154; 151, comparison_operator:not; 151, 152; 151, 153; 152, identifier:x; 153, identifier:u; 154, block; 154, 155; 155, expression_statement; 155, 156; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:u; 159, identifier:append; 160, argument_list; 160, 161; 161, identifier:x; 162, return_statement; 162, 163; 163, identifier:u | def unique(s):
"""Return a list of the elements in s, but without duplicates.
For example, unique([1,2,3,1,2,3]) is some permutation of [1,2,3],
unique("abcabc") some permutation of ["a", "b", "c"], and
unique(([1, 2], [2, 3], [1, 2])) some permutation of
[[2, 3], [1, 2]].
For best speed, all sequence elements should be hashable. Then
unique() will usually work in linear time.
If not possible, the sequence elements should enjoy a total
ordering, and if list(s).sort() doesn't raise TypeError it's
assumed that they do enjoy a total ordering. Then unique() will
usually work in O(N*log2(N)) time.
If that's not possible either, the sequence elements must support
equality-testing. Then unique() will usually work in quadratic
time.
"""
n = len(s)
if n == 0:
return []
# Try using a dict first, as that's the fastest and will usually
# work. If it doesn't work, it will usually fail quickly, so it
# usually doesn't cost much to *try* it. It requires that all the
# sequence elements be hashable, and support equality comparison.
u = {}
try:
for x in s:
u[x] = 1
except TypeError:
pass # move on to the next method
else:
return list(u.keys())
del u
# We can't hash all the elements. Second fastest is to sort,
# which brings the equal elements together; then duplicates are
# easy to weed out in a single pass.
# NOTE: Python's list.sort() was designed to be efficient in the
# presence of many duplicate elements. This isn't true of all
# sort functions in all languages or libraries, so this approach
# is more effective in Python than it may be elsewhere.
try:
t = sorted(s)
except TypeError:
pass # move on to the next method
else:
assert n > 0
last = t[0]
lasti = i = 1
while i < n:
if t[i] != last:
t[lasti] = last = t[i]
lasti = lasti + 1
i = i + 1
return t[:lasti]
del t
# Brute force is all that's left.
u = []
for x in s:
if x not in u:
u.append(x)
return u |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:setup_client; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:client_id; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:user_data; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:scan; 13, True; 14, default_parameter; 14, 15; 14, 16; 15, identifier:broadcast; 16, False; 17, block; 17, 18; 17, 20; 17, 36; 17, 53; 17, 77; 17, 90; 17, 109; 17, 118; 18, expression_statement; 18, 19; 19, comment; 20, if_statement; 20, 21; 20, 24; 21, comparison_operator:is; 21, 22; 21, 23; 22, identifier:client_id; 23, None; 24, block; 24, 25; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:client_id; 28, call; 28, 29; 28, 30; 29, identifier:str; 30, argument_list; 30, 31; 31, call; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:uuid; 34, identifier:uuid4; 35, argument_list; 36, if_statement; 36, 37; 36, 42; 37, comparison_operator:in; 37, 38; 37, 39; 38, identifier:client_id; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:_clients; 42, block; 42, 43; 43, raise_statement; 43, 44; 44, call; 44, 45; 44, 46; 45, identifier:ArgumentError; 46, argument_list; 46, 47; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, string:"Duplicate client_id: {}"; 50, identifier:format; 51, argument_list; 51, 52; 52, identifier:client_id; 53, function_definition; 53, 54; 53, 55; 53, 60; 54, function_name:_client_callback; 55, parameters; 55, 56; 55, 57; 55, 58; 55, 59; 56, identifier:conn_string; 57, identifier:_; 58, identifier:event_name; 59, identifier:event; 60, block; 60, 61; 60, 68; 61, expression_statement; 61, 62; 62, assignment; 62, 63; 62, 64; 63, identifier:event_tuple; 64, tuple; 64, 65; 64, 66; 64, 67; 65, identifier:conn_string; 66, identifier:event_name; 67, identifier:event; 68, expression_statement; 68, 69; 69, await; 69, 70; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:_forward_client_event; 74, argument_list; 74, 75; 74, 76; 75, identifier:client_id; 76, identifier:event_tuple; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:client_monitor; 80, call; 80, 81; 80, 86; 81, attribute; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:adapter; 85, identifier:register_monitor; 86, argument_list; 86, 87; 86, 88; 86, 89; 87, list:[]; 88, list:[]; 89, identifier:_client_callback; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 97; 92, subscript; 92, 93; 92, 96; 93, attribute; 93, 94; 93, 95; 94, identifier:self; 95, identifier:_clients; 96, identifier:client_id; 97, call; 97, 98; 97, 99; 98, identifier:dict; 99, argument_list; 99, 100; 99, 103; 99, 106; 100, keyword_argument; 100, 101; 100, 102; 101, identifier:user_data; 102, identifier:user_data; 103, keyword_argument; 103, 104; 103, 105; 104, identifier:connections; 105, dictionary; 106, keyword_argument; 106, 107; 106, 108; 107, identifier:monitor; 108, identifier:client_monitor; 109, expression_statement; 109, 110; 110, call; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:self; 113, identifier:_adjust_global_events; 114, argument_list; 114, 115; 114, 116; 114, 117; 115, identifier:client_id; 116, identifier:scan; 117, identifier:broadcast; 118, return_statement; 118, 119; 119, identifier:client_id | def setup_client(self, client_id=None, user_data=None, scan=True, broadcast=False):
"""Setup a newly connected client.
``client_id`` must be unique among all connected clients. If it is
passed as None, a random client_id will be generated as a string and
returned.
This method reserves internal resources for tracking what devices this
client has connected to and installs a monitor into the adapter on
behalf of the client.
It should be called whenever a new client connects to the device server
before any other activities by that client are allowed. By default,
all clients start receiving ``device_seen`` events but if you want
your client to also receive broadcast events, you can pass broadcast=True.
Args:
client_id (str): A unique identifier for this client that will be
used to refer to it in all future interactions. If this is
None, then a random string will be generated for the client_id.
user_data (object): An arbitrary object that you would like to store
with this client and will be passed to your event handler when
events are forwarded to this client.
scan (bool): Whether to install a monitor to listen for device_found
events.
broadcast (bool): Whether to install a monitor to list for broadcast
events.
Returns:
str: The client_id.
If a client id was passed in, it will be the same as what was passed
in. If no client id was passed in then it will be a random unique
string.
"""
if client_id is None:
client_id = str(uuid.uuid4())
if client_id in self._clients:
raise ArgumentError("Duplicate client_id: {}".format(client_id))
async def _client_callback(conn_string, _, event_name, event):
event_tuple = (conn_string, event_name, event)
await self._forward_client_event(client_id, event_tuple)
client_monitor = self.adapter.register_monitor([], [], _client_callback)
self._clients[client_id] = dict(user_data=user_data, connections={},
monitor=client_monitor)
self._adjust_global_events(client_id, scan, broadcast)
return client_id |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_parse_conn_string; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:conn_string; 6, block; 6, 7; 6, 9; 6, 13; 6, 15; 6, 51; 6, 65; 6, 78; 6, 87; 6, 245; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:disconnection_required; 12, False; 13, expression_statement; 13, 14; 14, comment; 15, if_statement; 15, 16; 15, 23; 16, boolean_operator:or; 16, 17; 16, 20; 17, comparison_operator:is; 17, 18; 17, 19; 18, identifier:conn_string; 19, None; 20, comparison_operator:not; 20, 21; 20, 22; 21, string:'device'; 22, identifier:conn_string; 23, block; 23, 24; 24, if_statement; 24, 25; 24, 38; 25, boolean_operator:and; 25, 26; 25, 31; 26, comparison_operator:is; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:_default_device_info; 30, None; 31, comparison_operator:!=; 31, 32; 31, 35; 32, attribute; 32, 33; 32, 34; 33, identifier:self; 34, identifier:_device_info; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:_default_device_info; 38, block; 38, 39; 38, 43; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:disconnection_required; 42, True; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:self; 47, identifier:_device_info; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:_default_device_info; 51, if_statement; 51, 52; 51, 62; 52, boolean_operator:or; 52, 53; 52, 56; 53, comparison_operator:is; 53, 54; 53, 55; 54, identifier:conn_string; 55, None; 56, comparison_operator:==; 56, 57; 56, 61; 57, call; 57, 58; 57, 59; 58, identifier:len; 59, argument_list; 59, 60; 60, identifier:conn_string; 61, integer:0; 62, block; 62, 63; 63, return_statement; 63, 64; 64, identifier:disconnection_required; 65, if_statement; 65, 66; 65, 69; 66, comparison_operator:in; 66, 67; 66, 68; 67, string:'@'; 68, identifier:conn_string; 69, block; 69, 70; 70, raise_statement; 70, 71; 71, call; 71, 72; 71, 73; 72, identifier:ArgumentError; 73, argument_list; 73, 74; 73, 75; 74, string:"Configuration files are not yet supported as part of a connection string argument"; 75, keyword_argument; 75, 76; 75, 77; 76, identifier:conn_string; 77, identifier:conn_string; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:pairs; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:conn_string; 84, identifier:split; 85, argument_list; 85, 86; 86, string:';'; 87, for_statement; 87, 88; 87, 89; 87, 90; 88, identifier:pair; 89, identifier:pairs; 90, block; 90, 91; 90, 103; 90, 119; 90, 127; 90, 135; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 97; 93, pattern_list; 93, 94; 93, 95; 93, 96; 94, identifier:name; 95, identifier:_; 96, identifier:value; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:pair; 100, identifier:partition; 101, argument_list; 101, 102; 102, string:'='; 103, if_statement; 103, 104; 103, 117; 104, boolean_operator:or; 104, 105; 104, 111; 105, comparison_operator:==; 105, 106; 105, 110; 106, call; 106, 107; 106, 108; 107, identifier:len; 108, argument_list; 108, 109; 109, identifier:name; 110, integer:0; 111, comparison_operator:==; 111, 112; 111, 116; 112, call; 112, 113; 112, 114; 113, identifier:len; 114, argument_list; 114, 115; 115, identifier:value; 116, integer:0; 117, block; 117, 118; 118, continue_statement; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:name; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:name; 125, identifier:strip; 126, argument_list; 127, expression_statement; 127, 128; 128, assignment; 128, 129; 128, 130; 129, identifier:value; 130, call; 130, 131; 130, 134; 131, attribute; 131, 132; 131, 133; 132, identifier:value; 133, identifier:strip; 134, argument_list; 135, if_statement; 135, 136; 135, 139; 135, 203; 136, comparison_operator:==; 136, 137; 136, 138; 137, identifier:name; 138, string:'device'; 139, block; 139, 140; 139, 151; 140, if_statement; 140, 141; 140, 144; 141, comparison_operator:in; 141, 142; 141, 143; 142, identifier:value; 143, identifier:DEVICE_ALIASES; 144, block; 144, 145; 145, expression_statement; 145, 146; 146, assignment; 146, 147; 146, 148; 147, identifier:device_name; 148, subscript; 148, 149; 148, 150; 149, identifier:DEVICE_ALIASES; 150, identifier:value; 151, if_statement; 151, 152; 151, 155; 151, 182; 152, comparison_operator:in; 152, 153; 152, 154; 153, identifier:device_name; 154, identifier:KNOWN_DEVICES; 155, block; 155, 156; 155, 165; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 159; 158, identifier:device_info; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:KNOWN_DEVICES; 162, identifier:get; 163, argument_list; 163, 164; 164, identifier:device_name; 165, if_statement; 165, 166; 165, 171; 166, comparison_operator:!=; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:self; 169, identifier:_device_info; 170, identifier:device_info; 171, block; 171, 172; 171, 178; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:self; 176, identifier:_device_info; 177, identifier:device_info; 178, expression_statement; 178, 179; 179, assignment; 179, 180; 179, 181; 180, identifier:disconnection_required; 181, True; 182, else_clause; 182, 183; 183, block; 183, 184; 184, raise_statement; 184, 185; 185, call; 185, 186; 185, 187; 186, identifier:ArgumentError; 187, argument_list; 187, 188; 187, 189; 187, 192; 188, string:"Unknown device name or alias, please select from known_devices"; 189, keyword_argument; 189, 190; 189, 191; 190, identifier:device_name; 191, identifier:value; 192, keyword_argument; 192, 193; 192, 194; 193, identifier:known_devices; 194, list_comprehension; 194, 195; 194, 196; 195, identifier:x; 196, for_in_clause; 196, 197; 196, 198; 197, identifier:x; 198, call; 198, 199; 198, 202; 199, attribute; 199, 200; 199, 201; 200, identifier:DEVICE_ALIASES; 201, identifier:keys; 202, argument_list; 203, elif_clause; 203, 204; 203, 207; 204, comparison_operator:==; 204, 205; 204, 206; 205, identifier:name; 206, string:'channel'; 207, block; 207, 208; 208, if_statement; 208, 209; 208, 214; 208, 238; 209, comparison_operator:is; 209, 210; 209, 213; 210, attribute; 210, 211; 210, 212; 211, identifier:self; 212, identifier:_mux_func; 213, None; 214, block; 214, 215; 215, if_statement; 215, 216; 215, 224; 216, comparison_operator:!=; 216, 217; 216, 220; 217, attribute; 217, 218; 217, 219; 218, identifier:self; 219, identifier:_channel; 220, call; 220, 221; 220, 222; 221, identifier:int; 222, argument_list; 222, 223; 223, identifier:value; 224, block; 224, 225; 224, 234; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:self; 229, identifier:_channel; 230, call; 230, 231; 230, 232; 231, identifier:int; 232, argument_list; 232, 233; 233, identifier:value; 234, expression_statement; 234, 235; 235, assignment; 235, 236; 235, 237; 236, identifier:disconnection_required; 237, True; 238, else_clause; 238, 239; 239, block; 239, 240; 240, expression_statement; 240, 241; 241, call; 241, 242; 241, 243; 242, identifier:print; 243, argument_list; 243, 244; 244, string:"Warning: multiplexing architecture not selected, channel will not be set"; 245, return_statement; 245, 246; 246, identifier:disconnection_required | def _parse_conn_string(self, conn_string):
"""Parse a connection string passed from 'debug -c' or 'connect_direct'
Returns True if any settings changed in the debug port, which
would require a jlink disconnection """
disconnection_required = False
"""If device not in conn_string, set to default info"""
if conn_string is None or 'device' not in conn_string:
if self._default_device_info is not None and self._device_info != self._default_device_info:
disconnection_required = True
self._device_info = self._default_device_info
if conn_string is None or len(conn_string) == 0:
return disconnection_required
if '@' in conn_string:
raise ArgumentError("Configuration files are not yet supported as part of a connection string argument",
conn_string=conn_string)
pairs = conn_string.split(';')
for pair in pairs:
name, _, value = pair.partition('=')
if len(name) == 0 or len(value) == 0:
continue
name = name.strip()
value = value.strip()
if name == 'device':
if value in DEVICE_ALIASES:
device_name = DEVICE_ALIASES[value]
if device_name in KNOWN_DEVICES:
device_info = KNOWN_DEVICES.get(device_name)
if self._device_info != device_info:
self._device_info = device_info
disconnection_required = True
else:
raise ArgumentError("Unknown device name or alias, please select from known_devices",
device_name=value, known_devices=[x for x in DEVICE_ALIASES.keys()])
elif name == 'channel':
if self._mux_func is not None:
if self._channel != int(value):
self._channel = int(value)
disconnection_required = True
else:
print("Warning: multiplexing architecture not selected, channel will not be set")
return disconnection_required |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:main; 3, parameters; 3, 4; 4, default_parameter; 4, 5; 4, 6; 5, identifier:argv; 6, None; 7, block; 7, 8; 7, 10; 7, 25; 7, 31; 7, 42; 7, 64; 7, 70; 7, 99; 7, 108; 7, 135; 7, 147; 7, 159; 7, 163; 7, 171; 7, 278; 7, 286; 7, 292; 7, 309; 7, 319; 8, expression_statement; 8, 9; 9, comment; 10, if_statement; 10, 11; 10, 14; 11, comparison_operator:is; 11, 12; 11, 13; 12, identifier:argv; 13, None; 14, block; 14, 15; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:argv; 18, subscript; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:sys; 21, identifier:argv; 22, slice; 22, 23; 22, 24; 23, integer:1; 24, colon; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:parser; 28, call; 28, 29; 28, 30; 29, identifier:build_args; 30, argument_list; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:args; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:parser; 37, identifier:parse_args; 38, argument_list; 38, 39; 39, keyword_argument; 39, 40; 39, 41; 40, identifier:args; 41, identifier:argv; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 47; 44, pattern_list; 44, 45; 44, 46; 45, identifier:recipe_name; 46, identifier:_ext; 47, call; 47, 48; 47, 53; 48, attribute; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:os; 51, identifier:path; 52, identifier:splitext; 53, argument_list; 53, 54; 54, call; 54, 55; 54, 60; 55, attribute; 55, 56; 55, 59; 56, attribute; 56, 57; 56, 58; 57, identifier:os; 58, identifier:path; 59, identifier:basename; 60, argument_list; 60, 61; 61, attribute; 61, 62; 61, 63; 62, identifier:args; 63, identifier:recipe; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:rm; 67, call; 67, 68; 67, 69; 68, identifier:RecipeManager; 69, argument_list; 70, expression_statement; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:rm; 74, identifier:add_recipe_folder; 75, argument_list; 75, 76; 75, 86; 76, call; 76, 77; 76, 82; 77, attribute; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:os; 80, identifier:path; 81, identifier:dirname; 82, argument_list; 82, 83; 83, attribute; 83, 84; 83, 85; 84, identifier:args; 85, identifier:recipe; 86, keyword_argument; 86, 87; 86, 88; 87, identifier:whitelist; 88, list:[os.path.basename(args.recipe)]; 88, 89; 89, call; 89, 90; 89, 95; 90, attribute; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:os; 93, identifier:path; 94, identifier:basename; 95, argument_list; 95, 96; 96, attribute; 96, 97; 96, 98; 97, identifier:args; 98, identifier:recipe; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:recipe; 102, call; 102, 103; 102, 106; 103, attribute; 103, 104; 103, 105; 104, identifier:rm; 105, identifier:get_recipe; 106, argument_list; 106, 107; 107, identifier:recipe_name; 108, if_statement; 108, 109; 108, 114; 109, comparison_operator:is; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:args; 112, identifier:archive; 113, None; 114, block; 114, 115; 114, 124; 114, 133; 115, expression_statement; 115, 116; 116, call; 116, 117; 116, 118; 117, identifier:print; 118, argument_list; 118, 119; 119, binary_operator:%; 119, 120; 119, 121; 120, string:"Archiving recipe into %s"; 121, attribute; 121, 122; 121, 123; 122, identifier:args; 123, identifier:archive; 124, expression_statement; 124, 125; 125, call; 125, 126; 125, 129; 126, attribute; 126, 127; 126, 128; 127, identifier:recipe; 128, identifier:archive; 129, argument_list; 129, 130; 130, attribute; 130, 131; 130, 132; 131, identifier:args; 132, identifier:archive; 133, return_statement; 133, 134; 134, integer:0; 135, if_statement; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:args; 138, identifier:info; 139, block; 139, 140; 139, 145; 140, expression_statement; 140, 141; 141, call; 141, 142; 141, 143; 142, identifier:print; 143, argument_list; 143, 144; 144, identifier:recipe; 145, return_statement; 145, 146; 146, integer:0; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 150; 149, identifier:variables; 150, call; 150, 151; 150, 152; 151, identifier:load_variables; 152, argument_list; 152, 153; 152, 156; 153, attribute; 153, 154; 153, 155; 154, identifier:args; 155, identifier:define; 156, attribute; 156, 157; 156, 158; 157, identifier:args; 158, identifier:config; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:success; 162, integer:0; 163, expression_statement; 163, 164; 164, assignment; 164, 165; 164, 166; 165, identifier:start_time; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:time; 169, identifier:time; 170, argument_list; 171, if_statement; 171, 172; 171, 177; 171, 209; 172, comparison_operator:is; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:args; 175, identifier:loop; 176, None; 177, block; 177, 178; 178, try_statement; 178, 179; 178, 191; 179, block; 179, 180; 179, 187; 180, expression_statement; 180, 181; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, identifier:recipe; 184, identifier:run; 185, argument_list; 185, 186; 186, identifier:variables; 187, expression_statement; 187, 188; 188, augmented_assignment:+=; 188, 189; 188, 190; 189, identifier:success; 190, integer:1; 191, except_clause; 191, 192; 191, 196; 192, as_pattern; 192, 193; 192, 194; 193, identifier:IOTileException; 194, as_pattern_target; 194, 195; 195, identifier:exc; 196, block; 196, 197; 196, 207; 197, expression_statement; 197, 198; 198, call; 198, 199; 198, 200; 199, identifier:print; 200, argument_list; 200, 201; 201, binary_operator:%; 201, 202; 201, 203; 202, string:"Error running recipe: %s"; 203, call; 203, 204; 203, 205; 204, identifier:str; 205, argument_list; 205, 206; 206, identifier:exc; 207, return_statement; 207, 208; 208, integer:1; 209, else_clause; 209, 210; 210, block; 210, 211; 211, while_statement; 211, 212; 211, 213; 212, True; 213, block; 213, 214; 213, 225; 213, 231; 213, 239; 213, 247; 214, expression_statement; 214, 215; 215, assignment; 215, 216; 215, 217; 216, identifier:value; 217, call; 217, 218; 217, 219; 218, identifier:input; 219, argument_list; 219, 220; 220, binary_operator:%; 220, 221; 220, 222; 221, string:"Enter value for loop variable %s (return to stop): "; 222, attribute; 222, 223; 222, 224; 223, identifier:args; 224, identifier:loop; 225, if_statement; 225, 226; 225, 229; 226, comparison_operator:==; 226, 227; 226, 228; 227, identifier:value; 228, string:''; 229, block; 229, 230; 230, break_statement; 231, expression_statement; 231, 232; 232, assignment; 232, 233; 232, 234; 233, identifier:local_vars; 234, call; 234, 235; 234, 236; 235, identifier:dict; 236, argument_list; 236, 237; 237, dictionary_splat; 237, 238; 238, identifier:variables; 239, expression_statement; 239, 240; 240, assignment; 240, 241; 240, 246; 241, subscript; 241, 242; 241, 243; 242, identifier:local_vars; 243, attribute; 243, 244; 243, 245; 244, identifier:args; 245, identifier:loop; 246, identifier:value; 247, try_statement; 247, 248; 247, 260; 248, block; 248, 249; 248, 256; 249, expression_statement; 249, 250; 250, call; 250, 251; 250, 254; 251, attribute; 251, 252; 251, 253; 252, identifier:recipe; 253, identifier:run; 254, argument_list; 254, 255; 255, identifier:local_vars; 256, expression_statement; 256, 257; 257, augmented_assignment:+=; 257, 258; 257, 259; 258, identifier:success; 259, integer:1; 260, except_clause; 260, 261; 260, 265; 261, as_pattern; 261, 262; 261, 263; 262, identifier:IOTileException; 263, as_pattern_target; 263, 264; 264, identifier:exc; 265, block; 265, 266; 266, expression_statement; 266, 267; 267, call; 267, 268; 267, 269; 268, identifier:print; 269, argument_list; 269, 270; 270, binary_operator:%; 270, 271; 270, 272; 271, string:"--> ERROR processing loop variable %s: %s"; 272, tuple; 272, 273; 272, 274; 273, identifier:value; 274, call; 274, 275; 274, 276; 275, identifier:str; 276, argument_list; 276, 277; 277, identifier:exc; 278, expression_statement; 278, 279; 279, assignment; 279, 280; 279, 281; 280, identifier:end_time; 281, call; 281, 282; 281, 285; 282, attribute; 282, 283; 282, 284; 283, identifier:time; 284, identifier:time; 285, argument_list; 286, expression_statement; 286, 287; 287, assignment; 287, 288; 287, 289; 288, identifier:total_time; 289, binary_operator:-; 289, 290; 289, 291; 290, identifier:end_time; 291, identifier:start_time; 292, if_statement; 292, 293; 292, 296; 292, 301; 293, comparison_operator:==; 293, 294; 293, 295; 294, identifier:success; 295, integer:0; 296, block; 296, 297; 297, expression_statement; 297, 298; 298, assignment; 298, 299; 298, 300; 299, identifier:per_time; 300, float:0.0; 301, else_clause; 301, 302; 302, block; 302, 303; 303, expression_statement; 303, 304; 304, assignment; 304, 305; 304, 306; 305, identifier:per_time; 306, binary_operator:/; 306, 307; 306, 308; 307, identifier:total_time; 308, identifier:success; 309, expression_statement; 309, 310; 310, call; 310, 311; 310, 312; 311, identifier:print; 312, argument_list; 312, 313; 313, binary_operator:%; 313, 314; 313, 315; 314, string:"Performed %d runs in %.1f seconds (%.1f seconds / run)"; 315, tuple; 315, 316; 315, 317; 315, 318; 316, identifier:success; 317, identifier:total_time; 318, identifier:per_time; 319, return_statement; 319, 320; 320, integer:0 | def main(argv=None):
"""Main entry point for iotile-ship recipe runner.
This is the iotile-ship command line program.
Args:
argv (list of str): An optional set of command line
parameters. If not passed, these are taken from
sys.argv.
"""
if argv is None:
argv = sys.argv[1:]
parser = build_args()
args = parser.parse_args(args=argv)
recipe_name, _ext = os.path.splitext(os.path.basename(args.recipe))
rm = RecipeManager()
rm.add_recipe_folder(os.path.dirname(args.recipe), whitelist=[os.path.basename(args.recipe)])
recipe = rm.get_recipe(recipe_name)
if args.archive is not None:
print("Archiving recipe into %s" % args.archive)
recipe.archive(args.archive)
return 0
if args.info:
print(recipe)
return 0
variables = load_variables(args.define, args.config)
success = 0
start_time = time.time()
if args.loop is None:
try:
recipe.run(variables)
success += 1
except IOTileException as exc:
print("Error running recipe: %s" % str(exc))
return 1
else:
while True:
value = input("Enter value for loop variable %s (return to stop): " % args.loop)
if value == '':
break
local_vars = dict(**variables)
local_vars[args.loop] = value
try:
recipe.run(local_vars)
success += 1
except IOTileException as exc:
print("--> ERROR processing loop variable %s: %s" % (value, str(exc)))
end_time = time.time()
total_time = end_time - start_time
if success == 0:
per_time = 0.0
else:
per_time = total_time / success
print("Performed %d runs in %.1f seconds (%.1f seconds / run)" % (success, total_time, per_time))
return 0 |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:assign_utc; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:self; 5, identifier:reading_id; 6, default_parameter; 6, 7; 6, 8; 7, identifier:uptime; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:prefer; 11, string:"before"; 12, block; 12, 13; 12, 15; 12, 32; 12, 44; 12, 58; 12, 69; 12, 73; 12, 77; 12, 81; 12, 93; 12, 104; 12, 133; 12, 145; 12, 156; 12, 168; 12, 179; 13, expression_statement; 13, 14; 14, comment; 15, if_statement; 15, 16; 15, 21; 16, comparison_operator:not; 16, 17; 16, 18; 17, identifier:prefer; 18, tuple; 18, 19; 18, 20; 19, string:"before"; 20, string:"after"; 21, block; 21, 22; 22, raise_statement; 22, 23; 23, call; 23, 24; 23, 25; 24, identifier:ArgumentError; 25, argument_list; 25, 26; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, string:"Invalid prefer parameter: {}, must be 'before' or 'after'"; 29, identifier:format; 30, argument_list; 30, 31; 31, identifier:prefer; 32, if_statement; 32, 33; 32, 41; 33, comparison_operator:==; 33, 34; 33, 40; 34, call; 34, 35; 34, 36; 35, identifier:len; 36, argument_list; 36, 37; 37, attribute; 37, 38; 37, 39; 38, identifier:self; 39, identifier:_anchor_points; 40, integer:0; 41, block; 41, 42; 42, return_statement; 42, 43; 43, None; 44, if_statement; 44, 45; 44, 55; 45, comparison_operator:>; 45, 46; 45, 47; 46, identifier:reading_id; 47, attribute; 47, 48; 47, 54; 48, subscript; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:self; 51, identifier:_anchor_points; 52, unary_operator:-; 52, 53; 53, integer:1; 54, identifier:reading_id; 55, block; 55, 56; 56, return_statement; 56, 57; 57, None; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:i; 61, call; 61, 62; 61, 67; 62, attribute; 62, 63; 62, 66; 63, attribute; 63, 64; 63, 65; 64, identifier:self; 65, identifier:_anchor_points; 66, identifier:bisect_key_left; 67, argument_list; 67, 68; 68, identifier:reading_id; 69, expression_statement; 69, 70; 70, assignment; 70, 71; 70, 72; 71, identifier:found_id; 72, False; 73, expression_statement; 73, 74; 74, assignment; 74, 75; 74, 76; 75, identifier:crossed_break; 76, False; 77, expression_statement; 77, 78; 78, assignment; 78, 79; 78, 80; 79, identifier:exact; 80, True; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:last; 84, call; 84, 85; 84, 92; 85, attribute; 85, 86; 85, 91; 86, subscript; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:self; 89, identifier:_anchor_points; 90, identifier:i; 91, identifier:copy; 92, argument_list; 93, if_statement; 93, 94; 93, 97; 94, comparison_operator:is; 94, 95; 94, 96; 95, identifier:uptime; 96, None; 97, block; 97, 98; 98, expression_statement; 98, 99; 99, assignment; 99, 100; 99, 103; 100, attribute; 100, 101; 100, 102; 101, identifier:last; 102, identifier:uptime; 103, identifier:uptime; 104, if_statement; 104, 105; 104, 110; 105, comparison_operator:==; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:last; 108, identifier:reading_id; 109, identifier:reading_id; 110, block; 110, 111; 110, 115; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:found_id; 114, True; 115, if_statement; 115, 116; 115, 121; 116, comparison_operator:is; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:last; 119, identifier:utc; 120, None; 121, block; 121, 122; 122, return_statement; 122, 123; 123, call; 123, 124; 123, 125; 124, identifier:UTCAssignment; 125, argument_list; 125, 126; 125, 127; 125, 130; 125, 131; 125, 132; 126, identifier:reading_id; 127, attribute; 127, 128; 127, 129; 128, identifier:last; 129, identifier:utc; 130, identifier:found_id; 131, identifier:exact; 132, identifier:crossed_break; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:left_assign; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:self; 139, identifier:_fix_left; 140, argument_list; 140, 141; 140, 142; 140, 143; 140, 144; 141, identifier:reading_id; 142, identifier:last; 143, identifier:i; 144, identifier:found_id; 145, if_statement; 145, 146; 145, 153; 146, boolean_operator:and; 146, 147; 146, 150; 147, comparison_operator:is; 147, 148; 147, 149; 148, identifier:left_assign; 149, None; 150, attribute; 150, 151; 150, 152; 151, identifier:left_assign; 152, identifier:exact; 153, block; 153, 154; 154, return_statement; 154, 155; 155, identifier:left_assign; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 159; 158, identifier:right_assign; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:self; 162, identifier:_fix_right; 163, argument_list; 163, 164; 163, 165; 163, 166; 163, 167; 164, identifier:reading_id; 165, identifier:last; 166, identifier:i; 167, identifier:found_id; 168, if_statement; 168, 169; 168, 176; 169, boolean_operator:and; 169, 170; 169, 173; 170, comparison_operator:is; 170, 171; 170, 172; 171, identifier:right_assign; 172, None; 173, attribute; 173, 174; 173, 175; 174, identifier:right_assign; 175, identifier:exact; 176, block; 176, 177; 177, return_statement; 177, 178; 178, identifier:right_assign; 179, return_statement; 179, 180; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:self; 183, identifier:_pick_best_fix; 184, argument_list; 184, 185; 184, 186; 184, 187; 185, identifier:left_assign; 186, identifier:right_assign; 187, identifier:prefer | def assign_utc(self, reading_id, uptime=None, prefer="before"):
"""Assign a utc datetime to a reading id.
This method will return an object with assignment information or None
if a utc value cannot be assigned. The assignment object returned
contains a utc property that has the asssigned UTC as well as other
properties describing how reliable the assignment is.
Args:
reading_id (int): The monotonic reading id that we wish to assign
a utc timestamp to.
uptime (int): Optional uptime that should be associated with the
reading id. If this is not specified and the reading_id is
found in the anchor points passed to this class then the
uptime from the corresponding anchor point will be used.
prefer (str): There are two possible directions that can be used
to assign a UTC timestamp (the nearest anchor before or after the
reading). If both directions are of similar quality, the choice
is arbitrary. Passing prefer="before" will use the anchor point
before the reading. Passing prefer="after" will use the anchor
point after the reading. Default: before.
Returns:
UTCAssignment: The assigned UTC time or None if assignment is impossible.
"""
if prefer not in ("before", "after"):
raise ArgumentError("Invalid prefer parameter: {}, must be 'before' or 'after'".format(prefer))
if len(self._anchor_points) == 0:
return None
if reading_id > self._anchor_points[-1].reading_id:
return None
i = self._anchor_points.bisect_key_left(reading_id)
found_id = False
crossed_break = False
exact = True
last = self._anchor_points[i].copy()
if uptime is not None:
last.uptime = uptime
if last.reading_id == reading_id:
found_id = True
if last.utc is not None:
return UTCAssignment(reading_id, last.utc, found_id, exact, crossed_break)
left_assign = self._fix_left(reading_id, last, i, found_id)
if left_assign is not None and left_assign.exact:
return left_assign
right_assign = self._fix_right(reading_id, last, i, found_id)
if right_assign is not None and right_assign.exact:
return right_assign
return self._pick_best_fix(left_assign, right_assign, prefer) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_text_contents; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 6, expression_statement; 6, 7; 7, comment; 8, try_statement; 8, 9; 8, 21; 8, 35; 9, block; 9, 10; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:self; 13, call; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:disambiguate; 17, argument_list; 17, 18; 18, keyword_argument; 18, 19; 18, 20; 19, identifier:must_exist; 20, integer:1; 21, except_clause; 21, 22; 21, 27; 21, 28; 21, 29; 21, 30; 21, 31; 21, 32; 22, attribute; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:SCons; 25, identifier:Errors; 26, identifier:UserError; 27, comment; 28, comment; 29, comment; 30, comment; 31, comment; 32, block; 32, 33; 33, return_statement; 33, 34; 34, string:''; 35, else_clause; 35, 36; 36, block; 36, 37; 37, return_statement; 37, 38; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:get_text_contents; 42, argument_list | def get_text_contents(self):
"""Fetch the decoded text contents of a Unicode encoded Entry.
Since this should return the text contents from the file
system, we check to see into what sort of subclass we should
morph this Entry."""
try:
self = self.disambiguate(must_exist=1)
except SCons.Errors.UserError:
# There was nothing on disk with which to disambiguate
# this entry. Leave it as an Entry, but return a null
# string so calls to get_text_contents() in emitters and
# the like (e.g. in qt.py) don't have to disambiguate by
# hand or catch the exception.
return ''
else:
return self.get_text_contents() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:_lookup; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:self; 5, identifier:p; 6, identifier:directory; 7, identifier:fsclass; 8, default_parameter; 8, 9; 8, 10; 9, identifier:create; 10, integer:1; 11, block; 11, 12; 11, 14; 11, 32; 11, 33; 11, 40; 11, 54; 11, 338; 11, 415; 12, expression_statement; 12, 13; 13, comment; 14, if_statement; 14, 15; 14, 20; 14, 21; 14, 22; 15, call; 15, 16; 15, 17; 16, identifier:isinstance; 17, argument_list; 17, 18; 17, 19; 18, identifier:p; 19, identifier:Base; 20, comment; 21, comment; 22, block; 22, 23; 22, 30; 23, expression_statement; 23, 24; 24, call; 24, 25; 24, 28; 25, attribute; 25, 26; 25, 27; 26, identifier:p; 27, identifier:must_be_same; 28, argument_list; 28, 29; 29, identifier:fsclass; 30, return_statement; 30, 31; 31, identifier:p; 32, comment; 33, expression_statement; 33, 34; 34, assignment; 34, 35; 34, 36; 35, identifier:p; 36, call; 36, 37; 36, 38; 37, identifier:str; 38, argument_list; 38, 39; 39, identifier:p; 40, if_statement; 40, 41; 40, 43; 41, not_operator; 41, 42; 42, identifier:os_sep_is_slash; 43, block; 43, 44; 44, expression_statement; 44, 45; 45, assignment; 45, 46; 45, 47; 46, identifier:p; 47, call; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:p; 50, identifier:replace; 51, argument_list; 51, 52; 51, 53; 52, identifier:OS_SEP; 53, string:'/'; 54, if_statement; 54, 55; 54, 63; 54, 64; 54, 65; 54, 66; 54, 179; 55, comparison_operator:==; 55, 56; 55, 62; 56, subscript; 56, 57; 56, 58; 57, identifier:p; 58, slice; 58, 59; 58, 60; 58, 61; 59, integer:0; 60, colon; 61, integer:1; 62, string:'#'; 63, comment; 64, comment; 65, comment; 66, block; 66, 67; 66, 75; 66, 81; 66, 82; 66, 83; 66, 84; 66, 85; 66, 86; 66, 87; 66, 88; 66, 89; 66, 90; 66, 91; 66, 131; 66, 132; 66, 133; 66, 142; 66, 149; 66, 150; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:p; 70, subscript; 70, 71; 70, 72; 71, identifier:p; 72, slice; 72, 73; 72, 74; 73, integer:1; 74, colon; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:directory; 78, attribute; 78, 79; 78, 80; 79, identifier:self; 80, identifier:Top; 81, comment; 82, comment; 83, comment; 84, comment; 85, comment; 86, comment; 87, comment; 88, comment; 89, comment; 90, comment; 91, if_statement; 91, 92; 91, 93; 91, 123; 92, identifier:do_splitdrive; 93, block; 93, 94; 93, 103; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 99; 96, pattern_list; 96, 97; 96, 98; 97, identifier:drive; 98, identifier:p; 99, call; 99, 100; 99, 101; 100, identifier:_my_splitdrive; 101, argument_list; 101, 102; 102, identifier:p; 103, if_statement; 103, 104; 103, 105; 103, 115; 104, identifier:drive; 105, block; 105, 106; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:root; 109, call; 109, 110; 109, 113; 110, attribute; 110, 111; 110, 112; 111, identifier:self; 112, identifier:get_root; 113, argument_list; 113, 114; 114, identifier:drive; 115, else_clause; 115, 116; 116, block; 116, 117; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 120; 119, identifier:root; 120, attribute; 120, 121; 120, 122; 121, identifier:directory; 122, identifier:root; 123, else_clause; 123, 124; 124, block; 124, 125; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:root; 128, attribute; 128, 129; 128, 130; 129, identifier:directory; 130, identifier:root; 131, comment; 132, comment; 133, expression_statement; 133, 134; 134, assignment; 134, 135; 134, 136; 135, identifier:p; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:p; 139, identifier:strip; 140, argument_list; 140, 141; 141, string:'/'; 142, expression_statement; 142, 143; 143, assignment; 143, 144; 143, 145; 144, identifier:needs_normpath; 145, call; 145, 146; 145, 147; 146, identifier:needs_normpath_match; 147, argument_list; 147, 148; 148, identifier:p; 149, comment; 150, if_statement; 150, 151; 150, 156; 150, 165; 151, comparison_operator:in; 151, 152; 151, 153; 152, identifier:p; 153, tuple; 153, 154; 153, 155; 154, string:''; 155, string:'.'; 156, block; 156, 157; 157, expression_statement; 157, 158; 158, assignment; 158, 159; 158, 160; 159, identifier:p; 160, call; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:directory; 163, identifier:get_labspath; 164, argument_list; 165, else_clause; 165, 166; 166, block; 166, 167; 167, expression_statement; 167, 168; 168, assignment; 168, 169; 168, 170; 169, identifier:p; 170, binary_operator:+; 170, 171; 170, 178; 171, binary_operator:+; 171, 172; 171, 177; 172, call; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:directory; 175, identifier:get_labspath; 176, argument_list; 177, string:'/'; 178, identifier:p; 179, else_clause; 179, 180; 180, block; 180, 181; 180, 212; 180, 213; 180, 214; 180, 228; 180, 235; 181, if_statement; 181, 182; 181, 183; 181, 206; 182, identifier:do_splitdrive; 183, block; 183, 184; 183, 193; 184, expression_statement; 184, 185; 185, assignment; 185, 186; 185, 189; 186, pattern_list; 186, 187; 186, 188; 187, identifier:drive; 188, identifier:p; 189, call; 189, 190; 189, 191; 190, identifier:_my_splitdrive; 191, argument_list; 191, 192; 192, identifier:p; 193, if_statement; 193, 194; 193, 198; 193, 199; 193, 200; 193, 201; 194, boolean_operator:and; 194, 195; 194, 196; 195, identifier:drive; 196, not_operator; 196, 197; 197, identifier:p; 198, comment; 199, comment; 200, comment; 201, block; 201, 202; 202, expression_statement; 202, 203; 203, assignment; 203, 204; 203, 205; 204, identifier:p; 205, string:'/'; 206, else_clause; 206, 207; 207, block; 207, 208; 208, expression_statement; 208, 209; 209, assignment; 209, 210; 209, 211; 210, identifier:drive; 211, string:''; 212, comment; 213, comment; 214, if_statement; 214, 215; 214, 218; 215, comparison_operator:!=; 215, 216; 215, 217; 216, identifier:p; 217, string:'/'; 218, block; 218, 219; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 222; 221, identifier:p; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:p; 225, identifier:rstrip; 226, argument_list; 226, 227; 227, string:'/'; 228, expression_statement; 228, 229; 229, assignment; 229, 230; 229, 231; 230, identifier:needs_normpath; 231, call; 231, 232; 231, 233; 232, identifier:needs_normpath_match; 233, argument_list; 233, 234; 234, identifier:p; 235, if_statement; 235, 236; 235, 244; 235, 245; 235, 255; 236, comparison_operator:==; 236, 237; 236, 243; 237, subscript; 237, 238; 237, 239; 238, identifier:p; 239, slice; 239, 240; 239, 241; 239, 242; 240, integer:0; 241, colon; 242, integer:1; 243, string:'/'; 244, comment; 245, block; 245, 246; 246, expression_statement; 246, 247; 247, assignment; 247, 248; 247, 249; 248, identifier:root; 249, call; 249, 250; 249, 253; 250, attribute; 250, 251; 250, 252; 251, identifier:self; 252, identifier:get_root; 253, argument_list; 253, 254; 254, identifier:drive; 255, else_clause; 255, 256; 255, 257; 255, 258; 255, 259; 255, 260; 256, comment; 257, comment; 258, comment; 259, comment; 260, block; 260, 261; 260, 289; 260, 318; 261, if_statement; 261, 262; 261, 263; 261, 281; 262, identifier:directory; 263, block; 263, 264; 264, if_statement; 264, 265; 264, 271; 265, not_operator; 265, 266; 266, call; 266, 267; 266, 268; 267, identifier:isinstance; 268, argument_list; 268, 269; 268, 270; 269, identifier:directory; 270, identifier:Dir; 271, block; 271, 272; 272, expression_statement; 272, 273; 273, assignment; 273, 274; 273, 275; 274, identifier:directory; 275, call; 275, 276; 275, 279; 276, attribute; 276, 277; 276, 278; 277, identifier:self; 278, identifier:Dir; 279, argument_list; 279, 280; 280, identifier:directory; 281, else_clause; 281, 282; 282, block; 282, 283; 283, expression_statement; 283, 284; 284, assignment; 284, 285; 284, 286; 285, identifier:directory; 286, attribute; 286, 287; 286, 288; 287, identifier:self; 288, identifier:_cwd; 289, if_statement; 289, 290; 289, 295; 289, 304; 290, comparison_operator:in; 290, 291; 290, 292; 291, identifier:p; 292, tuple; 292, 293; 292, 294; 293, string:''; 294, string:'.'; 295, block; 295, 296; 296, expression_statement; 296, 297; 297, assignment; 297, 298; 297, 299; 298, identifier:p; 299, call; 299, 300; 299, 303; 300, attribute; 300, 301; 300, 302; 301, identifier:directory; 302, identifier:get_labspath; 303, argument_list; 304, else_clause; 304, 305; 305, block; 305, 306; 306, expression_statement; 306, 307; 307, assignment; 307, 308; 307, 309; 308, identifier:p; 309, binary_operator:+; 309, 310; 309, 317; 310, binary_operator:+; 310, 311; 310, 316; 311, call; 311, 312; 311, 315; 312, attribute; 312, 313; 312, 314; 313, identifier:directory; 314, identifier:get_labspath; 315, argument_list; 316, string:'/'; 317, identifier:p; 318, if_statement; 318, 319; 318, 320; 318, 330; 319, identifier:drive; 320, block; 320, 321; 321, expression_statement; 321, 322; 322, assignment; 322, 323; 322, 324; 323, identifier:root; 324, call; 324, 325; 324, 328; 325, attribute; 325, 326; 325, 327; 326, identifier:self; 327, identifier:get_root; 328, argument_list; 328, 329; 329, identifier:drive; 330, else_clause; 330, 331; 331, block; 331, 332; 332, expression_statement; 332, 333; 333, assignment; 333, 334; 333, 335; 334, identifier:root; 335, attribute; 335, 336; 335, 337; 336, identifier:directory; 337, identifier:root; 338, if_statement; 338, 339; 338, 342; 338, 343; 338, 344; 338, 345; 338, 346; 338, 347; 338, 348; 338, 349; 338, 350; 338, 351; 339, comparison_operator:is; 339, 340; 339, 341; 340, identifier:needs_normpath; 341, None; 342, comment; 343, comment; 344, comment; 345, comment; 346, comment; 347, comment; 348, comment; 349, comment; 350, comment; 351, block; 351, 352; 351, 365; 351, 369; 351, 404; 352, expression_statement; 352, 353; 353, assignment; 353, 354; 353, 355; 354, identifier:ins; 355, subscript; 355, 356; 355, 362; 356, call; 356, 357; 356, 360; 357, attribute; 357, 358; 357, 359; 358, identifier:p; 359, identifier:split; 360, argument_list; 360, 361; 361, string:'/'; 362, slice; 362, 363; 362, 364; 363, integer:1; 364, colon; 365, expression_statement; 365, 366; 366, assignment; 366, 367; 366, 368; 367, identifier:outs; 368, list:[]; 369, for_statement; 369, 370; 369, 371; 369, 372; 370, identifier:d; 371, identifier:ins; 372, block; 372, 373; 373, if_statement; 373, 374; 373, 377; 373, 390; 374, comparison_operator:==; 374, 375; 374, 376; 375, identifier:d; 376, string:'..'; 377, block; 377, 378; 378, try_statement; 378, 379; 378, 386; 379, block; 379, 380; 380, expression_statement; 380, 381; 381, call; 381, 382; 381, 385; 382, attribute; 382, 383; 382, 384; 383, identifier:outs; 384, identifier:pop; 385, argument_list; 386, except_clause; 386, 387; 386, 388; 387, identifier:IndexError; 388, block; 388, 389; 389, pass_statement; 390, elif_clause; 390, 391; 390, 396; 391, comparison_operator:not; 391, 392; 391, 393; 392, identifier:d; 393, tuple; 393, 394; 393, 395; 394, string:''; 395, string:'.'; 396, block; 396, 397; 397, expression_statement; 397, 398; 398, call; 398, 399; 398, 402; 399, attribute; 399, 400; 399, 401; 400, identifier:outs; 401, identifier:append; 402, argument_list; 402, 403; 403, identifier:d; 404, expression_statement; 404, 405; 405, assignment; 405, 406; 405, 407; 406, identifier:p; 407, binary_operator:+; 407, 408; 407, 409; 408, string:'/'; 409, call; 409, 410; 409, 413; 410, attribute; 410, 411; 410, 412; 411, string:'/'; 412, identifier:join; 413, argument_list; 413, 414; 414, identifier:outs; 415, return_statement; 415, 416; 416, call; 416, 417; 416, 420; 417, attribute; 417, 418; 417, 419; 418, identifier:root; 419, identifier:_lookup_abs; 420, argument_list; 420, 421; 420, 422; 420, 423; 421, identifier:p; 422, identifier:fsclass; 423, identifier:create | def _lookup(self, p, directory, fsclass, create=1):
"""
The generic entry point for Node lookup with user-supplied data.
This translates arbitrary input into a canonical Node.FS object
of the specified fsclass. The general approach for strings is
to turn it into a fully normalized absolute path and then call
the root directory's lookup_abs() method for the heavy lifting.
If the path name begins with '#', it is unconditionally
interpreted relative to the top-level directory of this FS. '#'
is treated as a synonym for the top-level SConstruct directory,
much like '~' is treated as a synonym for the user's home
directory in a UNIX shell. So both '#foo' and '#/foo' refer
to the 'foo' subdirectory underneath the top-level SConstruct
directory.
If the path name is relative, then the path is looked up relative
to the specified directory, or the current directory (self._cwd,
typically the SConscript directory) if the specified directory
is None.
"""
if isinstance(p, Base):
# It's already a Node.FS object. Make sure it's the right
# class and return.
p.must_be_same(fsclass)
return p
# str(p) in case it's something like a proxy object
p = str(p)
if not os_sep_is_slash:
p = p.replace(OS_SEP, '/')
if p[0:1] == '#':
# There was an initial '#', so we strip it and override
# whatever directory they may have specified with the
# top-level SConstruct directory.
p = p[1:]
directory = self.Top
# There might be a drive letter following the
# '#'. Although it is not described in the SCons man page,
# the regression test suite explicitly tests for that
# syntax. It seems to mean the following thing:
#
# Assuming the the SCons top dir is in C:/xxx/yyy,
# '#X:/toto' means X:/xxx/yyy/toto.
#
# i.e. it assumes that the X: drive has a directory
# structure similar to the one found on drive C:.
if do_splitdrive:
drive, p = _my_splitdrive(p)
if drive:
root = self.get_root(drive)
else:
root = directory.root
else:
root = directory.root
# We can only strip trailing after splitting the drive
# since the drive might the UNC '//' prefix.
p = p.strip('/')
needs_normpath = needs_normpath_match(p)
# The path is relative to the top-level SCons directory.
if p in ('', '.'):
p = directory.get_labspath()
else:
p = directory.get_labspath() + '/' + p
else:
if do_splitdrive:
drive, p = _my_splitdrive(p)
if drive and not p:
# This causes a naked drive letter to be treated
# as a synonym for the root directory on that
# drive.
p = '/'
else:
drive = ''
# We can only strip trailing '/' since the drive might the
# UNC '//' prefix.
if p != '/':
p = p.rstrip('/')
needs_normpath = needs_normpath_match(p)
if p[0:1] == '/':
# Absolute path
root = self.get_root(drive)
else:
# This is a relative lookup or to the current directory
# (the path name is not absolute). Add the string to the
# appropriate directory lookup path, after which the whole
# thing gets normalized.
if directory:
if not isinstance(directory, Dir):
directory = self.Dir(directory)
else:
directory = self._cwd
if p in ('', '.'):
p = directory.get_labspath()
else:
p = directory.get_labspath() + '/' + p
if drive:
root = self.get_root(drive)
else:
root = directory.root
if needs_normpath is not None:
# Normalize a pathname. Will return the same result for
# equivalent paths.
#
# We take advantage of the fact that we have an absolute
# path here for sure. In addition, we know that the
# components of lookup path are separated by slashes at
# this point. Because of this, this code is about 2X
# faster than calling os.path.normpath() followed by
# replacing os.sep with '/' again.
ins = p.split('/')[1:]
outs = []
for d in ins:
if d == '..':
try:
outs.pop()
except IndexError:
pass
elif d not in ('', '.'):
outs.append(d)
p = '/' + '/'.join(outs)
return root._lookup_abs(p, fsclass, create) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:_glob1; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:self; 5, identifier:pattern; 6, default_parameter; 6, 7; 6, 8; 7, identifier:ondisk; 8, True; 9, default_parameter; 9, 10; 9, 11; 10, identifier:source; 11, False; 12, default_parameter; 12, 13; 12, 14; 13, identifier:strings; 14, False; 15, block; 15, 16; 15, 18; 15, 26; 15, 45; 15, 51; 15, 55; 15, 239; 15, 246; 15, 267; 15, 277; 15, 282; 16, expression_statement; 16, 17; 17, comment; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:search_dir_list; 21, call; 21, 22; 21, 25; 22, attribute; 22, 23; 22, 24; 23, identifier:self; 24, identifier:get_all_rdirs; 25, argument_list; 26, for_statement; 26, 27; 26, 28; 26, 33; 27, identifier:srcdir; 28, call; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:srcdir_list; 32, argument_list; 33, block; 33, 34; 34, expression_statement; 34, 35; 35, call; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:search_dir_list; 38, identifier:extend; 39, argument_list; 39, 40; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:srcdir; 43, identifier:get_all_rdirs; 44, argument_list; 45, expression_statement; 45, 46; 46, assignment; 46, 47; 46, 48; 47, identifier:selfEntry; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:Entry; 51, expression_statement; 51, 52; 52, assignment; 52, 53; 52, 54; 53, identifier:names; 54, list:[]; 55, for_statement; 55, 56; 55, 57; 55, 58; 55, 59; 55, 60; 55, 61; 56, identifier:dir; 57, identifier:search_dir_list; 58, comment; 59, comment; 60, comment; 61, block; 61, 62; 61, 86; 61, 93; 61, 108; 62, expression_statement; 62, 63; 63, assignment; 63, 64; 63, 65; 64, identifier:node_names; 65, list_comprehension; 65, 66; 65, 69; 65, 80; 66, attribute; 66, 67; 66, 68; 67, identifier:v; 68, identifier:name; 69, for_in_clause; 69, 70; 69, 73; 70, pattern_list; 70, 71; 70, 72; 71, identifier:k; 72, identifier:v; 73, call; 73, 74; 73, 79; 74, attribute; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:dir; 77, identifier:entries; 78, identifier:items; 79, argument_list; 80, if_clause; 80, 81; 81, comparison_operator:not; 81, 82; 81, 83; 82, identifier:k; 83, tuple; 83, 84; 83, 85; 84, string:'.'; 85, string:'..'; 86, expression_statement; 86, 87; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:names; 90, identifier:extend; 91, argument_list; 91, 92; 92, identifier:node_names; 93, if_statement; 93, 94; 93, 96; 93, 97; 93, 98; 94, not_operator; 94, 95; 95, identifier:strings; 96, comment; 97, comment; 98, block; 98, 99; 99, for_statement; 99, 100; 99, 101; 99, 102; 100, identifier:name; 101, identifier:node_names; 102, block; 102, 103; 103, expression_statement; 103, 104; 104, call; 104, 105; 104, 106; 105, identifier:selfEntry; 106, argument_list; 106, 107; 107, identifier:name; 108, if_statement; 108, 109; 108, 110; 109, identifier:ondisk; 110, block; 110, 111; 110, 130; 110, 137; 111, try_statement; 111, 112; 111, 124; 112, block; 112, 113; 113, expression_statement; 113, 114; 114, assignment; 114, 115; 114, 116; 115, identifier:disk_names; 116, call; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:os; 119, identifier:listdir; 120, argument_list; 120, 121; 121, attribute; 121, 122; 121, 123; 122, identifier:dir; 123, identifier:_abspath; 124, except_clause; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:os; 127, identifier:error; 128, block; 128, 129; 129, continue_statement; 130, expression_statement; 130, 131; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:names; 134, identifier:extend; 135, argument_list; 135, 136; 136, identifier:disk_names; 137, if_statement; 137, 138; 137, 140; 137, 141; 137, 142; 137, 143; 137, 144; 137, 145; 137, 146; 137, 147; 137, 148; 138, not_operator; 138, 139; 139, identifier:strings; 140, comment; 141, comment; 142, comment; 143, comment; 144, comment; 145, comment; 146, comment; 147, comment; 148, block; 148, 149; 148, 170; 148, 180; 148, 186; 149, if_statement; 149, 150; 149, 155; 150, comparison_operator:!=; 150, 151; 150, 154; 151, subscript; 151, 152; 151, 153; 152, identifier:pattern; 153, integer:0; 154, string:'.'; 155, block; 155, 156; 156, expression_statement; 156, 157; 157, assignment; 157, 158; 157, 159; 158, identifier:disk_names; 159, list_comprehension; 159, 160; 159, 161; 159, 164; 160, identifier:x; 161, for_in_clause; 161, 162; 161, 163; 162, identifier:x; 163, identifier:disk_names; 164, if_clause; 164, 165; 165, comparison_operator:!=; 165, 166; 165, 169; 166, subscript; 166, 167; 166, 168; 167, identifier:x; 168, integer:0; 169, string:'.'; 170, expression_statement; 170, 171; 171, assignment; 171, 172; 171, 173; 172, identifier:disk_names; 173, call; 173, 174; 173, 177; 174, attribute; 174, 175; 174, 176; 175, identifier:fnmatch; 176, identifier:filter; 177, argument_list; 177, 178; 177, 179; 178, identifier:disk_names; 179, identifier:pattern; 180, expression_statement; 180, 181; 181, assignment; 181, 182; 181, 183; 182, identifier:dirEntry; 183, attribute; 183, 184; 183, 185; 184, identifier:dir; 185, identifier:Entry; 186, for_statement; 186, 187; 186, 188; 186, 189; 186, 190; 186, 191; 187, identifier:name; 188, identifier:disk_names; 189, comment; 190, comment; 191, block; 191, 192; 191, 198; 191, 209; 191, 216; 192, expression_statement; 192, 193; 193, assignment; 193, 194; 193, 195; 194, identifier:name; 195, binary_operator:+; 195, 196; 195, 197; 196, string:'./'; 197, identifier:name; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:node; 201, call; 201, 202; 201, 208; 202, attribute; 202, 203; 202, 207; 203, call; 203, 204; 203, 205; 204, identifier:dirEntry; 205, argument_list; 205, 206; 206, identifier:name; 207, identifier:disambiguate; 208, argument_list; 209, expression_statement; 209, 210; 210, assignment; 210, 211; 210, 212; 211, identifier:n; 212, call; 212, 213; 212, 214; 213, identifier:selfEntry; 214, argument_list; 214, 215; 215, identifier:name; 216, if_statement; 216, 217; 216, 224; 217, comparison_operator:!=; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:n; 220, identifier:__class__; 221, attribute; 221, 222; 221, 223; 222, identifier:node; 223, identifier:__class__; 224, block; 224, 225; 224, 233; 225, expression_statement; 225, 226; 226, assignment; 226, 227; 226, 230; 227, attribute; 227, 228; 227, 229; 228, identifier:n; 229, identifier:__class__; 230, attribute; 230, 231; 230, 232; 231, identifier:node; 232, identifier:__class__; 233, expression_statement; 233, 234; 234, call; 234, 235; 234, 238; 235, attribute; 235, 236; 235, 237; 236, identifier:n; 237, identifier:_morph; 238, argument_list; 239, expression_statement; 239, 240; 240, assignment; 240, 241; 240, 242; 241, identifier:names; 242, call; 242, 243; 242, 244; 243, identifier:set; 244, argument_list; 244, 245; 245, identifier:names; 246, if_statement; 246, 247; 246, 252; 247, comparison_operator:!=; 247, 248; 247, 251; 248, subscript; 248, 249; 248, 250; 249, identifier:pattern; 250, integer:0; 251, string:'.'; 252, block; 252, 253; 253, expression_statement; 253, 254; 254, assignment; 254, 255; 254, 256; 255, identifier:names; 256, list_comprehension; 256, 257; 256, 258; 256, 261; 257, identifier:x; 258, for_in_clause; 258, 259; 258, 260; 259, identifier:x; 260, identifier:names; 261, if_clause; 261, 262; 262, comparison_operator:!=; 262, 263; 262, 266; 263, subscript; 263, 264; 263, 265; 264, identifier:x; 265, integer:0; 266, string:'.'; 267, expression_statement; 267, 268; 268, assignment; 268, 269; 268, 270; 269, identifier:names; 270, call; 270, 271; 270, 274; 271, attribute; 271, 272; 271, 273; 272, identifier:fnmatch; 273, identifier:filter; 274, argument_list; 274, 275; 274, 276; 275, identifier:names; 276, identifier:pattern; 277, if_statement; 277, 278; 277, 279; 278, identifier:strings; 279, block; 279, 280; 280, return_statement; 280, 281; 281, identifier:names; 282, return_statement; 282, 283; 283, list_comprehension; 283, 284; 283, 292; 284, subscript; 284, 285; 284, 288; 285, attribute; 285, 286; 285, 287; 286, identifier:self; 287, identifier:entries; 288, call; 288, 289; 288, 290; 289, identifier:_my_normcase; 290, argument_list; 290, 291; 291, identifier:n; 292, for_in_clause; 292, 293; 292, 294; 293, identifier:n; 294, identifier:names | def _glob1(self, pattern, ondisk=True, source=False, strings=False):
"""
Globs for and returns a list of entry names matching a single
pattern in this directory.
This searches any repositories and source directories for
corresponding entries and returns a Node (or string) relative
to the current directory if an entry is found anywhere.
TODO: handle pattern with no wildcard
"""
search_dir_list = self.get_all_rdirs()
for srcdir in self.srcdir_list():
search_dir_list.extend(srcdir.get_all_rdirs())
selfEntry = self.Entry
names = []
for dir in search_dir_list:
# We use the .name attribute from the Node because the keys of
# the dir.entries dictionary are normalized (that is, all upper
# case) on case-insensitive systems like Windows.
node_names = [ v.name for k, v in dir.entries.items()
if k not in ('.', '..') ]
names.extend(node_names)
if not strings:
# Make sure the working directory (self) actually has
# entries for all Nodes in repositories or variant dirs.
for name in node_names: selfEntry(name)
if ondisk:
try:
disk_names = os.listdir(dir._abspath)
except os.error:
continue
names.extend(disk_names)
if not strings:
# We're going to return corresponding Nodes in
# the local directory, so we need to make sure
# those Nodes exist. We only want to create
# Nodes for the entries that will match the
# specified pattern, though, which means we
# need to filter the list here, even though
# the overall list will also be filtered later,
# after we exit this loop.
if pattern[0] != '.':
disk_names = [x for x in disk_names if x[0] != '.']
disk_names = fnmatch.filter(disk_names, pattern)
dirEntry = dir.Entry
for name in disk_names:
# Add './' before disk filename so that '#' at
# beginning of filename isn't interpreted.
name = './' + name
node = dirEntry(name).disambiguate()
n = selfEntry(name)
if n.__class__ != node.__class__:
n.__class__ = node.__class__
n._morph()
names = set(names)
if pattern[0] != '.':
names = [x for x in names if x[0] != '.']
names = fnmatch.filter(names, pattern)
if strings:
return names
return [self.entries[_my_normcase(n)] for n in names] |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:release_target_info; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 21; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 19; 9, parenthesized_expression; 9, 10; 10, boolean_operator:or; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 12, identifier:self; 13, identifier:released_target_info; 14, attribute; 14, 15; 14, 18; 15, attribute; 15, 16; 15, 17; 16, identifier:SCons; 17, identifier:Node; 18, identifier:interactive; 19, block; 19, 20; 20, return_statement; 21, if_statement; 21, 22; 21, 30; 21, 31; 21, 32; 22, not_operator; 22, 23; 23, call; 23, 24; 23, 25; 24, identifier:hasattr; 25, argument_list; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:attributes; 29, string:'keep_targetinfo'; 30, comment; 31, comment; 32, block; 32, 33; 32, 42; 32, 48; 32, 54; 32, 55; 32, 61; 32, 71; 32, 77; 32, 78; 32, 93; 32, 108; 32, 123; 32, 138; 32, 153; 32, 154; 32, 155; 33, expression_statement; 33, 34; 34, call; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:self; 37, identifier:changed; 38, argument_list; 38, 39; 39, keyword_argument; 39, 40; 39, 41; 40, identifier:allowcache; 41, True; 42, expression_statement; 42, 43; 43, call; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:self; 46, identifier:get_contents_sig; 47, argument_list; 48, expression_statement; 48, 49; 49, call; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:self; 52, identifier:get_build_env; 53, argument_list; 54, comment; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:self; 59, identifier:executor; 60, None; 61, expression_statement; 61, 62; 62, call; 62, 63; 62, 68; 63, attribute; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:self; 66, identifier:_memo; 67, identifier:pop; 68, argument_list; 68, 69; 68, 70; 69, string:'rfile'; 70, None; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:self; 75, identifier:prerequisites; 76, None; 77, comment; 78, if_statement; 78, 79; 78, 86; 79, not_operator; 79, 80; 80, call; 80, 81; 80, 82; 81, identifier:len; 82, argument_list; 82, 83; 83, attribute; 83, 84; 83, 85; 84, identifier:self; 85, identifier:ignore_set; 86, block; 86, 87; 87, expression_statement; 87, 88; 88, assignment; 88, 89; 88, 92; 89, attribute; 89, 90; 89, 91; 90, identifier:self; 91, identifier:ignore_set; 92, None; 93, if_statement; 93, 94; 93, 101; 94, not_operator; 94, 95; 95, call; 95, 96; 95, 97; 96, identifier:len; 97, argument_list; 97, 98; 98, attribute; 98, 99; 98, 100; 99, identifier:self; 100, identifier:implicit_set; 101, block; 101, 102; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 107; 104, attribute; 104, 105; 104, 106; 105, identifier:self; 106, identifier:implicit_set; 107, None; 108, if_statement; 108, 109; 108, 116; 109, not_operator; 109, 110; 110, call; 110, 111; 110, 112; 111, identifier:len; 112, argument_list; 112, 113; 113, attribute; 113, 114; 113, 115; 114, identifier:self; 115, identifier:depends_set; 116, block; 116, 117; 117, expression_statement; 117, 118; 118, assignment; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:self; 121, identifier:depends_set; 122, None; 123, if_statement; 123, 124; 123, 131; 124, not_operator; 124, 125; 125, call; 125, 126; 125, 127; 126, identifier:len; 127, argument_list; 127, 128; 128, attribute; 128, 129; 128, 130; 129, identifier:self; 130, identifier:ignore; 131, block; 131, 132; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 137; 134, attribute; 134, 135; 134, 136; 135, identifier:self; 136, identifier:ignore; 137, None; 138, if_statement; 138, 139; 138, 146; 139, not_operator; 139, 140; 140, call; 140, 141; 140, 142; 141, identifier:len; 142, argument_list; 142, 143; 143, attribute; 143, 144; 143, 145; 144, identifier:self; 145, identifier:depends; 146, block; 146, 147; 147, expression_statement; 147, 148; 148, assignment; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:self; 151, identifier:depends; 152, None; 153, comment; 154, comment; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:self; 159, identifier:released_target_info; 160, True | def release_target_info(self):
"""Called just after this node has been marked
up-to-date or was built completely.
This is where we try to release as many target node infos
as possible for clean builds and update runs, in order
to minimize the overall memory consumption.
We'd like to remove a lot more attributes like self.sources
and self.sources_set, but they might get used
in a next build step. For example, during configuration
the source files for a built E{*}.o file are used to figure out
which linker to use for the resulting Program (gcc vs. g++)!
That's why we check for the 'keep_targetinfo' attribute,
config Nodes and the Interactive mode just don't allow
an early release of most variables.
In the same manner, we can't simply remove the self.attributes
here. The smart linking relies on the shared flag, and some
parts of the java Tool use it to transport information
about nodes...
@see: built() and Node.release_target_info()
"""
if (self.released_target_info or SCons.Node.interactive):
return
if not hasattr(self.attributes, 'keep_targetinfo'):
# Cache some required values, before releasing
# stuff like env, executor and builder...
self.changed(allowcache=True)
self.get_contents_sig()
self.get_build_env()
# Now purge unneeded stuff to free memory...
self.executor = None
self._memo.pop('rfile', None)
self.prerequisites = None
# Cleanup lists, but only if they're empty
if not len(self.ignore_set):
self.ignore_set = None
if not len(self.implicit_set):
self.implicit_set = None
if not len(self.depends_set):
self.depends_set = None
if not len(self.ignore):
self.ignore = None
if not len(self.depends):
self.depends = None
# Mark this node as done, we only have to release
# the memory once...
self.released_target_info = True |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:find_file; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:filename; 6, identifier:paths; 7, default_parameter; 7, 8; 7, 9; 8, identifier:verbose; 9, None; 10, block; 10, 11; 10, 13; 10, 23; 10, 60; 10, 106; 10, 119; 10, 144; 10, 148; 10, 195; 10, 201; 11, expression_statement; 11, 12; 12, comment; 13, expression_statement; 13, 14; 14, assignment; 14, 15; 14, 16; 15, identifier:memo_key; 16, call; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:_find_file_key; 20, argument_list; 20, 21; 20, 22; 21, identifier:filename; 22, identifier:paths; 23, try_statement; 23, 24; 23, 33; 23, 48; 24, block; 24, 25; 25, expression_statement; 25, 26; 26, assignment; 26, 27; 26, 28; 27, identifier:memo_dict; 28, subscript; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:_memo; 32, string:'find_file'; 33, except_clause; 33, 34; 33, 35; 34, identifier:KeyError; 35, block; 35, 36; 35, 40; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:memo_dict; 39, dictionary; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 47; 42, subscript; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:self; 45, identifier:_memo; 46, string:'find_file'; 47, identifier:memo_dict; 48, else_clause; 48, 49; 49, block; 49, 50; 50, try_statement; 50, 51; 50, 56; 51, block; 51, 52; 52, return_statement; 52, 53; 53, subscript; 53, 54; 53, 55; 54, identifier:memo_dict; 55, identifier:memo_key; 56, except_clause; 56, 57; 56, 58; 57, identifier:KeyError; 58, block; 58, 59; 59, pass_statement; 60, if_statement; 60, 61; 60, 68; 61, boolean_operator:and; 61, 62; 61, 63; 62, identifier:verbose; 63, not_operator; 63, 64; 64, call; 64, 65; 64, 66; 65, identifier:callable; 66, argument_list; 66, 67; 67, identifier:verbose; 68, block; 68, 69; 68, 84; 68, 90; 69, if_statement; 69, 70; 69, 79; 70, not_operator; 70, 71; 71, call; 71, 72; 71, 77; 72, attribute; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:SCons; 75, identifier:Util; 76, identifier:is_String; 77, argument_list; 77, 78; 78, identifier:verbose; 79, block; 79, 80; 80, expression_statement; 80, 81; 81, assignment; 81, 82; 81, 83; 82, identifier:verbose; 83, string:"find_file"; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:_verbose; 87, binary_operator:%; 87, 88; 87, 89; 88, string:u' %s: '; 89, identifier:verbose; 90, expression_statement; 90, 91; 91, assignment; 91, 92; 91, 93; 92, identifier:verbose; 93, lambda; 93, 94; 93, 96; 94, lambda_parameters; 94, 95; 95, identifier:s; 96, call; 96, 97; 96, 102; 97, attribute; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:sys; 100, identifier:stdout; 101, identifier:write; 102, argument_list; 102, 103; 103, binary_operator:+; 103, 104; 103, 105; 104, identifier:_verbose; 105, identifier:s; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 111; 108, pattern_list; 108, 109; 108, 110; 109, identifier:filedir; 110, identifier:filename; 111, call; 111, 112; 111, 117; 112, attribute; 112, 113; 112, 116; 113, attribute; 113, 114; 113, 115; 114, identifier:os; 115, identifier:path; 116, identifier:split; 117, argument_list; 117, 118; 118, identifier:filename; 119, if_statement; 119, 120; 119, 121; 120, identifier:filedir; 121, block; 121, 122; 121, 128; 122, expression_statement; 122, 123; 123, assignment; 123, 124; 123, 127; 124, attribute; 124, 125; 124, 126; 125, identifier:self; 126, identifier:default_filedir; 127, identifier:filedir; 128, expression_statement; 128, 129; 129, assignment; 129, 130; 129, 131; 130, identifier:paths; 131, list_comprehension; 131, 132; 131, 133; 131, 142; 132, identifier:_f; 133, for_in_clause; 133, 134; 133, 135; 134, identifier:_f; 135, call; 135, 136; 135, 137; 136, identifier:map; 137, argument_list; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:self; 140, identifier:filedir_lookup; 141, identifier:paths; 142, if_clause; 142, 143; 143, identifier:_f; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:result; 147, None; 148, for_statement; 148, 149; 148, 150; 148, 151; 149, identifier:dir; 150, identifier:paths; 151, block; 151, 152; 151, 164; 151, 175; 152, if_statement; 152, 153; 152, 154; 153, identifier:verbose; 154, block; 154, 155; 155, expression_statement; 155, 156; 156, call; 156, 157; 156, 158; 157, identifier:verbose; 158, argument_list; 158, 159; 159, binary_operator:%; 159, 160; 159, 161; 160, string:"looking for '%s' in '%s' ...\n"; 161, tuple; 161, 162; 161, 163; 162, identifier:filename; 163, identifier:dir; 164, expression_statement; 164, 165; 165, assignment; 165, 166; 165, 169; 166, pattern_list; 166, 167; 166, 168; 167, identifier:node; 168, identifier:d; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:dir; 172, identifier:srcdir_find_file; 173, argument_list; 173, 174; 174, identifier:filename; 175, if_statement; 175, 176; 175, 177; 176, identifier:node; 177, block; 177, 178; 177, 190; 177, 194; 178, if_statement; 178, 179; 178, 180; 179, identifier:verbose; 180, block; 180, 181; 181, expression_statement; 181, 182; 182, call; 182, 183; 182, 184; 183, identifier:verbose; 184, argument_list; 184, 185; 185, binary_operator:%; 185, 186; 185, 187; 186, string:"... FOUND '%s' in '%s'\n"; 187, tuple; 187, 188; 187, 189; 188, identifier:filename; 189, identifier:d; 190, expression_statement; 190, 191; 191, assignment; 191, 192; 191, 193; 192, identifier:result; 193, identifier:node; 194, break_statement; 195, expression_statement; 195, 196; 196, assignment; 196, 197; 196, 200; 197, subscript; 197, 198; 197, 199; 198, identifier:memo_dict; 199, identifier:memo_key; 200, identifier:result; 201, return_statement; 201, 202; 202, identifier:result | def find_file(self, filename, paths, verbose=None):
"""
Find a node corresponding to either a derived file or a file that exists already.
Only the first file found is returned, and none is returned if no file is found.
filename: A filename to find
paths: A list of directory path *nodes* to search in. Can be represented as a list, a tuple, or a callable that is called with no arguments and returns the list or tuple.
returns The node created from the found file.
"""
memo_key = self._find_file_key(filename, paths)
try:
memo_dict = self._memo['find_file']
except KeyError:
memo_dict = {}
self._memo['find_file'] = memo_dict
else:
try:
return memo_dict[memo_key]
except KeyError:
pass
if verbose and not callable(verbose):
if not SCons.Util.is_String(verbose):
verbose = "find_file"
_verbose = u' %s: ' % verbose
verbose = lambda s: sys.stdout.write(_verbose + s)
filedir, filename = os.path.split(filename)
if filedir:
self.default_filedir = filedir
paths = [_f for _f in map(self.filedir_lookup, paths) if _f]
result = None
for dir in paths:
if verbose:
verbose("looking for '%s' in '%s' ...\n" % (filename, dir))
node, d = dir.srcdir_find_file(filename)
if node:
if verbose:
verbose("... FOUND '%s' in '%s'\n" % (filename, d))
result = node
break
memo_dict[memo_key] = result
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:build_report; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:self; 5, identifier:device_id; 6, default_parameter; 6, 7; 6, 8; 7, identifier:max_size; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:device_uptime; 11, integer:0; 12, default_parameter; 12, 13; 12, 14; 13, identifier:report_id; 14, None; 15, default_parameter; 15, 16; 15, 17; 16, identifier:auth_chain; 17, None; 18, block; 18, 19; 18, 21; 18, 39; 18, 55; 18, 71; 18, 264; 19, expression_statement; 19, 20; 20, comment; 21, if_statement; 21, 22; 21, 33; 22, boolean_operator:or; 22, 23; 22, 28; 23, comparison_operator:is; 23, 24; 23, 27; 24, attribute; 24, 25; 24, 26; 25, identifier:self; 26, identifier:walker; 27, None; 28, comparison_operator:is; 28, 29; 28, 32; 29, attribute; 29, 30; 29, 31; 30, identifier:self; 31, identifier:index; 32, None; 33, block; 33, 34; 34, raise_statement; 34, 35; 35, call; 35, 36; 35, 37; 36, identifier:InternalError; 37, argument_list; 37, 38; 38, string:"You can only build a report with a DataStreamer if you create it with a SensorLog and a streamer index"; 39, if_statement; 39, 40; 39, 49; 40, boolean_operator:and; 40, 41; 40, 46; 41, call; 41, 42; 41, 45; 42, attribute; 42, 43; 42, 44; 43, identifier:self; 44, identifier:requires_signing; 45, argument_list; 46, comparison_operator:is; 46, 47; 46, 48; 47, identifier:auth_chain; 48, None; 49, block; 49, 50; 50, raise_statement; 50, 51; 51, call; 51, 52; 51, 53; 52, identifier:ArgumentError; 53, argument_list; 53, 54; 54, string:"You must pass an auth chain to sign this report."; 55, if_statement; 55, 56; 55, 65; 56, boolean_operator:and; 56, 57; 56, 62; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:self; 60, identifier:requires_id; 61, argument_list; 62, comparison_operator:is; 62, 63; 62, 64; 63, identifier:report_id; 64, None; 65, block; 65, 66; 66, raise_statement; 66, 67; 67, call; 67, 68; 67, 69; 68, identifier:ArgumentError; 69, argument_list; 69, 70; 70, string:"You must pass a report_id to serialize this report"; 71, if_statement; 71, 72; 71, 77; 71, 137; 72, comparison_operator:==; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:self; 75, identifier:format; 76, string:'individual'; 77, block; 77, 78; 77, 88; 77, 94; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 81; 80, identifier:reading; 81, call; 81, 82; 81, 87; 82, attribute; 82, 83; 82, 86; 83, attribute; 83, 84; 83, 85; 84, identifier:self; 85, identifier:walker; 86, identifier:pop; 87, argument_list; 88, expression_statement; 88, 89; 89, assignment; 89, 90; 89, 91; 90, identifier:highest_id; 91, attribute; 91, 92; 91, 93; 92, identifier:reading; 93, identifier:reading_id; 94, if_statement; 94, 95; 94, 100; 94, 115; 95, comparison_operator:==; 95, 96; 95, 99; 96, attribute; 96, 97; 96, 98; 97, identifier:self; 98, identifier:report_type; 99, string:'telegram'; 100, block; 100, 101; 101, return_statement; 101, 102; 102, call; 102, 103; 102, 104; 103, identifier:StreamerReport; 104, argument_list; 104, 105; 104, 113; 104, 114; 105, call; 105, 106; 105, 109; 106, attribute; 106, 107; 106, 108; 107, identifier:IndividualReadingReport; 108, identifier:FromReadings; 109, argument_list; 109, 110; 109, 111; 110, identifier:device_id; 111, list:[reading]; 111, 112; 112, identifier:reading; 113, integer:1; 114, identifier:highest_id; 115, elif_clause; 115, 116; 115, 121; 116, comparison_operator:==; 116, 117; 116, 120; 117, attribute; 117, 118; 117, 119; 118, identifier:self; 119, identifier:report_type; 120, string:'broadcast'; 121, block; 121, 122; 122, return_statement; 122, 123; 123, call; 123, 124; 123, 125; 124, identifier:StreamerReport; 125, argument_list; 125, 126; 125, 135; 125, 136; 126, call; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:BroadcastReport; 129, identifier:FromReadings; 130, argument_list; 130, 131; 130, 132; 130, 134; 131, identifier:device_id; 132, list:[reading]; 132, 133; 133, identifier:reading; 134, identifier:device_uptime; 135, integer:1; 136, identifier:highest_id; 137, elif_clause; 137, 138; 137, 143; 138, comparison_operator:==; 138, 139; 138, 142; 139, attribute; 139, 140; 139, 141; 140, identifier:self; 141, identifier:format; 142, string:'hashedlist'; 143, block; 143, 144; 143, 155; 143, 168; 143, 172; 143, 176; 143, 228; 144, expression_statement; 144, 145; 145, assignment; 145, 146; 145, 147; 146, identifier:max_readings; 147, binary_operator://; 147, 148; 147, 154; 148, parenthesized_expression; 148, 149; 149, binary_operator:-; 149, 150; 149, 153; 150, binary_operator:-; 150, 151; 150, 152; 151, identifier:max_size; 152, integer:20; 153, integer:24; 154, integer:16; 155, if_statement; 155, 156; 155, 159; 156, comparison_operator:<=; 156, 157; 156, 158; 157, identifier:max_readings; 158, integer:0; 159, block; 159, 160; 160, raise_statement; 160, 161; 161, call; 161, 162; 161, 163; 162, identifier:InternalError; 163, argument_list; 163, 164; 163, 165; 164, string:"max_size is too small to hold even a single reading"; 165, keyword_argument; 165, 166; 165, 167; 166, identifier:max_size; 167, identifier:max_size; 168, expression_statement; 168, 169; 169, assignment; 169, 170; 169, 171; 170, identifier:readings; 171, list:[]; 172, expression_statement; 172, 173; 173, assignment; 173, 174; 173, 175; 174, identifier:highest_id; 175, integer:0; 176, try_statement; 176, 177; 176, 216; 177, block; 177, 178; 178, while_statement; 178, 179; 178, 185; 179, comparison_operator:<; 179, 180; 179, 184; 180, call; 180, 181; 180, 182; 181, identifier:len; 182, argument_list; 182, 183; 183, identifier:readings; 184, identifier:max_readings; 185, block; 185, 186; 185, 196; 185, 203; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 189; 188, identifier:reading; 189, call; 189, 190; 189, 195; 190, attribute; 190, 191; 190, 194; 191, attribute; 191, 192; 191, 193; 192, identifier:self; 193, identifier:walker; 194, identifier:pop; 195, argument_list; 196, expression_statement; 196, 197; 197, call; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:readings; 200, identifier:append; 201, argument_list; 201, 202; 202, identifier:reading; 203, if_statement; 203, 204; 203, 209; 204, comparison_operator:>; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:reading; 207, identifier:reading_id; 208, identifier:highest_id; 209, block; 209, 210; 210, expression_statement; 210, 211; 211, assignment; 211, 212; 211, 213; 212, identifier:highest_id; 213, attribute; 213, 214; 213, 215; 214, identifier:reading; 215, identifier:reading_id; 216, except_clause; 216, 217; 216, 218; 217, identifier:StreamEmptyError; 218, block; 218, 219; 219, if_statement; 219, 220; 219, 226; 220, comparison_operator:==; 220, 221; 220, 225; 221, call; 221, 222; 221, 223; 222, identifier:len; 223, argument_list; 223, 224; 224, identifier:readings; 225, integer:0; 226, block; 226, 227; 227, raise_statement; 228, return_statement; 228, 229; 229, call; 229, 230; 229, 231; 230, identifier:StreamerReport; 231, argument_list; 231, 232; 231, 259; 231, 263; 232, call; 232, 233; 232, 236; 233, attribute; 233, 234; 233, 235; 234, identifier:SignedListReport; 235, identifier:FromReadings; 236, argument_list; 236, 237; 236, 238; 236, 239; 236, 242; 236, 251; 236, 256; 237, identifier:device_id; 238, identifier:readings; 239, keyword_argument; 239, 240; 239, 241; 240, identifier:report_id; 241, identifier:report_id; 242, keyword_argument; 242, 243; 242, 244; 243, identifier:selector; 244, call; 244, 245; 244, 250; 245, attribute; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:self; 248, identifier:selector; 249, identifier:encode; 250, argument_list; 251, keyword_argument; 251, 252; 251, 253; 252, identifier:streamer; 253, attribute; 253, 254; 253, 255; 254, identifier:self; 255, identifier:index; 256, keyword_argument; 256, 257; 256, 258; 257, identifier:sent_timestamp; 258, identifier:device_uptime; 259, call; 259, 260; 259, 261; 260, identifier:len; 261, argument_list; 261, 262; 262, identifier:readings; 263, identifier:highest_id; 264, raise_statement; 264, 265; 265, call; 265, 266; 265, 267; 266, identifier:InternalError; 267, argument_list; 267, 268; 267, 269; 267, 274; 268, string:"Streamer report format or type is not supported currently"; 269, keyword_argument; 269, 270; 269, 271; 270, identifier:report_format; 271, attribute; 271, 272; 271, 273; 272, identifier:self; 273, identifier:format; 274, keyword_argument; 274, 275; 274, 276; 275, identifier:report_type; 276, attribute; 276, 277; 276, 278; 277, identifier:self; 278, identifier:report_type | def build_report(self, device_id, max_size=None, device_uptime=0, report_id=None, auth_chain=None):
"""Build a report with all of the readings in this streamer.
This method will produce an IOTileReport subclass and, if necessary,
sign it using the passed authentication chain.
Args:
device_id (int): The UUID of the device to generate a report for.
max_size (int): Optional maximum number of bytes that the report can be
device_uptime (int): The device's uptime to use as the sent timestamp of the report
report_id (int): The report id to use if the report type require serialization.
auth_chain (AuthChain): An auth chain class to use to sign the report if the report
type requires signing.
Returns:
StreamerReport: The report, its highest id and the number of readings in it.
The highest reading id and number of readings are returned
separately from the report itself because, depending on the format
of the report (such as whether it is encrypted or does not contain
reading ids), these details may not be recoverable from the report
itself.
Raises:
InternalError: If there was no SensorLog passed when this streamer was created.
StreamEmptyError: If there is no data to generate a report from. This can only happen
if a call to triggered() returned False.
ArgumentError: If the report requires additional metadata that was not passed like a
signing key or report_id.
"""
if self.walker is None or self.index is None:
raise InternalError("You can only build a report with a DataStreamer if you create it with a SensorLog and a streamer index")
if self.requires_signing() and auth_chain is None:
raise ArgumentError("You must pass an auth chain to sign this report.")
if self.requires_id() and report_id is None:
raise ArgumentError("You must pass a report_id to serialize this report")
if self.format == 'individual':
reading = self.walker.pop()
highest_id = reading.reading_id
if self.report_type == 'telegram':
return StreamerReport(IndividualReadingReport.FromReadings(device_id, [reading]), 1, highest_id)
elif self.report_type == 'broadcast':
return StreamerReport(BroadcastReport.FromReadings(device_id, [reading], device_uptime), 1, highest_id)
elif self.format == 'hashedlist':
max_readings = (max_size - 20 - 24) // 16
if max_readings <= 0:
raise InternalError("max_size is too small to hold even a single reading", max_size=max_size)
readings = []
highest_id = 0
try:
while len(readings) < max_readings:
reading = self.walker.pop()
readings.append(reading)
if reading.reading_id > highest_id:
highest_id = reading.reading_id
except StreamEmptyError:
if len(readings) == 0:
raise
return StreamerReport(SignedListReport.FromReadings(device_id, readings, report_id=report_id, selector=self.selector.encode(),
streamer=self.index, sent_timestamp=device_uptime), len(readings), highest_id)
raise InternalError("Streamer report format or type is not supported currently", report_format=self.format, report_type=self.report_type) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:scan; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:wait; 7, None; 8, block; 8, 9; 8, 11; 8, 23; 8, 35; 8, 36; 8, 40; 8, 50; 8, 61; 8, 62; 8, 63; 8, 85; 8, 86; 8, 95; 8, 105; 8, 111; 8, 117; 8, 181; 9, expression_statement; 9, 10; 10, comment; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12, 14; 13, identifier:min_scan; 14, call; 14, 15; 14, 20; 15, attribute; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:adapter; 19, identifier:get_config; 20, argument_list; 20, 21; 20, 22; 21, string:'minimum_scan_time'; 22, float:0.0; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:probe_required; 26, call; 26, 27; 26, 32; 27, attribute; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:adapter; 31, identifier:get_config; 32, argument_list; 32, 33; 32, 34; 33, string:'probe_required'; 34, False; 35, comment; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:wait_time; 39, None; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:elapsed; 43, binary_operator:-; 43, 44; 43, 47; 44, call; 44, 45; 44, 46; 45, identifier:monotonic; 46, argument_list; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:_start_time; 50, if_statement; 50, 51; 50, 54; 51, comparison_operator:<; 51, 52; 51, 53; 52, identifier:elapsed; 53, identifier:min_scan; 54, block; 54, 55; 55, expression_statement; 55, 56; 56, assignment; 56, 57; 56, 58; 57, identifier:wait_time; 58, binary_operator:-; 58, 59; 58, 60; 59, identifier:min_scan; 60, identifier:elapsed; 61, comment; 62, comment; 63, if_statement; 63, 64; 63, 65; 64, identifier:probe_required; 65, block; 65, 66; 65, 81; 66, expression_statement; 66, 67; 67, call; 67, 68; 67, 73; 68, attribute; 68, 69; 68, 72; 69, attribute; 69, 70; 69, 71; 70, identifier:self; 71, identifier:_loop; 72, identifier:run_coroutine; 73, argument_list; 73, 74; 74, call; 74, 75; 74, 80; 75, attribute; 75, 76; 75, 79; 76, attribute; 76, 77; 76, 78; 77, identifier:self; 78, identifier:adapter; 79, identifier:probe; 80, argument_list; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:wait_time; 84, identifier:min_scan; 85, comment; 86, if_statement; 86, 87; 86, 90; 87, comparison_operator:is; 87, 88; 87, 89; 88, identifier:wait; 89, None; 90, block; 90, 91; 91, expression_statement; 91, 92; 92, assignment; 92, 93; 92, 94; 93, identifier:wait_time; 94, identifier:wait; 95, if_statement; 95, 96; 95, 99; 96, comparison_operator:is; 96, 97; 96, 98; 97, identifier:wait_time; 98, None; 99, block; 99, 100; 100, expression_statement; 100, 101; 101, call; 101, 102; 101, 103; 102, identifier:sleep; 103, argument_list; 103, 104; 104, identifier:wait_time; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:to_remove; 108, call; 108, 109; 108, 110; 109, identifier:set; 110, argument_list; 111, expression_statement; 111, 112; 112, assignment; 112, 113; 112, 114; 113, identifier:now; 114, call; 114, 115; 114, 116; 115, identifier:monotonic; 116, argument_list; 117, with_statement; 117, 118; 117, 123; 118, with_clause; 118, 119; 119, with_item; 119, 120; 120, attribute; 120, 121; 120, 122; 121, identifier:self; 122, identifier:_scan_lock; 123, block; 123, 124; 123, 150; 123, 160; 124, for_statement; 124, 125; 124, 128; 124, 135; 125, pattern_list; 125, 126; 125, 127; 126, identifier:name; 127, identifier:value; 128, call; 128, 129; 128, 134; 129, attribute; 129, 130; 129, 133; 130, attribute; 130, 131; 130, 132; 131, identifier:self; 132, identifier:_scanned_devices; 133, identifier:items; 134, argument_list; 135, block; 135, 136; 136, if_statement; 136, 137; 136, 142; 137, comparison_operator:<; 137, 138; 137, 141; 138, subscript; 138, 139; 138, 140; 139, identifier:value; 140, string:'expiration_time'; 141, identifier:now; 142, block; 142, 143; 143, expression_statement; 143, 144; 144, call; 144, 145; 144, 148; 145, attribute; 145, 146; 145, 147; 146, identifier:to_remove; 147, identifier:add; 148, argument_list; 148, 149; 149, identifier:name; 150, for_statement; 150, 151; 150, 152; 150, 153; 151, identifier:name; 152, identifier:to_remove; 153, block; 153, 154; 154, delete_statement; 154, 155; 155, subscript; 155, 156; 155, 159; 156, attribute; 156, 157; 156, 158; 157, identifier:self; 158, identifier:_scanned_devices; 159, identifier:name; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:devices; 163, call; 163, 164; 163, 165; 164, identifier:sorted; 165, argument_list; 165, 166; 165, 173; 166, call; 166, 167; 166, 172; 167, attribute; 167, 168; 167, 171; 168, attribute; 168, 169; 168, 170; 169, identifier:self; 170, identifier:_scanned_devices; 171, identifier:values; 172, argument_list; 173, keyword_argument; 173, 174; 173, 175; 174, identifier:key; 175, lambda; 175, 176; 175, 178; 176, lambda_parameters; 176, 177; 177, identifier:x; 178, subscript; 178, 179; 178, 180; 179, identifier:x; 180, string:'uuid'; 181, return_statement; 181, 182; 182, identifier:devices | def scan(self, wait=None):
"""Return the devices that have been found for this device adapter.
If the adapter indicates that we need to explicitly tell it to probe for devices, probe now.
By default we return the list of seen devices immediately, however there are two cases where
we will sleep here for a fixed period of time to let devices show up in our result list:
- If we are probing then we wait for 'minimum_scan_time'
- If we are told an explicit wait time that overrides everything and we wait that long
"""
min_scan = self.adapter.get_config('minimum_scan_time', 0.0)
probe_required = self.adapter.get_config('probe_required', False)
# Figure out how long and if we need to wait before returning our scan results
wait_time = None
elapsed = monotonic() - self._start_time
if elapsed < min_scan:
wait_time = min_scan - elapsed
# If we need to probe for devices rather than letting them just bubble up, start the probe
# and then use our min_scan_time to wait for them to arrive via the normal _on_scan event
if probe_required:
self._loop.run_coroutine(self.adapter.probe())
wait_time = min_scan
# If an explicit wait is specified that overrides everything else
if wait is not None:
wait_time = wait
if wait_time is not None:
sleep(wait_time)
to_remove = set()
now = monotonic()
with self._scan_lock:
for name, value in self._scanned_devices.items():
if value['expiration_time'] < now:
to_remove.add(name)
for name in to_remove:
del self._scanned_devices[name]
devices = sorted(self._scanned_devices.values(), key=lambda x: x['uuid'])
return devices |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:send_rpc; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:self; 5, identifier:address; 6, identifier:rpc_id; 7, identifier:call_payload; 8, default_parameter; 8, 9; 8, 10; 9, identifier:timeout; 10, float:3.0; 11, block; 11, 12; 11, 14; 11, 25; 11, 34; 11, 39; 11, 43; 11, 47; 11, 58; 11, 83; 11, 133; 11, 157; 11, 168; 12, expression_statement; 12, 13; 13, comment; 14, if_statement; 14, 15; 14, 19; 15, not_operator; 15, 16; 16, attribute; 16, 17; 16, 18; 17, identifier:self; 18, identifier:connected; 19, block; 19, 20; 20, raise_statement; 20, 21; 21, call; 21, 22; 21, 23; 22, identifier:HardwareError; 23, argument_list; 23, 24; 24, string:"Cannot send an RPC if we are not in a connected state"; 25, if_statement; 25, 26; 25, 29; 26, comparison_operator:is; 26, 27; 26, 28; 27, identifier:timeout; 28, None; 29, block; 29, 30; 30, expression_statement; 30, 31; 31, assignment; 31, 32; 31, 33; 32, identifier:timeout; 33, float:3.0; 34, expression_statement; 34, 35; 35, assignment; 35, 36; 35, 37; 36, identifier:status; 37, unary_operator:-; 37, 38; 38, integer:1; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:payload; 42, string:b''; 43, expression_statement; 43, 44; 44, assignment; 44, 45; 44, 46; 45, identifier:recording; 46, None; 47, if_statement; 47, 48; 47, 51; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:connection_interrupted; 51, block; 51, 52; 52, expression_statement; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:_try_reconnect; 57, argument_list; 58, if_statement; 58, 59; 58, 64; 59, comparison_operator:is; 59, 60; 59, 63; 60, attribute; 60, 61; 60, 62; 61, identifier:self; 62, identifier:_record; 63, None; 64, block; 64, 65; 64, 77; 65, expression_statement; 65, 66; 66, assignment; 66, 67; 66, 68; 67, identifier:recording; 68, call; 68, 69; 68, 70; 69, identifier:_RecordedRPC; 70, argument_list; 70, 71; 70, 74; 70, 75; 70, 76; 71, attribute; 71, 72; 71, 73; 72, identifier:self; 73, identifier:connection_string; 74, identifier:address; 75, identifier:rpc_id; 76, identifier:call_payload; 77, expression_statement; 77, 78; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:recording; 81, identifier:start; 82, argument_list; 83, try_statement; 83, 84; 83, 117; 84, block; 84, 85; 84, 107; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:payload; 88, call; 88, 89; 88, 94; 89, attribute; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:self; 92, identifier:_loop; 93, identifier:run_coroutine; 94, argument_list; 94, 95; 95, call; 95, 96; 95, 101; 96, attribute; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:self; 99, identifier:adapter; 100, identifier:send_rpc; 101, argument_list; 101, 102; 101, 103; 101, 104; 101, 105; 101, 106; 102, integer:0; 103, identifier:address; 104, identifier:rpc_id; 105, identifier:call_payload; 106, identifier:timeout; 107, expression_statement; 107, 108; 108, assignment; 108, 109; 108, 112; 109, pattern_list; 109, 110; 109, 111; 110, identifier:status; 111, identifier:payload; 112, call; 112, 113; 112, 114; 113, identifier:pack_rpc_response; 114, argument_list; 114, 115; 114, 116; 115, identifier:payload; 116, None; 117, except_clause; 117, 118; 117, 122; 118, as_pattern; 118, 119; 118, 120; 119, identifier:VALID_RPC_EXCEPTIONS; 120, as_pattern_target; 120, 121; 121, identifier:exc; 122, block; 122, 123; 123, expression_statement; 123, 124; 124, assignment; 124, 125; 124, 128; 125, pattern_list; 125, 126; 125, 127; 126, identifier:status; 127, identifier:payload; 128, call; 128, 129; 128, 130; 129, identifier:pack_rpc_response; 130, argument_list; 130, 131; 130, 132; 131, identifier:payload; 132, identifier:exc; 133, if_statement; 133, 134; 133, 139; 134, comparison_operator:is; 134, 135; 134, 138; 135, attribute; 135, 136; 135, 137; 136, identifier:self; 137, identifier:_record; 138, None; 139, block; 139, 140; 139, 148; 140, expression_statement; 140, 141; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:recording; 144, identifier:finish; 145, argument_list; 145, 146; 145, 147; 146, identifier:status; 147, identifier:payload; 148, expression_statement; 148, 149; 149, call; 149, 150; 149, 155; 150, attribute; 150, 151; 150, 154; 151, attribute; 151, 152; 151, 153; 152, identifier:self; 153, identifier:_recording; 154, identifier:append; 155, argument_list; 155, 156; 156, identifier:recording; 157, if_statement; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:self; 160, identifier:connection_interrupted; 161, block; 161, 162; 162, expression_statement; 162, 163; 163, call; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:self; 166, identifier:_try_reconnect; 167, argument_list; 168, return_statement; 168, 169; 169, call; 169, 170; 169, 171; 170, identifier:unpack_rpc_response; 171, argument_list; 171, 172; 171, 173; 171, 174; 171, 175; 172, identifier:status; 173, identifier:payload; 174, identifier:rpc_id; 175, identifier:address | def send_rpc(self, address, rpc_id, call_payload, timeout=3.0):
"""Send an rpc to our connected device.
The device must already be connected and the rpc interface open. This
method will synchronously send an RPC and wait for the response. Any
RPC errors will be raised as exceptions and if there were no errors, the
RPC's response payload will be returned as a binary bytearray.
See :meth:`AbstractDeviceAdapter.send_rpc` for documentation of the possible
exceptions that can be raised here.
Args:
address (int): The tile address containing the RPC
rpc_id (int): The ID of the RPC that we wish to call.
call_payload (bytes): The payload containing encoded arguments for the
RPC.
timeout (float): The maximum number of seconds to wait for the RPC to
finish. Defaults to 3s.
Returns:
bytearray: The RPC's response payload.
"""
if not self.connected:
raise HardwareError("Cannot send an RPC if we are not in a connected state")
if timeout is None:
timeout = 3.0
status = -1
payload = b''
recording = None
if self.connection_interrupted:
self._try_reconnect()
if self._record is not None:
recording = _RecordedRPC(self.connection_string, address, rpc_id, call_payload)
recording.start()
try:
payload = self._loop.run_coroutine(self.adapter.send_rpc(0, address, rpc_id, call_payload, timeout))
status, payload = pack_rpc_response(payload, None)
except VALID_RPC_EXCEPTIONS as exc:
status, payload = pack_rpc_response(payload, exc)
if self._record is not None:
recording.finish(status, payload)
self._recording.append(recording)
if self.connection_interrupted:
self._try_reconnect()
return unpack_rpc_response(status, payload, rpc_id, address) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:__xml_scan; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:node; 5, identifier:env; 6, identifier:path; 7, identifier:arg; 8, block; 8, 9; 8, 11; 8, 12; 8, 28; 8, 54; 8, 67; 8, 249; 8, 258; 8, 267; 8, 283; 8, 293; 8, 297; 8, 340; 8, 346; 8, 352; 8, 358; 9, expression_statement; 9, 10; 10, comment; 11, comment; 12, if_statement; 12, 13; 12, 25; 13, not_operator; 13, 14; 14, call; 14, 15; 14, 20; 15, attribute; 15, 16; 15, 19; 16, attribute; 16, 17; 16, 18; 17, identifier:os; 18, identifier:path; 19, identifier:isfile; 20, argument_list; 20, 21; 21, call; 21, 22; 21, 23; 22, identifier:str; 23, argument_list; 23, 24; 24, identifier:node; 25, block; 25, 26; 26, return_statement; 26, 27; 27, list:[]; 28, if_statement; 28, 29; 28, 36; 28, 37; 28, 38; 29, call; 29, 30; 29, 33; 30, attribute; 30, 31; 30, 32; 31, identifier:env; 32, identifier:get; 33, argument_list; 33, 34; 33, 35; 34, string:'DOCBOOK_SCANENT'; 35, string:''; 36, comment; 37, comment; 38, block; 38, 39; 38, 47; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:contents; 42, call; 42, 43; 42, 46; 43, attribute; 43, 44; 43, 45; 44, identifier:node; 45, identifier:get_text_contents; 46, argument_list; 47, return_statement; 47, 48; 48, call; 48, 49; 48, 52; 49, attribute; 49, 50; 49, 51; 50, identifier:sentity_re; 51, identifier:findall; 52, argument_list; 52, 53; 53, identifier:contents; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:xsl_file; 57, call; 57, 58; 57, 63; 58, attribute; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:os; 61, identifier:path; 62, identifier:join; 63, argument_list; 63, 64; 63, 65; 63, 66; 64, identifier:scriptpath; 65, string:'utils'; 66, string:'xmldepend.xsl'; 67, if_statement; 67, 68; 67, 72; 68, boolean_operator:or; 68, 69; 68, 71; 69, not_operator; 69, 70; 70, identifier:has_libxml2; 71, identifier:prefer_xsltproc; 72, block; 72, 73; 73, if_statement; 73, 74; 73, 78; 73, 151; 74, boolean_operator:and; 74, 75; 74, 76; 75, identifier:has_lxml; 76, not_operator; 76, 77; 77, identifier:prefer_xsltproc; 78, block; 78, 79; 78, 84; 78, 93; 78, 105; 78, 114; 78, 149; 79, import_from_statement; 79, 80; 79, 82; 80, dotted_name; 80, 81; 81, identifier:lxml; 82, dotted_name; 82, 83; 83, identifier:etree; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:xsl_tree; 87, call; 87, 88; 87, 91; 88, attribute; 88, 89; 88, 90; 89, identifier:etree; 90, identifier:parse; 91, argument_list; 91, 92; 92, identifier:xsl_file; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:doc; 96, call; 96, 97; 96, 100; 97, attribute; 97, 98; 97, 99; 98, identifier:etree; 99, identifier:parse; 100, argument_list; 100, 101; 101, call; 101, 102; 101, 103; 102, identifier:str; 103, argument_list; 103, 104; 104, identifier:node; 105, expression_statement; 105, 106; 106, assignment; 106, 107; 106, 108; 107, identifier:result; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:doc; 111, identifier:xslt; 112, argument_list; 112, 113; 113, identifier:xsl_tree; 114, expression_statement; 114, 115; 115, assignment; 115, 116; 115, 117; 116, identifier:depfiles; 117, list_comprehension; 117, 118; 117, 123; 117, 133; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:x; 121, identifier:strip; 122, argument_list; 123, for_in_clause; 123, 124; 123, 125; 124, identifier:x; 125, call; 125, 126; 125, 132; 126, attribute; 126, 127; 126, 131; 127, call; 127, 128; 127, 129; 128, identifier:str; 129, argument_list; 129, 130; 130, identifier:result; 131, identifier:splitlines; 132, argument_list; 133, if_clause; 133, 134; 134, boolean_operator:and; 134, 135; 134, 142; 135, comparison_operator:!=; 135, 136; 135, 141; 136, call; 136, 137; 136, 140; 137, attribute; 137, 138; 137, 139; 138, identifier:x; 139, identifier:strip; 140, argument_list; 141, string:""; 142, not_operator; 142, 143; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:x; 146, identifier:startswith; 147, argument_list; 147, 148; 148, string:"<?xml "; 149, return_statement; 149, 150; 150, identifier:depfiles; 151, else_clause; 151, 152; 151, 153; 152, comment; 153, block; 153, 154; 153, 163; 154, expression_statement; 154, 155; 155, assignment; 155, 156; 155, 157; 156, identifier:xsltproc; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:env; 160, identifier:subst; 161, argument_list; 161, 162; 162, string:"$DOCBOOK_XSLTPROC"; 163, if_statement; 163, 164; 163, 172; 163, 230; 164, boolean_operator:and; 164, 165; 164, 166; 165, identifier:xsltproc; 166, call; 166, 167; 166, 170; 167, attribute; 167, 168; 167, 169; 168, identifier:xsltproc; 169, identifier:endswith; 170, argument_list; 170, 171; 171, string:'xsltproc'; 172, block; 172, 173; 172, 193; 172, 228; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 176; 175, identifier:result; 176, call; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:env; 179, identifier:backtick; 180, argument_list; 180, 181; 181, call; 181, 182; 181, 185; 182, attribute; 182, 183; 182, 184; 183, string:' '; 184, identifier:join; 185, argument_list; 185, 186; 186, list:[xsltproc, xsl_file, str(node)]; 186, 187; 186, 188; 186, 189; 187, identifier:xsltproc; 188, identifier:xsl_file; 189, call; 189, 190; 189, 191; 190, identifier:str; 191, argument_list; 191, 192; 192, identifier:node; 193, expression_statement; 193, 194; 194, assignment; 194, 195; 194, 196; 195, identifier:depfiles; 196, list_comprehension; 196, 197; 196, 202; 196, 212; 197, call; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:x; 200, identifier:strip; 201, argument_list; 202, for_in_clause; 202, 203; 202, 204; 203, identifier:x; 204, call; 204, 205; 204, 211; 205, attribute; 205, 206; 205, 210; 206, call; 206, 207; 206, 208; 207, identifier:str; 208, argument_list; 208, 209; 209, identifier:result; 210, identifier:splitlines; 211, argument_list; 212, if_clause; 212, 213; 213, boolean_operator:and; 213, 214; 213, 221; 214, comparison_operator:!=; 214, 215; 214, 220; 215, call; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:x; 218, identifier:strip; 219, argument_list; 220, string:""; 221, not_operator; 221, 222; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:x; 225, identifier:startswith; 226, argument_list; 226, 227; 227, string:"<?xml "; 228, return_statement; 228, 229; 229, identifier:depfiles; 230, else_clause; 230, 231; 230, 232; 230, 233; 231, comment; 232, comment; 233, block; 233, 234; 233, 242; 234, expression_statement; 234, 235; 235, assignment; 235, 236; 235, 237; 236, identifier:contents; 237, call; 237, 238; 237, 241; 238, attribute; 238, 239; 238, 240; 239, identifier:node; 240, identifier:get_text_contents; 241, argument_list; 242, return_statement; 242, 243; 243, call; 243, 244; 243, 247; 244, attribute; 244, 245; 244, 246; 245, identifier:include_re; 246, identifier:findall; 247, argument_list; 247, 248; 248, identifier:contents; 249, expression_statement; 249, 250; 250, assignment; 250, 251; 250, 252; 251, identifier:styledoc; 252, call; 252, 253; 252, 256; 253, attribute; 253, 254; 253, 255; 254, identifier:libxml2; 255, identifier:parseFile; 256, argument_list; 256, 257; 257, identifier:xsl_file; 258, expression_statement; 258, 259; 259, assignment; 259, 260; 259, 261; 260, identifier:style; 261, call; 261, 262; 261, 265; 262, attribute; 262, 263; 262, 264; 263, identifier:libxslt; 264, identifier:parseStylesheetDoc; 265, argument_list; 265, 266; 266, identifier:styledoc; 267, expression_statement; 267, 268; 268, assignment; 268, 269; 268, 270; 269, identifier:doc; 270, call; 270, 271; 270, 274; 271, attribute; 271, 272; 271, 273; 272, identifier:libxml2; 273, identifier:readFile; 274, argument_list; 274, 275; 274, 279; 274, 280; 275, call; 275, 276; 275, 277; 276, identifier:str; 277, argument_list; 277, 278; 278, identifier:node; 279, None; 280, attribute; 280, 281; 280, 282; 281, identifier:libxml2; 282, identifier:XML_PARSE_NOENT; 283, expression_statement; 283, 284; 284, assignment; 284, 285; 284, 286; 285, identifier:result; 286, call; 286, 287; 286, 290; 287, attribute; 287, 288; 287, 289; 288, identifier:style; 289, identifier:applyStylesheet; 290, argument_list; 290, 291; 290, 292; 291, identifier:doc; 292, None; 293, expression_statement; 293, 294; 294, assignment; 294, 295; 294, 296; 295, identifier:depfiles; 296, list:[]; 297, for_statement; 297, 298; 297, 299; 297, 307; 298, identifier:x; 299, call; 299, 300; 299, 306; 300, attribute; 300, 301; 300, 305; 301, call; 301, 302; 301, 303; 302, identifier:str; 303, argument_list; 303, 304; 304, identifier:result; 305, identifier:splitlines; 306, argument_list; 307, block; 307, 308; 308, if_statement; 308, 309; 308, 324; 309, boolean_operator:and; 309, 310; 309, 317; 310, comparison_operator:!=; 310, 311; 310, 316; 311, call; 311, 312; 311, 315; 312, attribute; 312, 313; 312, 314; 313, identifier:x; 314, identifier:strip; 315, argument_list; 316, string:""; 317, not_operator; 317, 318; 318, call; 318, 319; 318, 322; 319, attribute; 319, 320; 319, 321; 320, identifier:x; 321, identifier:startswith; 322, argument_list; 322, 323; 323, string:"<?xml "; 324, block; 324, 325; 325, expression_statement; 325, 326; 326, call; 326, 327; 326, 330; 327, attribute; 327, 328; 327, 329; 328, identifier:depfiles; 329, identifier:extend; 330, argument_list; 330, 331; 331, call; 331, 332; 331, 339; 332, attribute; 332, 333; 332, 338; 333, call; 333, 334; 333, 337; 334, attribute; 334, 335; 334, 336; 335, identifier:x; 336, identifier:strip; 337, argument_list; 338, identifier:split; 339, argument_list; 340, expression_statement; 340, 341; 341, call; 341, 342; 341, 345; 342, attribute; 342, 343; 342, 344; 343, identifier:style; 344, identifier:freeStylesheet; 345, argument_list; 346, expression_statement; 346, 347; 347, call; 347, 348; 347, 351; 348, attribute; 348, 349; 348, 350; 349, identifier:doc; 350, identifier:freeDoc; 351, argument_list; 352, expression_statement; 352, 353; 353, call; 353, 354; 353, 357; 354, attribute; 354, 355; 354, 356; 355, identifier:result; 356, identifier:freeDoc; 357, argument_list; 358, return_statement; 358, 359; 359, identifier:depfiles | def __xml_scan(node, env, path, arg):
""" Simple XML file scanner, detecting local images and XIncludes as implicit dependencies. """
# Does the node exist yet?
if not os.path.isfile(str(node)):
return []
if env.get('DOCBOOK_SCANENT',''):
# Use simple pattern matching for system entities..., no support
# for recursion yet.
contents = node.get_text_contents()
return sentity_re.findall(contents)
xsl_file = os.path.join(scriptpath,'utils','xmldepend.xsl')
if not has_libxml2 or prefer_xsltproc:
if has_lxml and not prefer_xsltproc:
from lxml import etree
xsl_tree = etree.parse(xsl_file)
doc = etree.parse(str(node))
result = doc.xslt(xsl_tree)
depfiles = [x.strip() for x in str(result).splitlines() if x.strip() != "" and not x.startswith("<?xml ")]
return depfiles
else:
# Try to call xsltproc
xsltproc = env.subst("$DOCBOOK_XSLTPROC")
if xsltproc and xsltproc.endswith('xsltproc'):
result = env.backtick(' '.join([xsltproc, xsl_file, str(node)]))
depfiles = [x.strip() for x in str(result).splitlines() if x.strip() != "" and not x.startswith("<?xml ")]
return depfiles
else:
# Use simple pattern matching, there is currently no support
# for xi:includes...
contents = node.get_text_contents()
return include_re.findall(contents)
styledoc = libxml2.parseFile(xsl_file)
style = libxslt.parseStylesheetDoc(styledoc)
doc = libxml2.readFile(str(node), None, libxml2.XML_PARSE_NOENT)
result = style.applyStylesheet(doc, None)
depfiles = []
for x in str(result).splitlines():
if x.strip() != "" and not x.startswith("<?xml "):
depfiles.extend(x.strip().split())
style.freeStylesheet()
doc.freeDoc()
result.freeDoc()
return depfiles |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:DocbookMan; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 11; 4, identifier:env; 5, identifier:target; 6, default_parameter; 6, 7; 6, 8; 7, identifier:source; 8, None; 9, list_splat_pattern; 9, 10; 10, identifier:args; 11, dictionary_splat_pattern; 11, 12; 12, identifier:kw; 13, block; 13, 14; 13, 16; 13, 17; 13, 27; 13, 28; 13, 38; 13, 39; 13, 48; 13, 49; 13, 53; 13, 377; 14, expression_statement; 14, 15; 15, comment; 16, comment; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 22; 19, pattern_list; 19, 20; 19, 21; 20, identifier:target; 21, identifier:source; 22, call; 22, 23; 22, 24; 23, identifier:__extend_targets_sources; 24, argument_list; 24, 25; 24, 26; 25, identifier:target; 26, identifier:source; 27, comment; 28, expression_statement; 28, 29; 29, call; 29, 30; 29, 31; 30, identifier:__init_xsl_stylesheet; 31, argument_list; 31, 32; 31, 33; 31, 34; 31, 35; 32, identifier:kw; 33, identifier:env; 34, string:'$DOCBOOK_DEFAULT_XSL_MAN'; 35, list:['manpages','docbook.xsl']; 35, 36; 35, 37; 36, string:'manpages'; 37, string:'docbook.xsl'; 38, comment; 39, expression_statement; 39, 40; 40, assignment; 40, 41; 40, 42; 41, identifier:__builder; 42, call; 42, 43; 42, 44; 43, identifier:__select_builder; 44, argument_list; 44, 45; 44, 46; 44, 47; 45, identifier:__lxml_builder; 46, identifier:__libxml2_builder; 47, identifier:__xsltproc_builder; 48, comment; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:result; 52, list:[]; 53, for_statement; 53, 54; 53, 57; 53, 62; 54, pattern_list; 54, 55; 54, 56; 55, identifier:t; 56, identifier:s; 57, call; 57, 58; 57, 59; 58, identifier:zip; 59, argument_list; 59, 60; 59, 61; 60, identifier:target; 61, identifier:source; 62, block; 62, 63; 62, 67; 62, 71; 62, 82; 62, 321; 62, 334; 62, 346; 62, 355; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 66; 65, identifier:volnum; 66, string:"1"; 67, expression_statement; 67, 68; 68, assignment; 68, 69; 68, 70; 69, identifier:outfiles; 70, list:[]; 71, expression_statement; 71, 72; 72, assignment; 72, 73; 72, 74; 73, identifier:srcfile; 74, call; 74, 75; 74, 76; 75, identifier:__ensure_suffix; 76, argument_list; 76, 77; 76, 81; 77, call; 77, 78; 77, 79; 78, identifier:str; 79, argument_list; 79, 80; 80, identifier:s; 81, string:'.xml'; 82, if_statement; 82, 83; 82, 91; 82, 311; 83, call; 83, 84; 83, 89; 84, attribute; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:os; 87, identifier:path; 88, identifier:isfile; 89, argument_list; 89, 90; 90, identifier:srcfile; 91, block; 91, 92; 91, 253; 92, try_statement; 92, 93; 92, 178; 93, block; 93, 94; 93, 99; 93, 119; 93, 120; 93, 145; 93, 146; 94, import_statement; 94, 95; 95, dotted_name; 95, 96; 95, 97; 95, 98; 96, identifier:xml; 97, identifier:dom; 98, identifier:minidom; 99, expression_statement; 99, 100; 100, assignment; 100, 101; 100, 102; 101, identifier:dom; 102, call; 102, 103; 102, 110; 103, attribute; 103, 104; 103, 109; 104, attribute; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:xml; 107, identifier:dom; 108, identifier:minidom; 109, identifier:parse; 110, argument_list; 110, 111; 111, call; 111, 112; 111, 113; 112, identifier:__ensure_suffix; 113, argument_list; 113, 114; 113, 118; 114, call; 114, 115; 114, 116; 115, identifier:str; 116, argument_list; 116, 117; 117, identifier:s; 118, string:'.xml'; 119, comment; 120, for_statement; 120, 121; 120, 122; 120, 128; 121, identifier:node; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:dom; 125, identifier:getElementsByTagName; 126, argument_list; 126, 127; 127, string:'refmeta'; 128, block; 128, 129; 129, for_statement; 129, 130; 129, 131; 129, 137; 130, identifier:vol; 131, call; 131, 132; 131, 135; 132, attribute; 132, 133; 132, 134; 133, identifier:node; 134, identifier:getElementsByTagName; 135, argument_list; 135, 136; 136, string:'manvolnum'; 137, block; 137, 138; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:volnum; 141, call; 141, 142; 141, 143; 142, identifier:__get_xml_text; 143, argument_list; 143, 144; 144, identifier:vol; 145, comment; 146, for_statement; 146, 147; 146, 148; 146, 154; 147, identifier:node; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:dom; 151, identifier:getElementsByTagName; 152, argument_list; 152, 153; 153, string:'refnamediv'; 154, block; 154, 155; 155, for_statement; 155, 156; 155, 157; 155, 163; 156, identifier:ref; 157, call; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:node; 160, identifier:getElementsByTagName; 161, argument_list; 161, 162; 162, string:'refname'; 163, block; 163, 164; 164, expression_statement; 164, 165; 165, call; 165, 166; 165, 169; 166, attribute; 166, 167; 166, 168; 167, identifier:outfiles; 168, identifier:append; 169, argument_list; 169, 170; 170, binary_operator:+; 170, 171; 170, 177; 171, binary_operator:+; 171, 172; 171, 176; 172, call; 172, 173; 172, 174; 173, identifier:__get_xml_text; 174, argument_list; 174, 175; 175, identifier:ref; 176, string:'.'; 177, identifier:volnum; 178, except_clause; 178, 179; 178, 180; 179, comment; 180, block; 180, 181; 180, 196; 180, 204; 180, 210; 180, 228; 181, expression_statement; 181, 182; 182, assignment; 182, 183; 182, 184; 183, identifier:f; 184, call; 184, 185; 184, 186; 185, identifier:open; 186, argument_list; 186, 187; 186, 195; 187, call; 187, 188; 187, 189; 188, identifier:__ensure_suffix; 189, argument_list; 189, 190; 189, 194; 190, call; 190, 191; 190, 192; 191, identifier:str; 192, argument_list; 192, 193; 193, identifier:s; 194, string:'.xml'; 195, string:'r'; 196, expression_statement; 196, 197; 197, assignment; 197, 198; 197, 199; 198, identifier:content; 199, call; 199, 200; 199, 203; 200, attribute; 200, 201; 200, 202; 201, identifier:f; 202, identifier:read; 203, argument_list; 204, expression_statement; 204, 205; 205, call; 205, 206; 205, 209; 206, attribute; 206, 207; 206, 208; 207, identifier:f; 208, identifier:close; 209, argument_list; 210, for_statement; 210, 211; 210, 212; 210, 218; 211, identifier:m; 212, call; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:re_manvolnum; 215, identifier:finditer; 216, argument_list; 216, 217; 217, identifier:content; 218, block; 218, 219; 219, expression_statement; 219, 220; 220, assignment; 220, 221; 220, 222; 221, identifier:volnum; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:m; 225, identifier:group; 226, argument_list; 226, 227; 227, integer:1; 228, for_statement; 228, 229; 228, 230; 228, 236; 229, identifier:m; 230, call; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:re_refname; 233, identifier:finditer; 234, argument_list; 234, 235; 235, identifier:content; 236, block; 236, 237; 237, expression_statement; 237, 238; 238, call; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:outfiles; 241, identifier:append; 242, argument_list; 242, 243; 243, binary_operator:+; 243, 244; 243, 252; 244, binary_operator:+; 244, 245; 244, 251; 245, call; 245, 246; 245, 249; 246, attribute; 246, 247; 246, 248; 247, identifier:m; 248, identifier:group; 249, argument_list; 249, 250; 250, integer:1; 251, string:'.'; 252, identifier:volnum; 253, if_statement; 253, 254; 253, 256; 253, 257; 254, not_operator; 254, 255; 255, identifier:outfiles; 256, comment; 257, block; 257, 258; 257, 265; 258, expression_statement; 258, 259; 259, assignment; 259, 260; 259, 261; 260, identifier:spath; 261, call; 261, 262; 261, 263; 262, identifier:str; 263, argument_list; 263, 264; 264, identifier:s; 265, if_statement; 265, 266; 265, 273; 265, 285; 266, not_operator; 266, 267; 267, call; 267, 268; 267, 271; 268, attribute; 268, 269; 268, 270; 269, identifier:spath; 270, identifier:endswith; 271, argument_list; 271, 272; 272, string:'.xml'; 273, block; 273, 274; 274, expression_statement; 274, 275; 275, call; 275, 276; 275, 279; 276, attribute; 276, 277; 276, 278; 277, identifier:outfiles; 278, identifier:append; 279, argument_list; 279, 280; 280, binary_operator:+; 280, 281; 280, 284; 281, binary_operator:+; 281, 282; 281, 283; 282, identifier:spath; 283, string:'.'; 284, identifier:volnum; 285, else_clause; 285, 286; 286, block; 286, 287; 286, 300; 287, expression_statement; 287, 288; 288, assignment; 288, 289; 288, 292; 289, pattern_list; 289, 290; 289, 291; 290, identifier:stem; 291, identifier:ext; 292, call; 292, 293; 292, 298; 293, attribute; 293, 294; 293, 297; 294, attribute; 294, 295; 294, 296; 295, identifier:os; 296, identifier:path; 297, identifier:splitext; 298, argument_list; 298, 299; 299, identifier:spath; 300, expression_statement; 300, 301; 301, call; 301, 302; 301, 305; 302, attribute; 302, 303; 302, 304; 303, identifier:outfiles; 304, identifier:append; 305, argument_list; 305, 306; 306, binary_operator:+; 306, 307; 306, 310; 307, binary_operator:+; 307, 308; 307, 309; 308, identifier:stem; 309, string:'.'; 310, identifier:volnum; 311, else_clause; 311, 312; 311, 313; 312, comment; 313, block; 313, 314; 314, expression_statement; 314, 315; 315, call; 315, 316; 315, 319; 316, attribute; 316, 317; 316, 318; 317, identifier:outfiles; 318, identifier:append; 319, argument_list; 319, 320; 320, identifier:t; 321, expression_statement; 321, 322; 322, call; 322, 323; 322, 326; 323, attribute; 323, 324; 323, 325; 324, identifier:__builder; 325, identifier:__call__; 326, argument_list; 326, 327; 326, 328; 326, 331; 326, 332; 327, identifier:env; 328, subscript; 328, 329; 328, 330; 329, identifier:outfiles; 330, integer:0; 331, identifier:s; 332, dictionary_splat; 332, 333; 333, identifier:kw; 334, expression_statement; 334, 335; 335, call; 335, 336; 335, 339; 336, attribute; 336, 337; 336, 338; 337, identifier:env; 338, identifier:Depends; 339, argument_list; 339, 340; 339, 343; 340, subscript; 340, 341; 340, 342; 341, identifier:outfiles; 342, integer:0; 343, subscript; 343, 344; 343, 345; 344, identifier:kw; 345, string:'DOCBOOK_XSL'; 346, expression_statement; 346, 347; 347, call; 347, 348; 347, 351; 348, attribute; 348, 349; 348, 350; 349, identifier:result; 350, identifier:append; 351, argument_list; 351, 352; 352, subscript; 352, 353; 352, 354; 353, identifier:outfiles; 354, integer:0; 355, if_statement; 355, 356; 355, 362; 356, comparison_operator:>; 356, 357; 356, 361; 357, call; 357, 358; 357, 359; 358, identifier:len; 359, argument_list; 359, 360; 360, identifier:outfiles; 361, integer:1; 362, block; 362, 363; 363, expression_statement; 363, 364; 364, call; 364, 365; 364, 368; 365, attribute; 365, 366; 365, 367; 366, identifier:env; 367, identifier:Clean; 368, argument_list; 368, 369; 368, 372; 369, subscript; 369, 370; 369, 371; 370, identifier:outfiles; 371, integer:0; 372, subscript; 372, 373; 372, 374; 373, identifier:outfiles; 374, slice; 374, 375; 374, 376; 375, integer:1; 376, colon; 377, return_statement; 377, 378; 378, identifier:result | def DocbookMan(env, target, source=None, *args, **kw):
"""
A pseudo-Builder, providing a Docbook toolchain for Man page output.
"""
# Init list of targets/sources
target, source = __extend_targets_sources(target, source)
# Init XSL stylesheet
__init_xsl_stylesheet(kw, env, '$DOCBOOK_DEFAULT_XSL_MAN', ['manpages','docbook.xsl'])
# Setup builder
__builder = __select_builder(__lxml_builder, __libxml2_builder, __xsltproc_builder)
# Create targets
result = []
for t,s in zip(target,source):
volnum = "1"
outfiles = []
srcfile = __ensure_suffix(str(s),'.xml')
if os.path.isfile(srcfile):
try:
import xml.dom.minidom
dom = xml.dom.minidom.parse(__ensure_suffix(str(s),'.xml'))
# Extract volume number, default is 1
for node in dom.getElementsByTagName('refmeta'):
for vol in node.getElementsByTagName('manvolnum'):
volnum = __get_xml_text(vol)
# Extract output filenames
for node in dom.getElementsByTagName('refnamediv'):
for ref in node.getElementsByTagName('refname'):
outfiles.append(__get_xml_text(ref)+'.'+volnum)
except:
# Use simple regex parsing
f = open(__ensure_suffix(str(s),'.xml'), 'r')
content = f.read()
f.close()
for m in re_manvolnum.finditer(content):
volnum = m.group(1)
for m in re_refname.finditer(content):
outfiles.append(m.group(1)+'.'+volnum)
if not outfiles:
# Use stem of the source file
spath = str(s)
if not spath.endswith('.xml'):
outfiles.append(spath+'.'+volnum)
else:
stem, ext = os.path.splitext(spath)
outfiles.append(stem+'.'+volnum)
else:
# We have to completely rely on the given target name
outfiles.append(t)
__builder.__call__(env, outfiles[0], s, **kw)
env.Depends(outfiles[0], kw['DOCBOOK_XSL'])
result.append(outfiles[0])
if len(outfiles) > 1:
env.Clean(outfiles[0], outfiles[1:])
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:Builder; 3, parameters; 3, 4; 4, dictionary_splat_pattern; 4, 5; 5, identifier:kw; 6, block; 6, 7; 6, 9; 6, 13; 6, 135; 6, 229; 6, 237; 6, 251; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:composite; 12, None; 13, if_statement; 13, 14; 13, 17; 13, 48; 14, comparison_operator:in; 14, 15; 14, 16; 15, string:'generator'; 16, identifier:kw; 17, block; 17, 18; 17, 28; 17, 44; 18, if_statement; 18, 19; 18, 22; 19, comparison_operator:in; 19, 20; 19, 21; 20, string:'action'; 21, identifier:kw; 22, block; 22, 23; 23, raise_statement; 23, 24; 24, call; 24, 25; 24, 26; 25, identifier:UserError; 26, argument_list; 26, 27; 27, string:"You must not specify both an action and a generator."; 28, expression_statement; 28, 29; 29, assignment; 29, 30; 29, 33; 30, subscript; 30, 31; 30, 32; 31, identifier:kw; 32, string:'action'; 33, call; 33, 34; 33, 39; 34, attribute; 34, 35; 34, 38; 35, attribute; 35, 36; 35, 37; 36, identifier:SCons; 37, identifier:Action; 38, identifier:CommandGeneratorAction; 39, argument_list; 39, 40; 39, 43; 40, subscript; 40, 41; 40, 42; 41, identifier:kw; 42, string:'generator'; 43, dictionary; 44, delete_statement; 44, 45; 45, subscript; 45, 46; 45, 47; 46, identifier:kw; 47, string:'generator'; 48, elif_clause; 48, 49; 48, 52; 49, comparison_operator:in; 49, 50; 49, 51; 50, string:'action'; 51, identifier:kw; 52, block; 52, 53; 52, 63; 52, 72; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:source_ext_match; 56, call; 56, 57; 56, 60; 57, attribute; 57, 58; 57, 59; 58, identifier:kw; 59, identifier:get; 60, argument_list; 60, 61; 60, 62; 61, string:'source_ext_match'; 62, integer:1; 63, if_statement; 63, 64; 63, 67; 64, comparison_operator:in; 64, 65; 64, 66; 65, string:'source_ext_match'; 66, identifier:kw; 67, block; 67, 68; 68, delete_statement; 68, 69; 69, subscript; 69, 70; 69, 71; 70, identifier:kw; 71, string:'source_ext_match'; 72, if_statement; 72, 73; 72, 83; 72, 118; 73, call; 73, 74; 73, 79; 74, attribute; 74, 75; 74, 78; 75, attribute; 75, 76; 75, 77; 76, identifier:SCons; 77, identifier:Util; 78, identifier:is_Dict; 79, argument_list; 79, 80; 80, subscript; 80, 81; 80, 82; 81, identifier:kw; 82, string:'action'; 83, block; 83, 84; 83, 94; 83, 108; 84, expression_statement; 84, 85; 85, assignment; 85, 86; 85, 87; 86, identifier:composite; 87, call; 87, 88; 87, 89; 88, identifier:DictCmdGenerator; 89, argument_list; 89, 90; 89, 93; 90, subscript; 90, 91; 90, 92; 91, identifier:kw; 92, string:'action'; 93, identifier:source_ext_match; 94, expression_statement; 94, 95; 95, assignment; 95, 96; 95, 99; 96, subscript; 96, 97; 96, 98; 97, identifier:kw; 98, string:'action'; 99, call; 99, 100; 99, 105; 100, attribute; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:SCons; 103, identifier:Action; 104, identifier:CommandGeneratorAction; 105, argument_list; 105, 106; 105, 107; 106, identifier:composite; 107, dictionary; 108, expression_statement; 108, 109; 109, assignment; 109, 110; 109, 113; 110, subscript; 110, 111; 110, 112; 111, identifier:kw; 112, string:'src_suffix'; 113, call; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:composite; 116, identifier:src_suffixes; 117, argument_list; 118, else_clause; 118, 119; 119, block; 119, 120; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 125; 122, subscript; 122, 123; 122, 124; 123, identifier:kw; 124, string:'action'; 125, call; 125, 126; 125, 131; 126, attribute; 126, 127; 126, 130; 127, attribute; 127, 128; 127, 129; 128, identifier:SCons; 129, identifier:Action; 130, identifier:Action; 131, argument_list; 131, 132; 132, subscript; 132, 133; 132, 134; 133, identifier:kw; 134, string:'action'; 135, if_statement; 135, 136; 135, 139; 136, comparison_operator:in; 136, 137; 136, 138; 137, string:'emitter'; 138, identifier:kw; 139, block; 139, 140; 139, 146; 140, expression_statement; 140, 141; 141, assignment; 141, 142; 141, 143; 142, identifier:emitter; 143, subscript; 143, 144; 143, 145; 144, identifier:kw; 145, string:'emitter'; 146, if_statement; 146, 147; 146, 155; 146, 156; 146, 157; 146, 158; 146, 159; 146, 191; 146, 210; 147, call; 147, 148; 147, 153; 148, attribute; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:SCons; 151, identifier:Util; 152, identifier:is_String; 153, argument_list; 153, 154; 154, identifier:emitter; 155, comment; 156, comment; 157, comment; 158, comment; 159, block; 159, 160; 159, 171; 159, 182; 160, expression_statement; 160, 161; 161, assignment; 161, 162; 161, 163; 162, identifier:var; 163, call; 163, 164; 163, 169; 164, attribute; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:SCons; 167, identifier:Util; 168, identifier:get_environment_var; 169, argument_list; 169, 170; 170, identifier:emitter; 171, if_statement; 171, 172; 171, 174; 172, not_operator; 172, 173; 173, identifier:var; 174, block; 174, 175; 175, raise_statement; 175, 176; 176, call; 176, 177; 176, 178; 177, identifier:UserError; 178, argument_list; 178, 179; 179, binary_operator:%; 179, 180; 179, 181; 180, string:"Supplied emitter '%s' does not appear to refer to an Environment variable"; 181, identifier:emitter; 182, expression_statement; 182, 183; 183, assignment; 183, 184; 183, 187; 184, subscript; 184, 185; 184, 186; 185, identifier:kw; 186, string:'emitter'; 187, call; 187, 188; 187, 189; 188, identifier:EmitterProxy; 189, argument_list; 189, 190; 190, identifier:var; 191, elif_clause; 191, 192; 191, 200; 192, call; 192, 193; 192, 198; 193, attribute; 193, 194; 193, 197; 194, attribute; 194, 195; 194, 196; 195, identifier:SCons; 196, identifier:Util; 197, identifier:is_Dict; 198, argument_list; 198, 199; 199, identifier:emitter; 200, block; 200, 201; 201, expression_statement; 201, 202; 202, assignment; 202, 203; 202, 206; 203, subscript; 203, 204; 203, 205; 204, identifier:kw; 205, string:'emitter'; 206, call; 206, 207; 206, 208; 207, identifier:DictEmitter; 208, argument_list; 208, 209; 209, identifier:emitter; 210, elif_clause; 210, 211; 210, 219; 211, call; 211, 212; 211, 217; 212, attribute; 212, 213; 212, 216; 213, attribute; 213, 214; 213, 215; 214, identifier:SCons; 215, identifier:Util; 216, identifier:is_List; 217, argument_list; 217, 218; 218, identifier:emitter; 219, block; 219, 220; 220, expression_statement; 220, 221; 221, assignment; 221, 222; 221, 225; 222, subscript; 222, 223; 222, 224; 223, identifier:kw; 224, string:'emitter'; 225, call; 225, 226; 225, 227; 226, identifier:ListEmitter; 227, argument_list; 227, 228; 228, identifier:emitter; 229, expression_statement; 229, 230; 230, assignment; 230, 231; 230, 232; 231, identifier:result; 232, call; 232, 233; 232, 234; 233, identifier:BuilderBase; 234, argument_list; 234, 235; 235, dictionary_splat; 235, 236; 236, identifier:kw; 237, if_statement; 237, 238; 237, 242; 238, not_operator; 238, 239; 239, comparison_operator:is; 239, 240; 239, 241; 240, identifier:composite; 241, None; 242, block; 242, 243; 243, expression_statement; 243, 244; 244, assignment; 244, 245; 244, 246; 245, identifier:result; 246, call; 246, 247; 246, 248; 247, identifier:CompositeBuilder; 248, argument_list; 248, 249; 248, 250; 249, identifier:result; 250, identifier:composite; 251, return_statement; 251, 252; 252, identifier:result | def Builder(**kw):
"""A factory for builder objects."""
composite = None
if 'generator' in kw:
if 'action' in kw:
raise UserError("You must not specify both an action and a generator.")
kw['action'] = SCons.Action.CommandGeneratorAction(kw['generator'], {})
del kw['generator']
elif 'action' in kw:
source_ext_match = kw.get('source_ext_match', 1)
if 'source_ext_match' in kw:
del kw['source_ext_match']
if SCons.Util.is_Dict(kw['action']):
composite = DictCmdGenerator(kw['action'], source_ext_match)
kw['action'] = SCons.Action.CommandGeneratorAction(composite, {})
kw['src_suffix'] = composite.src_suffixes()
else:
kw['action'] = SCons.Action.Action(kw['action'])
if 'emitter' in kw:
emitter = kw['emitter']
if SCons.Util.is_String(emitter):
# This allows users to pass in an Environment
# variable reference (like "$FOO") as an emitter.
# We will look in that Environment variable for
# a callable to use as the actual emitter.
var = SCons.Util.get_environment_var(emitter)
if not var:
raise UserError("Supplied emitter '%s' does not appear to refer to an Environment variable" % emitter)
kw['emitter'] = EmitterProxy(var)
elif SCons.Util.is_Dict(emitter):
kw['emitter'] = DictEmitter(emitter)
elif SCons.Util.is_List(emitter):
kw['emitter'] = ListEmitter(emitter)
result = BuilderBase(**kw)
if not composite is None:
result = CompositeBuilder(result, composite)
return result |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_node_errors; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:builder; 5, identifier:env; 6, identifier:tlist; 7, identifier:slist; 8, block; 8, 9; 8, 11; 8, 12; 8, 13; 8, 334; 9, expression_statement; 9, 10; 10, comment; 11, comment; 12, comment; 13, for_statement; 13, 14; 13, 15; 13, 16; 14, identifier:t; 15, identifier:tlist; 16, block; 16, 17; 16, 29; 17, if_statement; 17, 18; 17, 21; 18, attribute; 18, 19; 18, 20; 19, identifier:t; 20, identifier:side_effect; 21, block; 21, 22; 22, raise_statement; 22, 23; 23, call; 23, 24; 23, 25; 24, identifier:UserError; 25, argument_list; 25, 26; 26, binary_operator:%; 26, 27; 26, 28; 27, string:"Multiple ways to build the same target were specified for: %s"; 28, identifier:t; 29, if_statement; 29, 30; 29, 35; 29, 36; 29, 37; 30, call; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:t; 33, identifier:has_explicit_builder; 34, argument_list; 35, comment; 36, comment; 37, block; 37, 38; 37, 209; 38, if_statement; 38, 39; 38, 94; 39, parenthesized_expression; 39, 40; 40, boolean_operator:and; 40, 41; 40, 54; 40, 55; 40, 56; 41, boolean_operator:and; 41, 42; 41, 48; 42, not_operator; 42, 43; 43, comparison_operator:is; 43, 44; 43, 47; 44, attribute; 44, 45; 44, 46; 45, identifier:t; 46, identifier:env; 47, None; 48, not_operator; 48, 49; 49, comparison_operator:is; 49, 50; 49, 53; 50, attribute; 50, 51; 50, 52; 51, identifier:t; 52, identifier:env; 53, identifier:env; 54, comment; 55, comment; 56, not_operator; 56, 57; 57, parenthesized_expression; 57, 58; 58, boolean_operator:and; 58, 59; 58, 90; 59, boolean_operator:and; 59, 60; 59, 75; 60, comparison_operator:is; 60, 61; 60, 69; 61, call; 61, 62; 61, 63; 62, identifier:getattr; 63, argument_list; 63, 64; 63, 67; 63, 68; 64, attribute; 64, 65; 64, 66; 65, identifier:t; 66, identifier:env; 67, string:'__subject'; 68, integer:0; 69, call; 69, 70; 69, 71; 70, identifier:getattr; 71, argument_list; 71, 72; 71, 73; 71, 74; 72, identifier:env; 73, string:'__subject'; 74, integer:1; 75, comparison_operator:==; 75, 76; 75, 84; 76, call; 76, 77; 76, 78; 77, identifier:getattr; 78, argument_list; 78, 79; 78, 82; 78, 83; 79, attribute; 79, 80; 79, 81; 80, identifier:t; 81, identifier:env; 82, string:'overrides'; 83, integer:0; 84, call; 84, 85; 84, 86; 85, identifier:getattr; 86, argument_list; 86, 87; 86, 88; 86, 89; 87, identifier:env; 88, string:'overrides'; 89, integer:1; 90, not_operator; 90, 91; 91, attribute; 91, 92; 91, 93; 92, identifier:builder; 93, identifier:multi; 94, block; 94, 95; 94, 103; 94, 120; 94, 133; 95, expression_statement; 95, 96; 96, assignment; 96, 97; 96, 98; 97, identifier:action; 98, attribute; 98, 99; 98, 102; 99, attribute; 99, 100; 99, 101; 100, identifier:t; 101, identifier:builder; 102, identifier:action; 103, expression_statement; 103, 104; 104, assignment; 104, 105; 104, 106; 105, identifier:t_contents; 106, call; 106, 107; 106, 114; 107, attribute; 107, 108; 107, 113; 108, attribute; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:t; 111, identifier:builder; 112, identifier:action; 113, identifier:get_contents; 114, argument_list; 114, 115; 114, 116; 114, 117; 115, identifier:tlist; 116, identifier:slist; 117, attribute; 117, 118; 117, 119; 118, identifier:t; 119, identifier:env; 120, expression_statement; 120, 121; 121, assignment; 121, 122; 121, 123; 122, identifier:contents; 123, call; 123, 124; 123, 129; 124, attribute; 124, 125; 124, 128; 125, attribute; 125, 126; 125, 127; 126, identifier:builder; 127, identifier:action; 128, identifier:get_contents; 129, argument_list; 129, 130; 129, 131; 129, 132; 130, identifier:tlist; 131, identifier:slist; 132, identifier:env; 133, if_statement; 133, 134; 133, 137; 133, 169; 134, comparison_operator:==; 134, 135; 134, 136; 135, identifier:t_contents; 136, identifier:contents; 137, block; 137, 138; 137, 155; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:msg; 141, binary_operator:%; 141, 142; 141, 143; 142, string:"Two different environments were specified for target %s,\n\tbut they appear to have the same action: %s"; 143, tuple; 143, 144; 143, 145; 144, identifier:t; 145, call; 145, 146; 145, 149; 146, attribute; 146, 147; 146, 148; 147, identifier:action; 148, identifier:genstring; 149, argument_list; 149, 150; 149, 151; 149, 152; 150, identifier:tlist; 151, identifier:slist; 152, attribute; 152, 153; 152, 154; 153, identifier:t; 154, identifier:env; 155, expression_statement; 155, 156; 156, call; 156, 157; 156, 162; 157, attribute; 157, 158; 157, 161; 158, attribute; 158, 159; 158, 160; 159, identifier:SCons; 160, identifier:Warnings; 161, identifier:warn; 162, argument_list; 162, 163; 162, 168; 163, attribute; 163, 164; 163, 167; 164, attribute; 164, 165; 164, 166; 165, identifier:SCons; 166, identifier:Warnings; 167, identifier:DuplicateEnvironmentWarning; 168, identifier:msg; 169, else_clause; 169, 170; 170, block; 170, 171; 170, 204; 171, try_statement; 171, 172; 171, 192; 172, block; 172, 173; 173, expression_statement; 173, 174; 174, assignment; 174, 175; 174, 176; 175, identifier:msg; 176, binary_operator:%; 176, 177; 176, 178; 177, string:"Two environments with different actions were specified for the same target: %s\n(action 1: %s)\n(action 2: %s)"; 178, tuple; 178, 179; 178, 180; 178, 186; 179, identifier:t; 180, call; 180, 181; 180, 184; 181, attribute; 181, 182; 181, 183; 182, identifier:t_contents; 183, identifier:decode; 184, argument_list; 184, 185; 185, string:'utf-8'; 186, call; 186, 187; 186, 190; 187, attribute; 187, 188; 187, 189; 188, identifier:contents; 189, identifier:decode; 190, argument_list; 190, 191; 191, string:'utf-8'; 192, except_clause; 192, 193; 192, 197; 193, as_pattern; 193, 194; 193, 195; 194, identifier:UnicodeDecodeError; 195, as_pattern_target; 195, 196; 196, identifier:e; 197, block; 197, 198; 198, expression_statement; 198, 199; 199, assignment; 199, 200; 199, 201; 200, identifier:msg; 201, binary_operator:%; 201, 202; 201, 203; 202, string:"Two environments with different actions were specified for the same target: %s"; 203, identifier:t; 204, raise_statement; 204, 205; 205, call; 205, 206; 205, 207; 206, identifier:UserError; 207, argument_list; 207, 208; 208, identifier:msg; 209, if_statement; 209, 210; 209, 213; 209, 297; 210, attribute; 210, 211; 210, 212; 211, identifier:builder; 212, identifier:multi; 213, block; 213, 214; 213, 247; 213, 248; 214, if_statement; 214, 215; 214, 220; 215, comparison_operator:!=; 215, 216; 215, 219; 216, attribute; 216, 217; 216, 218; 217, identifier:t; 218, identifier:builder; 219, identifier:builder; 220, block; 220, 221; 220, 242; 221, expression_statement; 221, 222; 222, assignment; 222, 223; 222, 224; 223, identifier:msg; 224, binary_operator:%; 224, 225; 224, 226; 225, string:"Two different builders (%s and %s) were specified for the same target: %s"; 226, tuple; 226, 227; 226, 235; 226, 241; 227, call; 227, 228; 227, 233; 228, attribute; 228, 229; 228, 232; 229, attribute; 229, 230; 229, 231; 230, identifier:t; 231, identifier:builder; 232, identifier:get_name; 233, argument_list; 233, 234; 234, identifier:env; 235, call; 235, 236; 235, 239; 236, attribute; 236, 237; 236, 238; 237, identifier:builder; 238, identifier:get_name; 239, argument_list; 239, 240; 240, identifier:env; 241, identifier:t; 242, raise_statement; 242, 243; 243, call; 243, 244; 243, 245; 244, identifier:UserError; 245, argument_list; 245, 246; 246, identifier:msg; 247, comment; 248, if_statement; 248, 249; 248, 260; 249, comparison_operator:!=; 249, 250; 249, 259; 250, call; 250, 251; 250, 258; 251, attribute; 251, 252; 251, 257; 252, call; 252, 253; 252, 256; 253, attribute; 253, 254; 253, 255; 254, identifier:t; 255, identifier:get_executor; 256, argument_list; 257, identifier:get_all_targets; 258, argument_list; 259, identifier:tlist; 260, block; 260, 261; 260, 292; 261, expression_statement; 261, 262; 262, assignment; 262, 263; 262, 264; 263, identifier:msg; 264, binary_operator:%; 264, 265; 264, 266; 265, string:"Two different target lists have a target in common: %s (from %s and from %s)"; 266, tuple; 266, 267; 266, 268; 266, 284; 267, identifier:t; 268, call; 268, 269; 268, 270; 269, identifier:list; 270, argument_list; 270, 271; 271, call; 271, 272; 271, 273; 272, identifier:map; 273, argument_list; 273, 274; 273, 275; 274, identifier:str; 275, call; 275, 276; 275, 283; 276, attribute; 276, 277; 276, 282; 277, call; 277, 278; 277, 281; 278, attribute; 278, 279; 278, 280; 279, identifier:t; 280, identifier:get_executor; 281, argument_list; 282, identifier:get_all_targets; 283, argument_list; 284, call; 284, 285; 284, 286; 285, identifier:list; 286, argument_list; 286, 287; 287, call; 287, 288; 287, 289; 288, identifier:map; 289, argument_list; 289, 290; 289, 291; 290, identifier:str; 291, identifier:tlist; 292, raise_statement; 292, 293; 293, call; 293, 294; 293, 295; 294, identifier:UserError; 295, argument_list; 295, 296; 296, identifier:msg; 297, elif_clause; 297, 298; 297, 303; 298, comparison_operator:!=; 298, 299; 298, 302; 299, attribute; 299, 300; 299, 301; 300, identifier:t; 301, identifier:sources; 302, identifier:slist; 303, block; 303, 304; 303, 329; 304, expression_statement; 304, 305; 305, assignment; 305, 306; 305, 307; 306, identifier:msg; 307, binary_operator:%; 307, 308; 307, 309; 308, string:"Multiple ways to build the same target were specified for: %s (from %s and from %s)"; 309, tuple; 309, 310; 309, 311; 309, 321; 310, identifier:t; 311, call; 311, 312; 311, 313; 312, identifier:list; 313, argument_list; 313, 314; 314, call; 314, 315; 314, 316; 315, identifier:map; 316, argument_list; 316, 317; 316, 318; 317, identifier:str; 318, attribute; 318, 319; 318, 320; 319, identifier:t; 320, identifier:sources; 321, call; 321, 322; 321, 323; 322, identifier:list; 323, argument_list; 323, 324; 324, call; 324, 325; 324, 326; 325, identifier:map; 326, argument_list; 326, 327; 326, 328; 327, identifier:str; 328, identifier:slist; 329, raise_statement; 329, 330; 330, call; 330, 331; 330, 332; 331, identifier:UserError; 332, argument_list; 332, 333; 333, identifier:msg; 334, if_statement; 334, 335; 334, 338; 335, attribute; 335, 336; 335, 337; 336, identifier:builder; 337, identifier:single_source; 338, block; 338, 339; 339, if_statement; 339, 340; 339, 346; 340, comparison_operator:>; 340, 341; 340, 345; 341, call; 341, 342; 341, 343; 342, identifier:len; 343, argument_list; 343, 344; 344, identifier:slist; 345, integer:1; 346, block; 346, 347; 347, raise_statement; 347, 348; 348, call; 348, 349; 348, 350; 349, identifier:UserError; 350, argument_list; 350, 351; 351, binary_operator:%; 351, 352; 351, 353; 352, string:"More than one source given for single-source builder: targets=%s sources=%s"; 353, tuple; 353, 354; 353, 362; 354, call; 354, 355; 354, 356; 355, identifier:list; 356, argument_list; 356, 357; 357, call; 357, 358; 357, 359; 358, identifier:map; 359, argument_list; 359, 360; 359, 361; 360, identifier:str; 361, identifier:tlist; 362, call; 362, 363; 362, 364; 363, identifier:list; 364, argument_list; 364, 365; 365, call; 365, 366; 365, 367; 366, identifier:map; 367, argument_list; 367, 368; 367, 369; 368, identifier:str; 369, identifier:slist | def _node_errors(builder, env, tlist, slist):
"""Validate that the lists of target and source nodes are
legal for this builder and environment. Raise errors or
issue warnings as appropriate.
"""
# First, figure out if there are any errors in the way the targets
# were specified.
for t in tlist:
if t.side_effect:
raise UserError("Multiple ways to build the same target were specified for: %s" % t)
if t.has_explicit_builder():
# Check for errors when the environments are different
# No error if environments are the same Environment instance
if (not t.env is None and not t.env is env and
# Check OverrideEnvironment case - no error if wrapped Environments
# are the same instance, and overrides lists match
not (getattr(t.env, '__subject', 0) is getattr(env, '__subject', 1) and
getattr(t.env, 'overrides', 0) == getattr(env, 'overrides', 1) and
not builder.multi)):
action = t.builder.action
t_contents = t.builder.action.get_contents(tlist, slist, t.env)
contents = builder.action.get_contents(tlist, slist, env)
if t_contents == contents:
msg = "Two different environments were specified for target %s,\n\tbut they appear to have the same action: %s" % (t, action.genstring(tlist, slist, t.env))
SCons.Warnings.warn(SCons.Warnings.DuplicateEnvironmentWarning, msg)
else:
try:
msg = "Two environments with different actions were specified for the same target: %s\n(action 1: %s)\n(action 2: %s)" % (t,t_contents.decode('utf-8'),contents.decode('utf-8'))
except UnicodeDecodeError as e:
msg = "Two environments with different actions were specified for the same target: %s"%t
raise UserError(msg)
if builder.multi:
if t.builder != builder:
msg = "Two different builders (%s and %s) were specified for the same target: %s" % (t.builder.get_name(env), builder.get_name(env), t)
raise UserError(msg)
# TODO(batch): list constructed each time!
if t.get_executor().get_all_targets() != tlist:
msg = "Two different target lists have a target in common: %s (from %s and from %s)" % (t, list(map(str, t.get_executor().get_all_targets())), list(map(str, tlist)))
raise UserError(msg)
elif t.sources != slist:
msg = "Multiple ways to build the same target were specified for: %s (from %s and from %s)" % (t, list(map(str, t.sources)), list(map(str, slist)))
raise UserError(msg)
if builder.single_source:
if len(slist) > 1:
raise UserError("More than one source given for single-source builder: targets=%s sources=%s" % (list(map(str,tlist)), list(map(str,slist)))) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_order_pases; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:passes; 6, block; 6, 7; 6, 9; 6, 16; 6, 20; 6, 95; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:passes; 12, call; 12, 13; 12, 14; 13, identifier:set; 14, argument_list; 14, 15; 15, identifier:passes; 16, expression_statement; 16, 17; 17, assignment; 17, 18; 17, 19; 18, identifier:pass_deps; 19, dictionary; 20, for_statement; 20, 21; 20, 22; 20, 23; 21, identifier:opt; 22, identifier:passes; 23, block; 23, 24; 23, 35; 23, 48; 23, 61; 23, 62; 23, 63; 24, expression_statement; 24, 25; 25, assignment; 25, 26; 25, 30; 26, pattern_list; 26, 27; 26, 28; 26, 29; 27, identifier:_; 28, identifier:before; 29, identifier:after; 30, subscript; 30, 31; 30, 34; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:_known_passes; 34, identifier:opt; 35, if_statement; 35, 36; 35, 39; 36, comparison_operator:not; 36, 37; 36, 38; 37, identifier:opt; 38, identifier:pass_deps; 39, block; 39, 40; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 45; 42, subscript; 42, 43; 42, 44; 43, identifier:pass_deps; 44, identifier:opt; 45, call; 45, 46; 45, 47; 46, identifier:set; 47, argument_list; 48, for_statement; 48, 49; 48, 50; 48, 51; 49, identifier:after_pass; 50, identifier:after; 51, block; 51, 52; 52, expression_statement; 52, 53; 53, call; 53, 54; 53, 59; 54, attribute; 54, 55; 54, 58; 55, subscript; 55, 56; 55, 57; 56, identifier:pass_deps; 57, identifier:opt; 58, identifier:add; 59, argument_list; 59, 60; 60, identifier:after_pass; 61, comment; 62, comment; 63, for_statement; 63, 64; 63, 65; 63, 66; 64, identifier:other; 65, identifier:before; 66, block; 66, 67; 66, 73; 66, 86; 67, if_statement; 67, 68; 67, 71; 68, comparison_operator:not; 68, 69; 68, 70; 69, identifier:other; 70, identifier:passes; 71, block; 71, 72; 72, continue_statement; 73, if_statement; 73, 74; 73, 77; 74, comparison_operator:not; 74, 75; 74, 76; 75, identifier:other; 76, identifier:pass_deps; 77, block; 77, 78; 78, expression_statement; 78, 79; 79, assignment; 79, 80; 79, 83; 80, subscript; 80, 81; 80, 82; 81, identifier:pass_deps; 82, identifier:other; 83, call; 83, 84; 83, 85; 84, identifier:set; 85, argument_list; 86, expression_statement; 86, 87; 87, call; 87, 88; 87, 93; 88, attribute; 88, 89; 88, 92; 89, subscript; 89, 90; 89, 91; 90, identifier:pass_deps; 91, identifier:other; 92, identifier:add; 93, argument_list; 93, 94; 94, identifier:opt; 95, return_statement; 95, 96; 96, call; 96, 97; 96, 98; 97, identifier:toposort_flatten; 98, argument_list; 98, 99; 99, identifier:pass_deps | def _order_pases(self, passes):
"""Topologically sort optimization passes.
This ensures that the resulting passes are run in order
respecting before/after constraints.
Args:
passes (iterable): An iterable of pass names that should
be included in the optimization passes run.
"""
passes = set(passes)
pass_deps = {}
for opt in passes:
_, before, after = self._known_passes[opt]
if opt not in pass_deps:
pass_deps[opt] = set()
for after_pass in after:
pass_deps[opt].add(after_pass)
# For passes that we are before, we may need to
# preemptively add them to the list early
for other in before:
if other not in passes:
continue
if other not in pass_deps:
pass_deps[other] = set()
pass_deps[other].add(opt)
return toposort_flatten(pass_deps) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:prepare; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 10; 5, 18; 5, 36; 5, 37; 5, 38; 5, 39; 5, 45; 5, 71; 5, 72; 5, 73; 5, 74; 5, 75; 5, 76; 5, 77; 5, 78; 5, 79; 5, 80; 5, 81; 5, 93; 5, 99; 5, 105; 6, expression_statement; 6, 7; 7, comment; 8, global_statement; 8, 9; 9, identifier:print_prepare; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:T; 13, attribute; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:tm; 17, identifier:trace; 18, if_statement; 18, 19; 18, 20; 19, identifier:T; 20, block; 20, 21; 21, expression_statement; 21, 22; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:T; 25, identifier:write; 26, argument_list; 26, 27; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:trace_message; 31, argument_list; 31, 32; 31, 33; 32, string:u'Task.prepare()'; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:node; 36, comment; 37, comment; 38, comment; 39, expression_statement; 39, 40; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:self; 43, identifier:exception_raise; 44, argument_list; 45, if_statement; 45, 46; 45, 51; 46, attribute; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:self; 49, identifier:tm; 50, identifier:message; 51, block; 51, 52; 51, 63; 52, expression_statement; 52, 53; 53, call; 53, 54; 53, 57; 54, attribute; 54, 55; 54, 56; 55, identifier:self; 56, identifier:display; 57, argument_list; 57, 58; 58, attribute; 58, 59; 58, 62; 59, attribute; 59, 60; 59, 61; 60, identifier:self; 61, identifier:tm; 62, identifier:message; 63, expression_statement; 63, 64; 64, assignment; 64, 65; 64, 70; 65, attribute; 65, 66; 65, 69; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:tm; 69, identifier:message; 70, None; 71, comment; 72, comment; 73, comment; 74, comment; 75, comment; 76, comment; 77, comment; 78, comment; 79, comment; 80, comment; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:executor; 84, call; 84, 85; 84, 92; 85, attribute; 85, 86; 85, 91; 86, subscript; 86, 87; 86, 90; 87, attribute; 87, 88; 87, 89; 88, identifier:self; 89, identifier:targets; 90, integer:0; 91, identifier:get_executor; 92, argument_list; 93, if_statement; 93, 94; 93, 97; 94, comparison_operator:is; 94, 95; 94, 96; 95, identifier:executor; 96, None; 97, block; 97, 98; 98, return_statement; 99, expression_statement; 99, 100; 100, call; 100, 101; 100, 104; 101, attribute; 101, 102; 101, 103; 102, identifier:executor; 103, identifier:prepare; 104, argument_list; 105, for_statement; 105, 106; 105, 107; 105, 112; 106, identifier:t; 107, call; 107, 108; 107, 111; 108, attribute; 108, 109; 108, 110; 109, identifier:executor; 110, identifier:get_action_targets; 111, argument_list; 112, block; 112, 113; 112, 136; 112, 142; 113, if_statement; 113, 114; 113, 115; 114, identifier:print_prepare; 115, block; 115, 116; 115, 123; 116, expression_statement; 116, 117; 117, call; 117, 118; 117, 119; 118, identifier:print; 119, argument_list; 119, 120; 120, binary_operator:%; 120, 121; 120, 122; 121, string:"Preparing target %s..."; 122, identifier:t; 123, for_statement; 123, 124; 123, 125; 123, 128; 124, identifier:s; 125, attribute; 125, 126; 125, 127; 126, identifier:t; 127, identifier:side_effects; 128, block; 128, 129; 129, expression_statement; 129, 130; 130, call; 130, 131; 130, 132; 131, identifier:print; 132, argument_list; 132, 133; 133, binary_operator:%; 133, 134; 133, 135; 134, string:"...with side-effect %s..."; 135, identifier:s; 136, expression_statement; 136, 137; 137, call; 137, 138; 137, 141; 138, attribute; 138, 139; 138, 140; 139, identifier:t; 140, identifier:prepare; 141, argument_list; 142, for_statement; 142, 143; 142, 144; 142, 147; 143, identifier:s; 144, attribute; 144, 145; 144, 146; 145, identifier:t; 146, identifier:side_effects; 147, block; 147, 148; 147, 158; 148, if_statement; 148, 149; 148, 150; 149, identifier:print_prepare; 150, block; 150, 151; 151, expression_statement; 151, 152; 152, call; 152, 153; 152, 154; 153, identifier:print; 154, argument_list; 154, 155; 155, binary_operator:%; 155, 156; 155, 157; 156, string:"...Preparing side-effect %s..."; 157, identifier:s; 158, expression_statement; 158, 159; 159, call; 159, 160; 159, 163; 160, attribute; 160, 161; 160, 162; 161, identifier:s; 162, identifier:prepare; 163, argument_list | def prepare(self):
"""
Called just before the task is executed.
This is mainly intended to give the target Nodes a chance to
unlink underlying files and make all necessary directories before
the Action is actually called to build the targets.
"""
global print_prepare
T = self.tm.trace
if T: T.write(self.trace_message(u'Task.prepare()', self.node))
# Now that it's the appropriate time, give the TaskMaster a
# chance to raise any exceptions it encountered while preparing
# this task.
self.exception_raise()
if self.tm.message:
self.display(self.tm.message)
self.tm.message = None
# Let the targets take care of any necessary preparations.
# This includes verifying that all of the necessary sources
# and dependencies exist, removing the target file(s), etc.
#
# As of April 2008, the get_executor().prepare() method makes
# sure that all of the aggregate sources necessary to build this
# Task's target(s) exist in one up-front check. The individual
# target t.prepare() methods check that each target's explicit
# or implicit dependencies exists, and also initialize the
# .sconsign info.
executor = self.targets[0].get_executor()
if executor is None:
return
executor.prepare()
for t in executor.get_action_targets():
if print_prepare:
print("Preparing target %s..."%t)
for s in t.side_effects:
print("...with side-effect %s..."%s)
t.prepare()
for s in t.side_effects:
if print_prepare:
print("...Preparing side-effect %s..."%s)
s.prepare() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:make_ready_current; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 10; 5, 18; 5, 36; 5, 42; 5, 46; 5, 130; 6, expression_statement; 6, 7; 7, comment; 8, global_statement; 8, 9; 9, identifier:print_prepare; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 12, identifier:T; 13, attribute; 13, 14; 13, 17; 14, attribute; 14, 15; 14, 16; 15, identifier:self; 16, identifier:tm; 17, identifier:trace; 18, if_statement; 18, 19; 18, 20; 19, identifier:T; 20, block; 20, 21; 21, expression_statement; 21, 22; 22, call; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:T; 25, identifier:write; 26, argument_list; 26, 27; 27, call; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:trace_message; 31, argument_list; 31, 32; 31, 33; 32, string:u'Task.make_ready_current()'; 33, attribute; 33, 34; 33, 35; 34, identifier:self; 35, identifier:node; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 41; 38, attribute; 38, 39; 38, 40; 39, identifier:self; 40, identifier:out_of_date; 41, list:[]; 42, expression_statement; 42, 43; 43, assignment; 43, 44; 43, 45; 44, identifier:needs_executing; 45, False; 46, for_statement; 46, 47; 46, 48; 46, 51; 47, identifier:t; 48, attribute; 48, 49; 48, 50; 49, identifier:self; 50, identifier:targets; 51, block; 51, 52; 51, 113; 52, try_statement; 52, 53; 52, 86; 53, block; 53, 54; 53, 64; 54, expression_statement; 54, 55; 55, call; 55, 56; 55, 63; 56, attribute; 56, 57; 56, 62; 57, call; 57, 58; 57, 61; 58, attribute; 58, 59; 58, 60; 59, identifier:t; 60, identifier:disambiguate; 61, argument_list; 62, identifier:make_ready; 63, argument_list; 64, expression_statement; 64, 65; 65, assignment; 65, 66; 65, 67; 66, identifier:is_up_to_date; 67, boolean_operator:or; 67, 68; 67, 74; 67, 75; 68, not_operator; 68, 69; 69, call; 69, 70; 69, 73; 70, attribute; 70, 71; 70, 72; 71, identifier:t; 72, identifier:has_builder; 73, argument_list; 74, line_continuation:\; 75, parenthesized_expression; 75, 76; 76, boolean_operator:and; 76, 77; 76, 81; 77, not_operator; 77, 78; 78, attribute; 78, 79; 78, 80; 79, identifier:t; 80, identifier:always_build; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:t; 84, identifier:is_up_to_date; 85, argument_list; 86, except_clause; 86, 87; 86, 91; 87, as_pattern; 87, 88; 87, 89; 88, identifier:EnvironmentError; 89, as_pattern_target; 89, 90; 90, identifier:e; 91, block; 91, 92; 92, raise_statement; 92, 93; 93, call; 93, 94; 93, 99; 94, attribute; 94, 95; 94, 98; 95, attribute; 95, 96; 95, 97; 96, identifier:SCons; 97, identifier:Errors; 98, identifier:BuildError; 99, argument_list; 99, 100; 99, 103; 99, 108; 100, keyword_argument; 100, 101; 100, 102; 101, identifier:node; 102, identifier:t; 103, keyword_argument; 103, 104; 103, 105; 104, identifier:errstr; 105, attribute; 105, 106; 105, 107; 106, identifier:e; 107, identifier:strerror; 108, keyword_argument; 108, 109; 108, 110; 109, identifier:filename; 110, attribute; 110, 111; 110, 112; 111, identifier:e; 112, identifier:filename; 113, if_statement; 113, 114; 113, 116; 114, not_operator; 114, 115; 115, identifier:is_up_to_date; 116, block; 116, 117; 116, 126; 117, expression_statement; 117, 118; 118, call; 118, 119; 118, 124; 119, attribute; 119, 120; 119, 123; 120, attribute; 120, 121; 120, 122; 121, identifier:self; 122, identifier:out_of_date; 123, identifier:append; 124, argument_list; 124, 125; 125, identifier:t; 126, expression_statement; 126, 127; 127, assignment; 127, 128; 127, 129; 128, identifier:needs_executing; 129, True; 130, if_statement; 130, 131; 130, 132; 130, 164; 131, identifier:needs_executing; 132, block; 132, 133; 133, for_statement; 133, 134; 133, 135; 133, 138; 134, identifier:t; 135, attribute; 135, 136; 135, 137; 136, identifier:self; 137, identifier:targets; 138, block; 138, 139; 138, 146; 139, expression_statement; 139, 140; 140, call; 140, 141; 140, 144; 141, attribute; 141, 142; 141, 143; 142, identifier:t; 143, identifier:set_state; 144, argument_list; 144, 145; 145, identifier:NODE_EXECUTING; 146, for_statement; 146, 147; 146, 148; 146, 151; 146, 152; 147, identifier:s; 148, attribute; 148, 149; 148, 150; 149, identifier:t; 150, identifier:side_effects; 151, comment; 152, block; 152, 153; 153, expression_statement; 153, 154; 154, call; 154, 155; 154, 162; 155, attribute; 155, 156; 155, 161; 156, call; 156, 157; 156, 160; 157, attribute; 157, 158; 157, 159; 158, identifier:s; 159, identifier:disambiguate; 160, argument_list; 161, identifier:set_state; 162, argument_list; 162, 163; 163, identifier:NODE_EXECUTING; 164, else_clause; 164, 165; 165, block; 165, 166; 166, for_statement; 166, 167; 166, 168; 166, 171; 166, 172; 166, 173; 166, 174; 166, 175; 167, identifier:t; 168, attribute; 168, 169; 168, 170; 169, identifier:self; 170, identifier:targets; 171, comment; 172, comment; 173, comment; 174, comment; 175, block; 175, 176; 175, 182; 175, 189; 176, expression_statement; 176, 177; 177, call; 177, 178; 177, 181; 178, attribute; 178, 179; 178, 180; 179, identifier:t; 180, identifier:visited; 181, argument_list; 182, expression_statement; 182, 183; 183, call; 183, 184; 183, 187; 184, attribute; 184, 185; 184, 186; 185, identifier:t; 186, identifier:set_state; 187, argument_list; 187, 188; 188, identifier:NODE_UP_TO_DATE; 189, if_statement; 189, 190; 189, 208; 190, parenthesized_expression; 190, 191; 191, boolean_operator:and; 191, 192; 191, 194; 192, not_operator; 192, 193; 193, identifier:print_prepare; 194, parenthesized_expression; 194, 195; 195, boolean_operator:or; 195, 196; 195, 202; 196, not_operator; 196, 197; 197, call; 197, 198; 197, 199; 198, identifier:hasattr; 199, argument_list; 199, 200; 199, 201; 200, identifier:self; 201, string:'options'; 202, not_operator; 202, 203; 203, attribute; 203, 204; 203, 207; 204, attribute; 204, 205; 204, 206; 205, identifier:self; 206, identifier:options; 207, identifier:debug_includes; 208, block; 208, 209; 209, expression_statement; 209, 210; 210, call; 210, 211; 210, 214; 211, attribute; 211, 212; 211, 213; 212, identifier:t; 213, identifier:release_target_info; 214, argument_list | def make_ready_current(self):
"""
Marks all targets in a task ready for execution if any target
is not current.
This is the default behavior for building only what's necessary.
"""
global print_prepare
T = self.tm.trace
if T: T.write(self.trace_message(u'Task.make_ready_current()',
self.node))
self.out_of_date = []
needs_executing = False
for t in self.targets:
try:
t.disambiguate().make_ready()
is_up_to_date = not t.has_builder() or \
(not t.always_build and t.is_up_to_date())
except EnvironmentError as e:
raise SCons.Errors.BuildError(node=t, errstr=e.strerror, filename=e.filename)
if not is_up_to_date:
self.out_of_date.append(t)
needs_executing = True
if needs_executing:
for t in self.targets:
t.set_state(NODE_EXECUTING)
for s in t.side_effects:
# add disambiguate here to mirror the call on targets in first loop above
s.disambiguate().set_state(NODE_EXECUTING)
else:
for t in self.targets:
# We must invoke visited() to ensure that the node
# information has been computed before allowing the
# parent nodes to execute. (That could occur in a
# parallel build...)
t.visited()
t.set_state(NODE_UP_TO_DATE)
if (not print_prepare and
(not hasattr(self, 'options') or not self.options.debug_includes)):
t.release_target_info() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:postprocess; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 16; 5, 34; 5, 35; 5, 36; 5, 37; 5, 38; 5, 39; 5, 40; 5, 49; 5, 57; 5, 61; 5, 116; 5, 193; 5, 248; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:T; 11, attribute; 11, 12; 11, 15; 12, attribute; 12, 13; 12, 14; 13, identifier:self; 14, identifier:tm; 15, identifier:trace; 16, if_statement; 16, 17; 16, 18; 17, identifier:T; 18, block; 18, 19; 19, expression_statement; 19, 20; 20, call; 20, 21; 20, 24; 21, attribute; 21, 22; 21, 23; 22, identifier:T; 23, identifier:write; 24, argument_list; 24, 25; 25, call; 25, 26; 25, 29; 26, attribute; 26, 27; 26, 28; 27, identifier:self; 28, identifier:trace_message; 29, argument_list; 29, 30; 29, 31; 30, string:u'Task.postprocess()'; 31, attribute; 31, 32; 31, 33; 32, identifier:self; 33, identifier:node; 34, comment; 35, comment; 36, comment; 37, comment; 38, comment; 39, comment; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:targets; 43, call; 43, 44; 43, 45; 44, identifier:set; 45, argument_list; 45, 46; 46, attribute; 46, 47; 46, 48; 47, identifier:self; 48, identifier:targets; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:pending_children; 52, attribute; 52, 53; 52, 56; 53, attribute; 53, 54; 53, 55; 54, identifier:self; 55, identifier:tm; 56, identifier:pending_children; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:parents; 60, dictionary; 61, for_statement; 61, 62; 61, 63; 61, 64; 61, 65; 61, 66; 62, identifier:t; 63, identifier:targets; 64, comment; 65, comment; 66, block; 66, 67; 66, 96; 67, if_statement; 67, 68; 67, 71; 68, attribute; 68, 69; 68, 70; 69, identifier:t; 70, identifier:waiting_parents; 71, block; 71, 72; 71, 89; 72, if_statement; 72, 73; 72, 74; 73, identifier:T; 74, block; 74, 75; 75, expression_statement; 75, 76; 76, call; 76, 77; 76, 80; 77, attribute; 77, 78; 77, 79; 78, identifier:T; 79, identifier:write; 80, argument_list; 80, 81; 81, call; 81, 82; 81, 85; 82, attribute; 82, 83; 82, 84; 83, identifier:self; 84, identifier:trace_message; 85, argument_list; 85, 86; 85, 87; 85, 88; 86, string:u'Task.postprocess()'; 87, identifier:t; 88, string:'removing'; 89, expression_statement; 89, 90; 90, call; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:pending_children; 93, identifier:discard; 94, argument_list; 94, 95; 95, identifier:t; 96, for_statement; 96, 97; 96, 98; 96, 101; 97, identifier:p; 98, attribute; 98, 99; 98, 100; 99, identifier:t; 100, identifier:waiting_parents; 101, block; 101, 102; 102, expression_statement; 102, 103; 103, assignment; 103, 104; 103, 107; 104, subscript; 104, 105; 104, 106; 105, identifier:parents; 106, identifier:p; 107, binary_operator:+; 107, 108; 107, 115; 108, call; 108, 109; 108, 112; 109, attribute; 109, 110; 109, 111; 110, identifier:parents; 111, identifier:get; 112, argument_list; 112, 113; 112, 114; 113, identifier:p; 114, integer:0; 115, integer:1; 116, for_statement; 116, 117; 116, 118; 116, 119; 117, identifier:t; 118, identifier:targets; 119, block; 119, 120; 120, if_statement; 120, 121; 120, 126; 121, comparison_operator:is; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:t; 124, identifier:side_effects; 125, None; 126, block; 126, 127; 127, for_statement; 127, 128; 127, 129; 127, 132; 128, identifier:s; 129, attribute; 129, 130; 129, 131; 130, identifier:t; 131, identifier:side_effects; 132, block; 132, 133; 132, 169; 133, if_statement; 133, 134; 133, 141; 134, comparison_operator:==; 134, 135; 134, 140; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:s; 138, identifier:get_state; 139, argument_list; 140, identifier:NODE_EXECUTING; 141, block; 141, 142; 141, 149; 142, expression_statement; 142, 143; 143, call; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:s; 146, identifier:set_state; 147, argument_list; 147, 148; 148, identifier:NODE_NO_STATE; 149, for_statement; 149, 150; 149, 151; 149, 154; 150, identifier:p; 151, attribute; 151, 152; 151, 153; 152, identifier:s; 153, identifier:waiting_parents; 154, block; 154, 155; 155, expression_statement; 155, 156; 156, assignment; 156, 157; 156, 160; 157, subscript; 157, 158; 157, 159; 158, identifier:parents; 159, identifier:p; 160, binary_operator:+; 160, 161; 160, 168; 161, call; 161, 162; 161, 165; 162, attribute; 162, 163; 162, 164; 163, identifier:parents; 164, identifier:get; 165, argument_list; 165, 166; 165, 167; 166, identifier:p; 167, integer:0; 168, integer:1; 169, for_statement; 169, 170; 169, 171; 169, 174; 170, identifier:p; 171, attribute; 171, 172; 171, 173; 172, identifier:s; 173, identifier:waiting_s_e; 174, block; 174, 175; 175, if_statement; 175, 176; 175, 181; 176, comparison_operator:==; 176, 177; 176, 180; 177, attribute; 177, 178; 177, 179; 178, identifier:p; 179, identifier:ref_count; 180, integer:0; 181, block; 181, 182; 182, expression_statement; 182, 183; 183, call; 183, 184; 183, 191; 184, attribute; 184, 185; 184, 190; 185, attribute; 185, 186; 185, 189; 186, attribute; 186, 187; 186, 188; 187, identifier:self; 188, identifier:tm; 189, identifier:candidates; 190, identifier:append; 191, argument_list; 191, 192; 192, identifier:p; 193, for_statement; 193, 194; 193, 197; 193, 202; 194, pattern_list; 194, 195; 194, 196; 195, identifier:p; 196, identifier:subtract; 197, call; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:parents; 200, identifier:items; 201, argument_list; 202, block; 202, 203; 202, 213; 202, 230; 203, expression_statement; 203, 204; 204, assignment; 204, 205; 204, 208; 205, attribute; 205, 206; 205, 207; 206, identifier:p; 207, identifier:ref_count; 208, binary_operator:-; 208, 209; 208, 212; 209, attribute; 209, 210; 209, 211; 210, identifier:p; 211, identifier:ref_count; 212, identifier:subtract; 213, if_statement; 213, 214; 213, 215; 214, identifier:T; 215, block; 215, 216; 216, expression_statement; 216, 217; 217, call; 217, 218; 217, 221; 218, attribute; 218, 219; 218, 220; 219, identifier:T; 220, identifier:write; 221, argument_list; 221, 222; 222, call; 222, 223; 222, 226; 223, attribute; 223, 224; 223, 225; 224, identifier:self; 225, identifier:trace_message; 226, argument_list; 226, 227; 226, 228; 226, 229; 227, string:u'Task.postprocess()'; 228, identifier:p; 229, string:'adjusted parent ref count'; 230, if_statement; 230, 231; 230, 236; 231, comparison_operator:==; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:p; 234, identifier:ref_count; 235, integer:0; 236, block; 236, 237; 237, expression_statement; 237, 238; 238, call; 238, 239; 238, 246; 239, attribute; 239, 240; 239, 245; 240, attribute; 240, 241; 240, 244; 241, attribute; 241, 242; 241, 243; 242, identifier:self; 243, identifier:tm; 244, identifier:candidates; 245, identifier:append; 246, argument_list; 246, 247; 247, identifier:p; 248, for_statement; 248, 249; 248, 250; 248, 251; 249, identifier:t; 250, identifier:targets; 251, block; 251, 252; 252, expression_statement; 252, 253; 253, call; 253, 254; 253, 257; 254, attribute; 254, 255; 254, 256; 255, identifier:t; 256, identifier:postprocess; 257, argument_list | def postprocess(self):
"""
Post-processes a task after it's been executed.
This examines all the targets just built (or not, we don't care
if the build was successful, or even if there was no build
because everything was up-to-date) to see if they have any
waiting parent Nodes, or Nodes waiting on a common side effect,
that can be put back on the candidates list.
"""
T = self.tm.trace
if T: T.write(self.trace_message(u'Task.postprocess()', self.node))
# We may have built multiple targets, some of which may have
# common parents waiting for this build. Count up how many
# targets each parent was waiting for so we can subtract the
# values later, and so we *don't* put waiting side-effect Nodes
# back on the candidates list if the Node is also a waiting
# parent.
targets = set(self.targets)
pending_children = self.tm.pending_children
parents = {}
for t in targets:
# A node can only be in the pending_children set if it has
# some waiting_parents.
if t.waiting_parents:
if T: T.write(self.trace_message(u'Task.postprocess()',
t,
'removing'))
pending_children.discard(t)
for p in t.waiting_parents:
parents[p] = parents.get(p, 0) + 1
for t in targets:
if t.side_effects is not None:
for s in t.side_effects:
if s.get_state() == NODE_EXECUTING:
s.set_state(NODE_NO_STATE)
for p in s.waiting_parents:
parents[p] = parents.get(p, 0) + 1
for p in s.waiting_s_e:
if p.ref_count == 0:
self.tm.candidates.append(p)
for p, subtract in parents.items():
p.ref_count = p.ref_count - subtract
if T: T.write(self.trace_message(u'Task.postprocess()',
p,
'adjusted parent ref count'))
if p.ref_count == 0:
self.tm.candidates.append(p)
for t in targets:
t.postprocess() |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:update_dependency; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:tile; 6, identifier:depinfo; 7, default_parameter; 7, 8; 7, 9; 8, identifier:destdir; 9, None; 10, block; 10, 11; 10, 13; 10, 36; 10, 40; 10, 44; 10, 62; 10, 209; 10, 214; 11, expression_statement; 11, 12; 12, comment; 13, if_statement; 13, 14; 13, 17; 14, comparison_operator:is; 14, 15; 14, 16; 15, identifier:destdir; 16, None; 17, block; 17, 18; 18, expression_statement; 18, 19; 19, assignment; 19, 20; 19, 21; 20, identifier:destdir; 21, call; 21, 22; 21, 27; 22, attribute; 22, 23; 22, 26; 23, attribute; 23, 24; 23, 25; 24, identifier:os; 25, identifier:path; 26, identifier:join; 27, argument_list; 27, 28; 27, 31; 27, 32; 27, 33; 28, attribute; 28, 29; 28, 30; 29, identifier:tile; 30, identifier:folder; 31, string:'build'; 32, string:'deps'; 33, subscript; 33, 34; 33, 35; 34, identifier:depinfo; 35, string:'unique_id'; 36, expression_statement; 36, 37; 37, assignment; 37, 38; 37, 39; 38, identifier:has_version; 39, False; 40, expression_statement; 40, 41; 41, assignment; 41, 42; 41, 43; 42, identifier:had_version; 43, False; 44, if_statement; 44, 45; 44, 53; 45, call; 45, 46; 45, 51; 46, attribute; 46, 47; 46, 50; 47, attribute; 47, 48; 47, 49; 48, identifier:os; 49, identifier:path; 50, identifier:exists; 51, argument_list; 51, 52; 52, identifier:destdir; 53, block; 53, 54; 53, 58; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:has_version; 57, True; 58, expression_statement; 58, 59; 59, assignment; 59, 60; 59, 61; 60, identifier:had_version; 61, True; 62, for_statement; 62, 63; 62, 66; 62, 69; 63, pattern_list; 63, 64; 63, 65; 64, identifier:priority; 65, identifier:rule; 66, attribute; 66, 67; 66, 68; 67, identifier:self; 68, identifier:rules; 69, block; 69, 70; 69, 81; 69, 90; 69, 131; 69, 132; 69, 142; 69, 158; 69, 165; 69, 181; 69, 194; 69, 202; 69, 207; 70, if_statement; 70, 71; 70, 79; 71, not_operator; 71, 72; 72, call; 72, 73; 72, 76; 73, attribute; 73, 74; 73, 75; 74, identifier:self; 75, identifier:_check_rule; 76, argument_list; 76, 77; 76, 78; 77, identifier:rule; 78, identifier:depinfo; 79, block; 79, 80; 80, continue_statement; 81, expression_statement; 81, 82; 82, assignment; 82, 83; 82, 84; 83, identifier:resolver; 84, call; 84, 85; 84, 88; 85, attribute; 85, 86; 85, 87; 86, identifier:self; 87, identifier:_find_resolver; 88, argument_list; 88, 89; 89, identifier:rule; 90, if_statement; 90, 91; 90, 92; 91, identifier:has_version; 92, block; 92, 93; 92, 100; 92, 101; 92, 112; 93, expression_statement; 93, 94; 94, assignment; 94, 95; 94, 96; 95, identifier:deptile; 96, call; 96, 97; 96, 98; 97, identifier:IOTile; 98, argument_list; 98, 99; 99, identifier:destdir; 100, comment; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:depstatus; 104, call; 104, 105; 104, 108; 105, attribute; 105, 106; 105, 107; 106, identifier:self; 107, identifier:_check_dep; 108, argument_list; 108, 109; 108, 110; 108, 111; 109, identifier:depinfo; 110, identifier:deptile; 111, identifier:resolver; 112, if_statement; 112, 113; 112, 116; 112, 128; 113, comparison_operator:is; 113, 114; 113, 115; 114, identifier:depstatus; 115, False; 116, block; 116, 117; 116, 124; 117, expression_statement; 117, 118; 118, call; 118, 119; 118, 122; 119, attribute; 119, 120; 119, 121; 120, identifier:shutil; 121, identifier:rmtree; 122, argument_list; 122, 123; 123, identifier:destdir; 124, expression_statement; 124, 125; 125, assignment; 125, 126; 125, 127; 126, identifier:has_version; 127, False; 128, else_clause; 128, 129; 129, block; 129, 130; 130, continue_statement; 131, comment; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:result; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:resolver; 138, identifier:resolve; 139, argument_list; 139, 140; 139, 141; 140, identifier:depinfo; 141, identifier:destdir; 142, if_statement; 142, 143; 142, 155; 143, boolean_operator:and; 143, 144; 143, 148; 144, not_operator; 144, 145; 145, subscript; 145, 146; 145, 147; 146, identifier:result; 147, string:'found'; 148, call; 148, 149; 148, 152; 149, attribute; 149, 150; 149, 151; 150, identifier:result; 151, identifier:get; 152, argument_list; 152, 153; 152, 154; 153, string:'stop'; 154, False; 155, block; 155, 156; 156, return_statement; 156, 157; 157, string:'not found'; 158, if_statement; 158, 159; 158, 163; 159, not_operator; 159, 160; 160, subscript; 160, 161; 160, 162; 161, identifier:result; 162, string:'found'; 163, block; 163, 164; 164, continue_statement; 165, expression_statement; 165, 166; 166, assignment; 166, 167; 166, 168; 167, identifier:settings; 168, dictionary; 168, 169; 168, 176; 169, pair; 169, 170; 169, 171; 170, string:'resolver'; 171, attribute; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:resolver; 174, identifier:__class__; 175, identifier:__name__; 176, pair; 176, 177; 176, 178; 177, string:'factory_args'; 178, subscript; 178, 179; 178, 180; 179, identifier:rule; 180, integer:2; 181, if_statement; 181, 182; 181, 185; 182, comparison_operator:in; 182, 183; 182, 184; 183, string:'settings'; 184, identifier:result; 185, block; 185, 186; 186, expression_statement; 186, 187; 187, assignment; 187, 188; 187, 191; 188, subscript; 188, 189; 188, 190; 189, identifier:settings; 190, string:'settings'; 191, subscript; 191, 192; 191, 193; 192, identifier:result; 193, string:'settings'; 194, expression_statement; 194, 195; 195, call; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:self; 198, identifier:_save_depsettings; 199, argument_list; 199, 200; 199, 201; 200, identifier:destdir; 201, identifier:settings; 202, if_statement; 202, 203; 202, 204; 203, identifier:had_version; 204, block; 204, 205; 205, return_statement; 205, 206; 206, string:"updated"; 207, return_statement; 207, 208; 208, string:"installed"; 209, if_statement; 209, 210; 209, 211; 210, identifier:has_version; 211, block; 211, 212; 212, return_statement; 212, 213; 213, string:"already installed"; 214, return_statement; 214, 215; 215, string:"not found" | def update_dependency(self, tile, depinfo, destdir=None):
"""Attempt to install or update a dependency to the latest version.
Args:
tile (IOTile): An IOTile object describing the tile that has the dependency
depinfo (dict): a dictionary from tile.dependencies specifying the dependency
destdir (string): An optional folder into which to unpack the dependency
Returns:
string: a string indicating the outcome. Possible values are:
"already installed"
"installed"
"updated"
"not found"
"""
if destdir is None:
destdir = os.path.join(tile.folder, 'build', 'deps', depinfo['unique_id'])
has_version = False
had_version = False
if os.path.exists(destdir):
has_version = True
had_version = True
for priority, rule in self.rules:
if not self._check_rule(rule, depinfo):
continue
resolver = self._find_resolver(rule)
if has_version:
deptile = IOTile(destdir)
# If the dependency is not up to date, don't do anything
depstatus = self._check_dep(depinfo, deptile, resolver)
if depstatus is False:
shutil.rmtree(destdir)
has_version = False
else:
continue
# Now try to resolve this dependency with the latest version
result = resolver.resolve(depinfo, destdir)
if not result['found'] and result.get('stop', False):
return 'not found'
if not result['found']:
continue
settings = {
'resolver': resolver.__class__.__name__,
'factory_args': rule[2]
}
if 'settings' in result:
settings['settings'] = result['settings']
self._save_depsettings(destdir, settings)
if had_version:
return "updated"
return "installed"
if has_version:
return "already installed"
return "not found" |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:stop; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 14; 5, 26; 5, 85; 5, 89; 5, 105; 5, 119; 5, 132; 5, 136; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:stopped; 12, block; 12, 13; 13, return_statement; 14, expression_statement; 14, 15; 15, call; 15, 16; 15, 21; 16, attribute; 16, 17; 16, 20; 17, attribute; 17, 18; 17, 19; 18, identifier:self; 19, identifier:_logger; 20, identifier:debug; 21, argument_list; 21, 22; 21, 23; 22, string:"Stopping task %s"; 23, attribute; 23, 24; 23, 25; 24, identifier:self; 25, identifier:name; 26, if_statement; 26, 27; 26, 32; 26, 70; 27, comparison_operator:is; 27, 28; 27, 31; 28, attribute; 28, 29; 28, 30; 29, identifier:self; 30, identifier:_finalizer; 31, None; 32, block; 32, 33; 33, try_statement; 33, 34; 33, 55; 34, block; 34, 35; 34, 44; 35, expression_statement; 35, 36; 36, assignment; 36, 37; 36, 38; 37, identifier:result; 38, call; 38, 39; 38, 42; 39, attribute; 39, 40; 39, 41; 40, identifier:self; 41, identifier:_finalizer; 42, argument_list; 42, 43; 43, identifier:self; 44, if_statement; 44, 45; 44, 51; 45, call; 45, 46; 45, 49; 46, attribute; 46, 47; 46, 48; 47, identifier:inspect; 48, identifier:isawaitable; 49, argument_list; 49, 50; 50, identifier:result; 51, block; 51, 52; 52, expression_statement; 52, 53; 53, await; 53, 54; 54, identifier:result; 55, except_clause; 55, 56; 55, 57; 56, comment; 57, block; 57, 58; 58, expression_statement; 58, 59; 59, call; 59, 60; 59, 65; 60, attribute; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:self; 63, identifier:_logger; 64, identifier:exception; 65, argument_list; 65, 66; 65, 67; 66, string:"Error running finalizer for task %s"; 67, attribute; 67, 68; 67, 69; 68, identifier:self; 69, identifier:name; 70, elif_clause; 70, 71; 70, 76; 71, comparison_operator:is; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:self; 74, identifier:task; 75, None; 76, block; 76, 77; 77, expression_statement; 77, 78; 78, call; 78, 79; 78, 84; 79, attribute; 79, 80; 79, 83; 80, attribute; 80, 81; 80, 82; 81, identifier:self; 82, identifier:task; 83, identifier:cancel; 84, argument_list; 85, expression_statement; 85, 86; 86, assignment; 86, 87; 86, 88; 87, identifier:tasks; 88, list:[]; 89, if_statement; 89, 90; 89, 95; 90, comparison_operator:is; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:self; 93, identifier:task; 94, None; 95, block; 95, 96; 96, expression_statement; 96, 97; 97, call; 97, 98; 97, 101; 98, attribute; 98, 99; 98, 100; 99, identifier:tasks; 100, identifier:append; 101, argument_list; 101, 102; 102, attribute; 102, 103; 102, 104; 103, identifier:self; 104, identifier:task; 105, expression_statement; 105, 106; 106, call; 106, 107; 106, 110; 107, attribute; 107, 108; 107, 109; 108, identifier:tasks; 109, identifier:extend; 110, generator_expression; 110, 111; 110, 114; 111, attribute; 111, 112; 111, 113; 112, identifier:x; 113, identifier:task; 114, for_in_clause; 114, 115; 114, 116; 115, identifier:x; 116, attribute; 116, 117; 116, 118; 117, identifier:self; 118, identifier:subtasks; 119, expression_statement; 119, 120; 120, assignment; 120, 121; 120, 122; 121, identifier:finished; 122, call; 122, 123; 122, 126; 123, attribute; 123, 124; 123, 125; 124, identifier:asyncio; 125, identifier:gather; 126, argument_list; 126, 127; 126, 129; 127, list_splat; 127, 128; 128, identifier:tasks; 129, keyword_argument; 129, 130; 129, 131; 130, identifier:return_exceptions; 131, True; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:outcomes; 135, list:[]; 136, try_statement; 136, 137; 136, 153; 136, 181; 137, block; 137, 138; 138, expression_statement; 138, 139; 139, assignment; 139, 140; 139, 141; 140, identifier:outcomes; 141, await; 141, 142; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:asyncio; 145, identifier:wait_for; 146, argument_list; 146, 147; 146, 148; 147, identifier:finished; 148, keyword_argument; 148, 149; 148, 150; 149, identifier:timeout; 150, attribute; 150, 151; 150, 152; 151, identifier:self; 152, identifier:_stop_timeout; 153, except_clause; 153, 154; 153, 160; 153, 161; 153, 162; 153, 163; 154, as_pattern; 154, 155; 154, 158; 155, attribute; 155, 156; 155, 157; 156, identifier:asyncio; 157, identifier:TimeoutError; 158, as_pattern_target; 158, 159; 159, identifier:err; 160, comment; 161, comment; 162, comment; 163, block; 163, 164; 163, 177; 163, 178; 163, 179; 164, try_statement; 164, 165; 164, 171; 165, block; 165, 166; 166, expression_statement; 166, 167; 167, assignment; 167, 168; 167, 169; 168, identifier:outcomes; 169, await; 169, 170; 170, identifier:finished; 171, except_clause; 171, 172; 171, 175; 172, attribute; 172, 173; 172, 174; 173, identifier:asyncio; 174, identifier:CancelledError; 175, block; 175, 176; 176, pass_statement; 177, comment; 178, comment; 179, raise_statement; 179, 180; 180, identifier:err; 181, finally_clause; 181, 182; 182, block; 182, 183; 182, 189; 182, 218; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:self; 187, identifier:stopped; 188, True; 189, for_statement; 189, 190; 189, 191; 189, 192; 190, identifier:outcome; 191, identifier:outcomes; 192, block; 192, 193; 193, if_statement; 193, 194; 193, 208; 194, boolean_operator:and; 194, 195; 194, 200; 195, call; 195, 196; 195, 197; 196, identifier:isinstance; 197, argument_list; 197, 198; 197, 199; 198, identifier:outcome; 199, identifier:Exception; 200, not_operator; 200, 201; 201, call; 201, 202; 201, 203; 202, identifier:isinstance; 203, argument_list; 203, 204; 203, 205; 204, identifier:outcome; 205, attribute; 205, 206; 205, 207; 206, identifier:asyncio; 207, identifier:CancelledError; 208, block; 208, 209; 209, expression_statement; 209, 210; 210, call; 210, 211; 210, 216; 211, attribute; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:self; 214, identifier:_logger; 215, identifier:error; 216, argument_list; 216, 217; 217, identifier:outcome; 218, if_statement; 218, 219; 218, 226; 219, comparison_operator:in; 219, 220; 219, 221; 220, identifier:self; 221, attribute; 221, 222; 221, 225; 222, attribute; 222, 223; 222, 224; 223, identifier:self; 224, identifier:_loop; 225, identifier:tasks; 226, block; 226, 227; 227, expression_statement; 227, 228; 228, call; 228, 229; 228, 236; 229, attribute; 229, 230; 229, 235; 230, attribute; 230, 231; 230, 234; 231, attribute; 231, 232; 231, 233; 232, identifier:self; 233, identifier:_loop; 234, identifier:tasks; 235, identifier:remove; 236, argument_list; 236, 237; 237, identifier:self | async def stop(self):
"""Stop this task and wait until it and all its subtasks end.
This function will finalize this task either by using the finalizer
function passed during creation or by calling task.cancel() if no
finalizer was passed.
It will then call join() on this task and any registered subtasks
with the given maximum timeout, raising asyncio.TimeoutError if
the tasks did not exit within the given timeout.
This method should only be called once.
After this method returns, the task is finished and no more subtasks
can be added. If this task is being tracked inside of the
BackgroundEventLoop that it is part of, it will automatically be
removed from the event loop's list of tasks.
"""
if self.stopped:
return
self._logger.debug("Stopping task %s", self.name)
if self._finalizer is not None:
try:
result = self._finalizer(self)
if inspect.isawaitable(result):
await result
except: #pylint:disable=bare-except;We need to make sure we always wait for the task
self._logger.exception("Error running finalizer for task %s",
self.name)
elif self.task is not None:
self.task.cancel()
tasks = []
if self.task is not None:
tasks.append(self.task)
tasks.extend(x.task for x in self.subtasks)
finished = asyncio.gather(*tasks, return_exceptions=True)
outcomes = []
try:
outcomes = await asyncio.wait_for(finished, timeout=self._stop_timeout)
except asyncio.TimeoutError as err:
# See discussion here: https://github.com/python/asyncio/issues/253#issuecomment-120138132
# This prevents a nuisance log error message, finished is guaranteed
# to be cancelled but not awaited when wait_for() has a timeout.
try:
outcomes = await finished
except asyncio.CancelledError:
pass
# See https://mail.python.org/pipermail/python-3000/2008-May/013740.html
# for why we need to explictly name the error here
raise err
finally:
self.stopped = True
for outcome in outcomes:
if isinstance(outcome, Exception) and not isinstance(outcome, asyncio.CancelledError):
self._logger.error(outcome)
if self in self._loop.tasks:
self._loop.tasks.remove(self) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:link_cloud; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:username; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:password; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, identifier:device_id; 13, None; 14, block; 14, 15; 14, 17; 14, 23; 14, 32; 14, 48; 14, 66; 14, 75; 14, 89; 14, 100; 14, 110; 14, 120; 14, 130; 15, expression_statement; 15, 16; 16, comment; 17, expression_statement; 17, 18; 18, assignment; 18, 19; 18, 20; 19, identifier:reg; 20, call; 20, 21; 20, 22; 21, identifier:ComponentRegistry; 22, argument_list; 23, expression_statement; 23, 24; 24, assignment; 24, 25; 24, 26; 25, identifier:domain; 26, call; 26, 27; 26, 30; 27, attribute; 27, 28; 27, 29; 28, identifier:self; 29, identifier:get; 30, argument_list; 30, 31; 31, string:'cloud:server'; 32, if_statement; 32, 33; 32, 36; 33, comparison_operator:is; 33, 34; 33, 35; 34, identifier:username; 35, None; 36, block; 36, 37; 36, 41; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:prompt_str; 40, string:"Please enter your IOTile.cloud email: "; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:username; 44, call; 44, 45; 44, 46; 45, identifier:input; 46, argument_list; 46, 47; 47, identifier:prompt_str; 48, if_statement; 48, 49; 48, 52; 49, comparison_operator:is; 49, 50; 49, 51; 50, identifier:password; 51, None; 52, block; 52, 53; 52, 57; 53, expression_statement; 53, 54; 54, assignment; 54, 55; 54, 56; 55, identifier:prompt_str; 56, string:"Please enter your IOTile.cloud password: "; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:password; 60, call; 60, 61; 60, 64; 61, attribute; 61, 62; 61, 63; 62, identifier:getpass; 63, identifier:getpass; 64, argument_list; 64, 65; 65, identifier:prompt_str; 66, expression_statement; 66, 67; 67, assignment; 67, 68; 67, 69; 68, identifier:cloud; 69, call; 69, 70; 69, 71; 70, identifier:Api; 71, argument_list; 71, 72; 72, keyword_argument; 72, 73; 72, 74; 73, identifier:domain; 74, identifier:domain; 75, expression_statement; 75, 76; 76, assignment; 76, 77; 76, 78; 77, identifier:ok_resp; 78, call; 78, 79; 78, 82; 79, attribute; 79, 80; 79, 81; 80, identifier:cloud; 81, identifier:login; 82, argument_list; 82, 83; 82, 86; 83, keyword_argument; 83, 84; 83, 85; 84, identifier:email; 85, identifier:username; 86, keyword_argument; 86, 87; 86, 88; 87, identifier:password; 88, identifier:password; 89, if_statement; 89, 90; 89, 92; 90, not_operator; 90, 91; 91, identifier:ok_resp; 92, block; 92, 93; 93, raise_statement; 93, 94; 94, call; 94, 95; 94, 96; 95, identifier:ArgumentError; 96, argument_list; 96, 97; 97, binary_operator:%; 97, 98; 97, 99; 98, string:"Could not login to iotile.cloud as user %s"; 99, identifier:username; 100, expression_statement; 100, 101; 101, call; 101, 102; 101, 105; 102, attribute; 102, 103; 102, 104; 103, identifier:reg; 104, identifier:set_config; 105, argument_list; 105, 106; 105, 107; 106, string:'arch:cloud_user'; 107, attribute; 107, 108; 107, 109; 108, identifier:cloud; 109, identifier:username; 110, expression_statement; 110, 111; 111, call; 111, 112; 111, 115; 112, attribute; 112, 113; 112, 114; 113, identifier:reg; 114, identifier:set_config; 115, argument_list; 115, 116; 115, 117; 116, string:'arch:cloud_token'; 117, attribute; 117, 118; 117, 119; 118, identifier:cloud; 119, identifier:token; 120, expression_statement; 120, 121; 121, call; 121, 122; 121, 125; 122, attribute; 122, 123; 122, 124; 123, identifier:reg; 124, identifier:set_config; 125, argument_list; 125, 126; 125, 127; 126, string:'arch:cloud_token_type'; 127, attribute; 127, 128; 127, 129; 128, identifier:cloud; 129, identifier:token_type; 130, if_statement; 130, 131; 130, 134; 131, comparison_operator:is; 131, 132; 131, 133; 132, identifier:device_id; 133, None; 134, block; 134, 135; 134, 141; 135, expression_statement; 135, 136; 136, assignment; 136, 137; 136, 138; 137, identifier:cloud; 138, call; 138, 139; 138, 140; 139, identifier:IOTileCloud; 140, argument_list; 141, expression_statement; 141, 142; 142, call; 142, 143; 142, 146; 143, attribute; 143, 144; 143, 145; 144, identifier:cloud; 145, identifier:impersonate_device; 146, argument_list; 146, 147; 147, identifier:device_id | def link_cloud(self, username=None, password=None, device_id=None):
"""Create and store a token for interacting with the IOTile Cloud API.
You will need to call link_cloud once for each virtualenv that
you create and want to use with any api calls that touch iotile cloud.
Note that this method is called on a ConfigManager instance
If you do not pass your username or password it will be prompted from
you securely on stdin.
If you are logging in for a user, the token will expire periodically and you
will have to relogin.
If you pass a device_id, you can obtain a limited token for that device
that will never expire, assuming you have access to that device.
Args:
username (string): Your iotile.cloud username. This is prompted
from stdin if not provided.
password (string): Your iotile.cloud password. This is prompted
from stdin if not provided.
device_id (int): Optional device id to obtain permanent credentials
for a device.
"""
reg = ComponentRegistry()
domain = self.get('cloud:server')
if username is None:
prompt_str = "Please enter your IOTile.cloud email: "
username = input(prompt_str)
if password is None:
prompt_str = "Please enter your IOTile.cloud password: "
password = getpass.getpass(prompt_str)
cloud = Api(domain=domain)
ok_resp = cloud.login(email=username, password=password)
if not ok_resp:
raise ArgumentError("Could not login to iotile.cloud as user %s" % username)
reg.set_config('arch:cloud_user', cloud.username)
reg.set_config('arch:cloud_token', cloud.token)
reg.set_config('arch:cloud_token_type', cloud.token_type)
if device_id is not None:
cloud = IOTileCloud()
cloud.impersonate_device(device_id) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:main; 3, parameters; 3, 4; 4, default_parameter; 4, 5; 4, 6; 5, identifier:argv; 6, None; 7, block; 7, 8; 7, 10; 7, 25; 7, 300; 8, expression_statement; 8, 9; 9, comment; 10, if_statement; 10, 11; 10, 14; 11, comparison_operator:is; 11, 12; 11, 13; 12, identifier:argv; 13, None; 14, block; 14, 15; 15, expression_statement; 15, 16; 16, assignment; 16, 17; 16, 18; 17, identifier:argv; 18, subscript; 18, 19; 18, 22; 19, attribute; 19, 20; 19, 21; 20, identifier:sys; 21, identifier:argv; 22, slice; 22, 23; 22, 24; 23, integer:1; 24, colon; 25, try_statement; 25, 26; 25, 285; 26, block; 26, 27; 26, 31; 26, 37; 26, 48; 26, 54; 26, 60; 26, 69; 26, 76; 26, 100; 26, 106; 26, 113; 26, 126; 26, 151; 26, 152; 26, 177; 26, 204; 26, 217; 26, 223; 26, 236; 26, 267; 27, expression_statement; 27, 28; 28, assignment; 28, 29; 28, 30; 29, identifier:executor; 30, None; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:parser; 34, call; 34, 35; 34, 36; 35, identifier:build_args; 36, argument_list; 37, expression_statement; 37, 38; 38, assignment; 38, 39; 38, 40; 39, identifier:args; 40, call; 40, 41; 40, 44; 41, attribute; 41, 42; 41, 43; 42, identifier:parser; 43, identifier:parse_args; 44, argument_list; 44, 45; 45, keyword_argument; 45, 46; 45, 47; 46, identifier:args; 47, identifier:argv; 48, expression_statement; 48, 49; 49, assignment; 49, 50; 49, 51; 50, identifier:model; 51, call; 51, 52; 51, 53; 52, identifier:DeviceModel; 53, argument_list; 54, expression_statement; 54, 55; 55, assignment; 55, 56; 55, 57; 56, identifier:parser; 57, call; 57, 58; 57, 59; 58, identifier:SensorGraphFileParser; 59, argument_list; 60, expression_statement; 60, 61; 61, call; 61, 62; 61, 65; 62, attribute; 62, 63; 62, 64; 63, identifier:parser; 64, identifier:parse_file; 65, argument_list; 65, 66; 66, attribute; 66, 67; 66, 68; 67, identifier:args; 68, identifier:sensor_graph; 69, expression_statement; 69, 70; 70, call; 70, 71; 70, 74; 71, attribute; 71, 72; 71, 73; 72, identifier:parser; 73, identifier:compile; 74, argument_list; 74, 75; 75, identifier:model; 76, if_statement; 76, 77; 76, 81; 77, not_operator; 77, 78; 78, attribute; 78, 79; 78, 80; 79, identifier:args; 80, identifier:disable_optimizer; 81, block; 81, 82; 81, 88; 82, expression_statement; 82, 83; 83, assignment; 83, 84; 83, 85; 84, identifier:opt; 85, call; 85, 86; 85, 87; 86, identifier:SensorGraphOptimizer; 87, argument_list; 88, expression_statement; 88, 89; 89, call; 89, 90; 89, 93; 90, attribute; 90, 91; 90, 92; 91, identifier:opt; 92, identifier:optimize; 93, argument_list; 93, 94; 93, 97; 94, attribute; 94, 95; 94, 96; 95, identifier:parser; 96, identifier:sensor_graph; 97, keyword_argument; 97, 98; 97, 99; 98, identifier:model; 99, identifier:model; 100, expression_statement; 100, 101; 101, assignment; 101, 102; 101, 103; 102, identifier:graph; 103, attribute; 103, 104; 103, 105; 104, identifier:parser; 105, identifier:sensor_graph; 106, expression_statement; 106, 107; 107, assignment; 107, 108; 107, 109; 108, identifier:sim; 109, call; 109, 110; 109, 111; 110, identifier:SensorGraphSimulator; 111, argument_list; 111, 112; 112, identifier:graph; 113, for_statement; 113, 114; 113, 115; 113, 118; 114, identifier:stop; 115, attribute; 115, 116; 115, 117; 116, identifier:args; 117, identifier:stop; 118, block; 118, 119; 119, expression_statement; 119, 120; 120, call; 120, 121; 120, 124; 121, attribute; 121, 122; 121, 123; 122, identifier:sim; 123, identifier:stop_condition; 124, argument_list; 124, 125; 125, identifier:stop; 126, for_statement; 126, 127; 126, 128; 126, 131; 127, identifier:watch; 128, attribute; 128, 129; 128, 130; 129, identifier:args; 130, identifier:watch; 131, block; 131, 132; 131, 141; 132, expression_statement; 132, 133; 133, assignment; 133, 134; 133, 135; 134, identifier:watch_sel; 135, call; 135, 136; 135, 139; 136, attribute; 136, 137; 136, 138; 137, identifier:DataStreamSelector; 138, identifier:FromString; 139, argument_list; 139, 140; 140, identifier:watch; 141, expression_statement; 141, 142; 142, call; 142, 143; 142, 148; 143, attribute; 143, 144; 143, 147; 144, attribute; 144, 145; 144, 146; 145, identifier:graph; 146, identifier:sensor_log; 147, identifier:watch; 148, argument_list; 148, 149; 148, 150; 149, identifier:watch_sel; 150, identifier:watch_printer; 151, comment; 152, if_statement; 152, 153; 152, 158; 153, comparison_operator:is; 153, 154; 153, 157; 154, attribute; 154, 155; 154, 156; 155, identifier:args; 156, identifier:semihost_device; 157, None; 158, block; 158, 159; 158, 171; 159, expression_statement; 159, 160; 160, assignment; 160, 161; 160, 162; 161, identifier:executor; 162, call; 162, 163; 162, 164; 163, identifier:SemihostedRPCExecutor; 164, argument_list; 164, 165; 164, 168; 165, attribute; 165, 166; 165, 167; 166, identifier:args; 167, identifier:port; 168, attribute; 168, 169; 168, 170; 169, identifier:args; 170, identifier:semihost_device; 171, expression_statement; 171, 172; 172, assignment; 172, 173; 172, 176; 173, attribute; 173, 174; 173, 175; 174, identifier:sim; 175, identifier:rpc_executor; 176, identifier:executor; 177, for_statement; 177, 178; 177, 179; 177, 182; 178, identifier:mock; 179, attribute; 179, 180; 179, 181; 180, identifier:args; 181, identifier:mock_rpc; 182, block; 182, 183; 182, 193; 183, expression_statement; 183, 184; 184, assignment; 184, 185; 184, 189; 185, pattern_list; 185, 186; 185, 187; 185, 188; 186, identifier:slot; 187, identifier:rpc_id; 188, identifier:value; 189, call; 189, 190; 189, 191; 190, identifier:process_mock_rpc; 191, argument_list; 191, 192; 192, identifier:mock; 193, expression_statement; 193, 194; 194, call; 194, 195; 194, 200; 195, attribute; 195, 196; 195, 199; 196, attribute; 196, 197; 196, 198; 197, identifier:sim; 198, identifier:rpc_executor; 199, identifier:mock; 200, argument_list; 200, 201; 200, 202; 200, 203; 201, identifier:slot; 202, identifier:rpc_id; 203, identifier:value; 204, for_statement; 204, 205; 204, 206; 204, 209; 205, identifier:stim; 206, attribute; 206, 207; 206, 208; 207, identifier:args; 208, identifier:stimulus; 209, block; 209, 210; 210, expression_statement; 210, 211; 211, call; 211, 212; 211, 215; 212, attribute; 212, 213; 212, 214; 213, identifier:sim; 214, identifier:stimulus; 215, argument_list; 215, 216; 216, identifier:stim; 217, expression_statement; 217, 218; 218, call; 218, 219; 218, 222; 219, attribute; 219, 220; 219, 221; 220, identifier:graph; 221, identifier:load_constants; 222, argument_list; 223, if_statement; 223, 224; 223, 229; 224, comparison_operator:is; 224, 225; 224, 228; 225, attribute; 225, 226; 225, 227; 226, identifier:args; 227, identifier:trace; 228, None; 229, block; 229, 230; 230, expression_statement; 230, 231; 231, call; 231, 232; 231, 235; 232, attribute; 232, 233; 232, 234; 233, identifier:sim; 234, identifier:record_trace; 235, argument_list; 236, try_statement; 236, 237; 236, 263; 237, block; 237, 238; 237, 251; 238, if_statement; 238, 239; 238, 242; 239, attribute; 239, 240; 239, 241; 240, identifier:args; 241, identifier:connected; 242, block; 242, 243; 243, expression_statement; 243, 244; 244, call; 244, 245; 244, 248; 245, attribute; 245, 246; 245, 247; 246, identifier:sim; 247, identifier:step; 248, argument_list; 248, 249; 248, 250; 249, identifier:user_connected; 250, integer:8; 251, expression_statement; 251, 252; 252, call; 252, 253; 252, 256; 253, attribute; 253, 254; 253, 255; 254, identifier:sim; 255, identifier:run; 256, argument_list; 256, 257; 257, keyword_argument; 257, 258; 257, 259; 258, identifier:accelerated; 259, not_operator; 259, 260; 260, attribute; 260, 261; 260, 262; 261, identifier:args; 262, identifier:realtime; 263, except_clause; 263, 264; 263, 265; 264, identifier:KeyboardInterrupt; 265, block; 265, 266; 266, pass_statement; 267, if_statement; 267, 268; 267, 273; 268, comparison_operator:is; 268, 269; 268, 272; 269, attribute; 269, 270; 269, 271; 270, identifier:args; 271, identifier:trace; 272, None; 273, block; 273, 274; 274, expression_statement; 274, 275; 275, call; 275, 276; 275, 281; 276, attribute; 276, 277; 276, 280; 277, attribute; 277, 278; 277, 279; 278, identifier:sim; 279, identifier:trace; 280, identifier:save; 281, argument_list; 281, 282; 282, attribute; 282, 283; 282, 284; 283, identifier:args; 284, identifier:trace; 285, finally_clause; 285, 286; 286, block; 286, 287; 287, if_statement; 287, 288; 287, 291; 288, comparison_operator:is; 288, 289; 288, 290; 289, identifier:executor; 290, None; 291, block; 291, 292; 292, expression_statement; 292, 293; 293, call; 293, 294; 293, 299; 294, attribute; 294, 295; 294, 298; 295, attribute; 295, 296; 295, 297; 296, identifier:executor; 297, identifier:hw; 298, identifier:close; 299, argument_list; 300, return_statement; 300, 301; 301, integer:0 | def main(argv=None):
"""Main entry point for iotile sensorgraph simulator.
This is the iotile-sgrun command line program. It takes
an optional set of command line parameters to allow for
testing.
Args:
argv (list of str): An optional set of command line
parameters. If not passed, these are taken from
sys.argv.
"""
if argv is None:
argv = sys.argv[1:]
try:
executor = None
parser = build_args()
args = parser.parse_args(args=argv)
model = DeviceModel()
parser = SensorGraphFileParser()
parser.parse_file(args.sensor_graph)
parser.compile(model)
if not args.disable_optimizer:
opt = SensorGraphOptimizer()
opt.optimize(parser.sensor_graph, model=model)
graph = parser.sensor_graph
sim = SensorGraphSimulator(graph)
for stop in args.stop:
sim.stop_condition(stop)
for watch in args.watch:
watch_sel = DataStreamSelector.FromString(watch)
graph.sensor_log.watch(watch_sel, watch_printer)
# If we are semihosting, create the appropriate executor connected to the device
if args.semihost_device is not None:
executor = SemihostedRPCExecutor(args.port, args.semihost_device)
sim.rpc_executor = executor
for mock in args.mock_rpc:
slot, rpc_id, value = process_mock_rpc(mock)
sim.rpc_executor.mock(slot, rpc_id, value)
for stim in args.stimulus:
sim.stimulus(stim)
graph.load_constants()
if args.trace is not None:
sim.record_trace()
try:
if args.connected:
sim.step(user_connected, 8)
sim.run(accelerated=not args.realtime)
except KeyboardInterrupt:
pass
if args.trace is not None:
sim.trace.save(args.trace)
finally:
if executor is not None:
executor.hw.close()
return 0 |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_update_pot_file; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:target; 5, identifier:source; 6, identifier:env; 7, block; 7, 8; 7, 10; 7, 13; 7, 16; 7, 20; 7, 29; 7, 30; 7, 31; 7, 41; 7, 49; 7, 57; 7, 68; 7, 69; 7, 70; 7, 87; 7, 88; 7, 98; 7, 99; 7, 176; 7, 177; 7, 194; 7, 195; 7, 205; 7, 212; 7, 213; 7, 218; 7, 224; 7, 332; 8, expression_statement; 8, 9; 9, comment; 10, import_statement; 10, 11; 11, dotted_name; 11, 12; 12, identifier:re; 13, import_statement; 13, 14; 14, dotted_name; 14, 15; 15, identifier:os; 16, import_statement; 16, 17; 17, dotted_name; 17, 18; 17, 19; 18, identifier:SCons; 19, identifier:Action; 20, expression_statement; 20, 21; 21, assignment; 21, 22; 21, 23; 22, identifier:nop; 23, lambda; 23, 24; 23, 28; 24, lambda_parameters; 24, 25; 24, 26; 24, 27; 25, identifier:target; 26, identifier:source; 27, identifier:env; 28, integer:0; 29, comment; 30, comment; 31, expression_statement; 31, 32; 32, assignment; 32, 33; 32, 34; 33, identifier:save_cwd; 34, call; 34, 35; 34, 40; 35, attribute; 35, 36; 35, 39; 36, attribute; 36, 37; 36, 38; 37, identifier:env; 38, identifier:fs; 39, identifier:getcwd; 40, argument_list; 41, expression_statement; 41, 42; 42, assignment; 42, 43; 42, 44; 43, identifier:save_os_cwd; 44, call; 44, 45; 44, 48; 45, attribute; 45, 46; 45, 47; 46, identifier:os; 47, identifier:getcwd; 48, argument_list; 49, expression_statement; 49, 50; 50, assignment; 50, 51; 50, 52; 51, identifier:chdir; 52, attribute; 52, 53; 52, 56; 53, subscript; 53, 54; 53, 55; 54, identifier:target; 55, integer:0; 56, identifier:dir; 57, expression_statement; 57, 58; 58, assignment; 58, 59; 58, 60; 59, identifier:chdir_str; 60, call; 60, 61; 60, 62; 61, identifier:repr; 62, argument_list; 62, 63; 63, call; 63, 64; 63, 67; 64, attribute; 64, 65; 64, 66; 65, identifier:chdir; 66, identifier:get_abspath; 67, argument_list; 68, comment; 69, comment; 70, expression_statement; 70, 71; 71, call; 71, 72; 71, 75; 72, attribute; 72, 73; 72, 74; 73, identifier:env; 74, identifier:Execute; 75, argument_list; 75, 76; 76, call; 76, 77; 76, 82; 77, attribute; 77, 78; 77, 81; 78, attribute; 78, 79; 78, 80; 79, identifier:SCons; 80, identifier:Action; 81, identifier:Action; 82, argument_list; 82, 83; 82, 84; 83, identifier:nop; 84, binary_operator:+; 84, 85; 84, 86; 85, string:"Entering "; 86, identifier:chdir_str; 87, comment; 88, expression_statement; 88, 89; 89, call; 89, 90; 89, 95; 90, attribute; 90, 91; 90, 94; 91, attribute; 91, 92; 91, 93; 92, identifier:env; 93, identifier:fs; 94, identifier:chdir; 95, argument_list; 95, 96; 95, 97; 96, identifier:chdir; 97, integer:1; 98, comment; 99, try_statement; 99, 100; 99, 137; 100, block; 100, 101; 100, 109; 100, 125; 101, expression_statement; 101, 102; 102, assignment; 102, 103; 102, 104; 103, identifier:cmd; 104, call; 104, 105; 104, 106; 105, identifier:_CmdRunner; 106, argument_list; 106, 107; 106, 108; 107, string:'$XGETTEXTCOM'; 108, string:'$XGETTEXTCOMSTR'; 109, expression_statement; 109, 110; 110, assignment; 110, 111; 110, 112; 111, identifier:action; 112, call; 112, 113; 112, 118; 113, attribute; 113, 114; 113, 117; 114, attribute; 114, 115; 114, 116; 115, identifier:SCons; 116, identifier:Action; 117, identifier:Action; 118, argument_list; 118, 119; 118, 120; 119, identifier:cmd; 120, keyword_argument; 120, 121; 120, 122; 121, identifier:strfunction; 122, attribute; 122, 123; 122, 124; 123, identifier:cmd; 124, identifier:strfunction; 125, expression_statement; 125, 126; 126, assignment; 126, 127; 126, 128; 127, identifier:status; 128, call; 128, 129; 128, 130; 129, identifier:action; 130, argument_list; 130, 131; 130, 135; 130, 136; 131, list:[target[0]]; 131, 132; 132, subscript; 132, 133; 132, 134; 133, identifier:target; 134, integer:0; 135, identifier:source; 136, identifier:env; 137, except_clause; 137, 138; 137, 139; 138, comment; 139, block; 139, 140; 139, 157; 139, 158; 139, 168; 139, 175; 140, expression_statement; 140, 141; 141, call; 141, 142; 141, 145; 142, attribute; 142, 143; 142, 144; 143, identifier:env; 144, identifier:Execute; 145, argument_list; 145, 146; 146, call; 146, 147; 146, 152; 147, attribute; 147, 148; 147, 151; 148, attribute; 148, 149; 148, 150; 149, identifier:SCons; 150, identifier:Action; 151, identifier:Action; 152, argument_list; 152, 153; 152, 154; 153, identifier:nop; 154, binary_operator:+; 154, 155; 154, 156; 155, string:"Leaving "; 156, identifier:chdir_str; 157, comment; 158, expression_statement; 158, 159; 159, call; 159, 160; 159, 165; 160, attribute; 160, 161; 160, 164; 161, attribute; 161, 162; 161, 163; 162, identifier:env; 163, identifier:fs; 164, identifier:chdir; 165, argument_list; 165, 166; 165, 167; 166, identifier:save_cwd; 167, integer:0; 168, expression_statement; 168, 169; 169, call; 169, 170; 169, 173; 170, attribute; 170, 171; 170, 172; 171, identifier:os; 172, identifier:chdir; 173, argument_list; 173, 174; 174, identifier:save_os_cwd; 175, raise_statement; 176, comment; 177, expression_statement; 177, 178; 178, call; 178, 179; 178, 182; 179, attribute; 179, 180; 179, 181; 180, identifier:env; 181, identifier:Execute; 182, argument_list; 182, 183; 183, call; 183, 184; 183, 189; 184, attribute; 184, 185; 184, 188; 185, attribute; 185, 186; 185, 187; 186, identifier:SCons; 187, identifier:Action; 188, identifier:Action; 189, argument_list; 189, 190; 189, 191; 190, identifier:nop; 191, binary_operator:+; 191, 192; 191, 193; 192, string:"Leaving "; 193, identifier:chdir_str; 194, comment; 195, expression_statement; 195, 196; 196, call; 196, 197; 196, 202; 197, attribute; 197, 198; 197, 201; 198, attribute; 198, 199; 198, 200; 199, identifier:env; 200, identifier:fs; 201, identifier:chdir; 202, argument_list; 202, 203; 202, 204; 203, identifier:save_cwd; 204, integer:0; 205, expression_statement; 205, 206; 206, call; 206, 207; 206, 210; 207, attribute; 207, 208; 207, 209; 208, identifier:os; 209, identifier:chdir; 210, argument_list; 210, 211; 211, identifier:save_os_cwd; 212, comment; 213, if_statement; 213, 214; 213, 215; 214, identifier:status; 215, block; 215, 216; 216, return_statement; 216, 217; 217, identifier:status; 218, expression_statement; 218, 219; 219, assignment; 219, 220; 219, 221; 220, identifier:new_content; 221, attribute; 221, 222; 221, 223; 222, identifier:cmd; 223, identifier:out; 224, if_statement; 224, 225; 224, 227; 224, 228; 224, 229; 224, 238; 225, not_operator; 225, 226; 226, identifier:new_content; 227, comment; 228, comment; 229, block; 229, 230; 229, 234; 230, expression_statement; 230, 231; 231, assignment; 231, 232; 231, 233; 232, identifier:needs_update; 233, False; 234, expression_statement; 234, 235; 235, assignment; 235, 236; 235, 237; 236, identifier:explain; 237, string:"no internationalized messages encountered"; 238, else_clause; 238, 239; 239, block; 239, 240; 240, if_statement; 240, 241; 240, 248; 240, 249; 240, 250; 240, 321; 241, call; 241, 242; 241, 247; 242, attribute; 242, 243; 242, 246; 243, subscript; 243, 244; 243, 245; 244, identifier:target; 245, integer:0; 246, identifier:exists; 247, argument_list; 248, comment; 249, comment; 250, block; 250, 251; 250, 261; 250, 273; 250, 284; 250, 295; 251, expression_statement; 251, 252; 252, assignment; 252, 253; 252, 254; 253, identifier:old_content; 254, call; 254, 255; 254, 260; 255, attribute; 255, 256; 255, 259; 256, subscript; 256, 257; 256, 258; 257, identifier:target; 258, integer:0; 259, identifier:get_text_contents; 260, argument_list; 261, expression_statement; 261, 262; 262, assignment; 262, 263; 262, 264; 263, identifier:re_cdate; 264, call; 264, 265; 264, 268; 265, attribute; 265, 266; 265, 267; 266, identifier:re; 267, identifier:compile; 268, argument_list; 268, 269; 268, 270; 269, string:r'^"POT-Creation-Date: .*"$[\r\n]?'; 270, attribute; 270, 271; 270, 272; 271, identifier:re; 272, identifier:M; 273, expression_statement; 273, 274; 274, assignment; 274, 275; 274, 276; 275, identifier:old_content_nocdate; 276, call; 276, 277; 276, 280; 277, attribute; 277, 278; 277, 279; 278, identifier:re; 279, identifier:sub; 280, argument_list; 280, 281; 280, 282; 280, 283; 281, identifier:re_cdate; 282, string:""; 283, identifier:old_content; 284, expression_statement; 284, 285; 285, assignment; 285, 286; 285, 287; 286, identifier:new_content_nocdate; 287, call; 287, 288; 287, 291; 288, attribute; 288, 289; 288, 290; 289, identifier:re; 290, identifier:sub; 291, argument_list; 291, 292; 291, 293; 291, 294; 292, identifier:re_cdate; 293, string:""; 294, identifier:new_content; 295, if_statement; 295, 296; 295, 300; 295, 301; 295, 310; 296, parenthesized_expression; 296, 297; 297, comparison_operator:==; 297, 298; 297, 299; 298, identifier:old_content_nocdate; 299, identifier:new_content_nocdate; 300, comment; 301, block; 301, 302; 301, 306; 302, expression_statement; 302, 303; 303, assignment; 303, 304; 303, 305; 304, identifier:needs_update; 305, False; 306, expression_statement; 306, 307; 307, assignment; 307, 308; 307, 309; 308, identifier:explain; 309, string:"messages in file found to be up-to-date"; 310, else_clause; 310, 311; 310, 312; 311, comment; 312, block; 312, 313; 312, 317; 313, expression_statement; 313, 314; 314, assignment; 314, 315; 314, 316; 315, identifier:needs_update; 316, True; 317, expression_statement; 317, 318; 318, assignment; 318, 319; 318, 320; 319, identifier:explain; 320, string:"messages in file were outdated"; 321, else_clause; 321, 322; 321, 323; 322, comment; 323, block; 323, 324; 323, 328; 324, expression_statement; 324, 325; 325, assignment; 325, 326; 325, 327; 326, identifier:needs_update; 327, True; 328, expression_statement; 328, 329; 329, assignment; 329, 330; 329, 331; 330, identifier:explain; 331, string:"new file"; 332, if_statement; 332, 333; 332, 334; 332, 335; 332, 399; 333, identifier:needs_update; 334, comment; 335, block; 335, 336; 335, 356; 335, 371; 335, 384; 335, 391; 335, 397; 336, expression_statement; 336, 337; 337, assignment; 337, 338; 337, 339; 338, identifier:msg; 339, binary_operator:+; 339, 340; 339, 355; 340, binary_operator:+; 340, 341; 340, 354; 341, binary_operator:+; 341, 342; 341, 353; 342, binary_operator:+; 342, 343; 342, 344; 343, string:"Writing "; 344, call; 344, 345; 344, 346; 345, identifier:repr; 346, argument_list; 346, 347; 347, call; 347, 348; 347, 349; 348, identifier:str; 349, argument_list; 349, 350; 350, subscript; 350, 351; 350, 352; 351, identifier:target; 352, integer:0; 353, string:" ("; 354, identifier:explain; 355, string:")"; 356, expression_statement; 356, 357; 357, call; 357, 358; 357, 361; 358, attribute; 358, 359; 358, 360; 359, identifier:env; 360, identifier:Execute; 361, argument_list; 361, 362; 362, call; 362, 363; 362, 368; 363, attribute; 363, 364; 363, 367; 364, attribute; 364, 365; 364, 366; 365, identifier:SCons; 366, identifier:Action; 367, identifier:Action; 368, argument_list; 368, 369; 368, 370; 369, identifier:nop; 370, identifier:msg; 371, expression_statement; 371, 372; 372, assignment; 372, 373; 372, 374; 373, identifier:f; 374, call; 374, 375; 374, 376; 375, identifier:open; 376, argument_list; 376, 377; 376, 383; 377, call; 377, 378; 377, 379; 378, identifier:str; 379, argument_list; 379, 380; 380, subscript; 380, 381; 380, 382; 381, identifier:target; 382, integer:0; 383, string:"w"; 384, expression_statement; 384, 385; 385, call; 385, 386; 385, 389; 386, attribute; 386, 387; 386, 388; 387, identifier:f; 388, identifier:write; 389, argument_list; 389, 390; 390, identifier:new_content; 391, expression_statement; 391, 392; 392, call; 392, 393; 392, 396; 393, attribute; 393, 394; 393, 395; 394, identifier:f; 395, identifier:close; 396, argument_list; 397, return_statement; 397, 398; 398, integer:0; 399, else_clause; 399, 400; 399, 401; 400, comment; 401, block; 401, 402; 401, 422; 401, 437; 402, expression_statement; 402, 403; 403, assignment; 403, 404; 403, 405; 404, identifier:msg; 405, binary_operator:+; 405, 406; 405, 421; 406, binary_operator:+; 406, 407; 406, 420; 407, binary_operator:+; 407, 408; 407, 419; 408, binary_operator:+; 408, 409; 408, 410; 409, string:"Not writing "; 410, call; 410, 411; 410, 412; 411, identifier:repr; 412, argument_list; 412, 413; 413, call; 413, 414; 413, 415; 414, identifier:str; 415, argument_list; 415, 416; 416, subscript; 416, 417; 416, 418; 417, identifier:target; 418, integer:0; 419, string:" ("; 420, identifier:explain; 421, string:")"; 422, expression_statement; 422, 423; 423, call; 423, 424; 423, 427; 424, attribute; 424, 425; 424, 426; 425, identifier:env; 426, identifier:Execute; 427, argument_list; 427, 428; 428, call; 428, 429; 428, 434; 429, attribute; 429, 430; 429, 433; 430, attribute; 430, 431; 430, 432; 431, identifier:SCons; 432, identifier:Action; 433, identifier:Action; 434, argument_list; 434, 435; 434, 436; 435, identifier:nop; 436, identifier:msg; 437, return_statement; 437, 438; 438, integer:0 | def _update_pot_file(target, source, env):
""" Action function for `POTUpdate` builder """
import re
import os
import SCons.Action
nop = lambda target, source, env: 0
# Save scons cwd and os cwd (NOTE: they may be different. After the job, we
# revert each one to its original state).
save_cwd = env.fs.getcwd()
save_os_cwd = os.getcwd()
chdir = target[0].dir
chdir_str = repr(chdir.get_abspath())
# Print chdir message (employ SCons.Action.Action for that. It knows better
# than me how to to this correctly).
env.Execute(SCons.Action.Action(nop, "Entering " + chdir_str))
# Go to target's directory and do our job
env.fs.chdir(chdir, 1) # Go into target's directory
try:
cmd = _CmdRunner('$XGETTEXTCOM', '$XGETTEXTCOMSTR')
action = SCons.Action.Action(cmd, strfunction=cmd.strfunction)
status = action([target[0]], source, env)
except:
# Something went wrong.
env.Execute(SCons.Action.Action(nop, "Leaving " + chdir_str))
# Revert working dirs to previous state and re-throw exception.
env.fs.chdir(save_cwd, 0)
os.chdir(save_os_cwd)
raise
# Print chdir message.
env.Execute(SCons.Action.Action(nop, "Leaving " + chdir_str))
# Revert working dirs to previous state.
env.fs.chdir(save_cwd, 0)
os.chdir(save_os_cwd)
# If the command was not successfull, return error code.
if status: return status
new_content = cmd.out
if not new_content:
# When xgettext finds no internationalized messages, no *.pot is created
# (because we don't want to bother translators with empty POT files).
needs_update = False
explain = "no internationalized messages encountered"
else:
if target[0].exists():
# If the file already exists, it's left unaltered unless its messages
# are outdated (w.r.t. to these recovered by xgettext from sources).
old_content = target[0].get_text_contents()
re_cdate = re.compile(r'^"POT-Creation-Date: .*"$[\r\n]?', re.M)
old_content_nocdate = re.sub(re_cdate, "", old_content)
new_content_nocdate = re.sub(re_cdate, "", new_content)
if (old_content_nocdate == new_content_nocdate):
# Messages are up-to-date
needs_update = False
explain = "messages in file found to be up-to-date"
else:
# Messages are outdated
needs_update = True
explain = "messages in file were outdated"
else:
# No POT file found, create new one
needs_update = True
explain = "new file"
if needs_update:
# Print message employing SCons.Action.Action for that.
msg = "Writing " + repr(str(target[0])) + " (" + explain + ")"
env.Execute(SCons.Action.Action(nop, msg))
f = open(str(target[0]), "w")
f.write(new_content)
f.close()
return 0
else:
# Print message employing SCons.Action.Action for that.
msg = "Not writing " + repr(str(target[0])) + " (" + explain + ")"
env.Execute(SCons.Action.Action(nop, msg))
return 0 |
Subsets and Splits