pile_js / EinsteinsWorkshop__BlocksCAD.jsonl
Hamhams's picture
commit files to HF hub
c7f4bd0
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"blockscad\/msg\/create_messages.py","language":"python","identifier":"main","parameters":"()","argument_list":"","return_statement":"","docstring":"Generate .js files defining Blockly core and language messages.","docstring_summary":"Generate .js files defining Blockly core and language messages.","docstring_tokens":["Generate",".","js","files","defining","Blockly","core","and","language","messages","."],"function":"def main():\n \"\"\"Generate .js files defining Blockly core and language messages.\"\"\"\n\n # Process command-line arguments.\n parser = argparse.ArgumentParser(description='Convert JSON files to JS.')\n parser.add_argument('--source_lang', default='en',\n help='ISO 639-1 source language code')\n parser.add_argument('--source_lang_file',\n default=os.path.join('json', 'en.json'),\n help='Path to .json file for source language')\n parser.add_argument('--source_synonym_file',\n default=os.path.join('json', 'synonyms.json'),\n help='Path to .json file with synonym definitions')\n parser.add_argument('--output_dir', default='js\/',\n help='relative directory for output files')\n parser.add_argument('--key_file', default='keys.json',\n help='relative path to input keys file')\n parser.add_argument('--quiet', action='store_true', default=False,\n help='do not write anything to standard output')\n parser.add_argument('files', nargs='+', help='input files')\n args = parser.parse_args()\n if not args.output_dir.endswith(os.path.sep):\n args.output_dir += os.path.sep\n\n # Read in source language .json file, which provides any values missing\n # in target languages' .json files.\n source_defs = read_json_file(os.path.join(os.curdir, args.source_lang_file))\n # Make sure the source file doesn't contain a newline or carriage return.\n for key, value in source_defs.items():\n if _NEWLINE_PATTERN.search(value):\n print('ERROR: definition of {0} in {1} contained a newline character.'.\n format(key, args.source_lang_file))\n sys.exit(1)\n sorted_keys = source_defs.keys()\n sorted_keys.sort()\n\n # Read in synonyms file, which must be output in every language.\n synonym_defs = read_json_file(os.path.join(\n os.curdir, args.source_synonym_file))\n synonym_text = '\\n'.join(['Blockscad.Msg.{0} = Blockscad.Msg.{1};'.format(\n key, synonym_defs[key]) for key in synonym_defs])\n\n # Create each output file.\n for arg_file in args.files:\n (_, filename) = os.path.split(arg_file)\n target_lang = filename[:filename.index('.')]\n if target_lang not in ('qqq', 'keys', 'synonyms'):\n target_defs = read_json_file(os.path.join(os.curdir, arg_file))\n\n # Verify that keys are 'ascii'\n bad_keys = [key for key in target_defs if not string_is_ascii(key)]\n if bad_keys:\n print(u'These keys in {0} contain non ascii characters: {1}'.format(\n filename, ', '.join(bad_keys)))\n\n # If there's a '\\n' or '\\r', remove it and print a warning.\n for key, value in target_defs.items():\n if _NEWLINE_PATTERN.search(value):\n print(u'WARNING: definition of {0} in {1} contained '\n 'a newline character.'.\n format(key, arg_file))\n target_defs[key] = _NEWLINE_PATTERN.sub(' ', value)\n\n # Output file.\n outname = os.path.join(os.curdir, args.output_dir, target_lang + '.js')\n with codecs.open(outname, 'w', 'utf-8') as outfile:\n outfile.write(\n \"\"\"\/\/ This file was automatically generated. Do not modify.\n\n'use strict';\n\ngoog.provide('Blockscad.Msg.{0}');\n\n\n\"\"\".format(target_lang.replace('-', '.')))\n # For each key in the source language file, output the target value\n # if present; otherwise, output the source language value with a\n # warning comment.\n for key in sorted_keys:\n if key in target_defs:\n value = target_defs[key]\n comment = ''\n del target_defs[key]\n else:\n value = source_defs[key]\n comment = ' \/\/ untranslated'\n value = value.replace('\"', '\\\\\"')\n outfile.write(u'Blockscad.Msg.{0} = \"{1}\";{2}\\n'.format(\n key, value, comment))\n\n # Announce any keys defined only for target language.\n if target_defs:\n extra_keys = [key for key in target_defs if key not in synonym_defs]\n synonym_keys = [key for key in target_defs if key in synonym_defs]\n if not args.quiet:\n if extra_keys:\n print(u'These extra keys appeared in {0}: {1}'.format(\n filename, ', '.join(extra_keys)))\n if synonym_keys:\n print(u'These synonym keys appeared in {0}: {1}'.format(\n filename, ', '.join(synonym_keys)))\n\n outfile.write(synonym_text)\n\n if not args.quiet:\n print('Created {0}.'.format(outname))","function_tokens":["def","main","(",")",":","# Process command-line arguments.","parser","=","argparse",".","ArgumentParser","(","description","=","'Convert JSON files to JS.'",")","parser",".","add_argument","(","'--source_lang'",",","default","=","'en'",",","help","=","'ISO 639-1 source language code'",")","parser",".","add_argument","(","'--source_lang_file'",",","default","=","os",".","path",".","join","(","'json'",",","'en.json'",")",",","help","=","'Path to .json file for source language'",")","parser",".","add_argument","(","'--source_synonym_file'",",","default","=","os",".","path",".","join","(","'json'",",","'synonyms.json'",")",",","help","=","'Path to .json file with synonym definitions'",")","parser",".","add_argument","(","'--output_dir'",",","default","=","'js\/'",",","help","=","'relative directory for output files'",")","parser",".","add_argument","(","'--key_file'",",","default","=","'keys.json'",",","help","=","'relative path to input keys file'",")","parser",".","add_argument","(","'--quiet'",",","action","=","'store_true'",",","default","=","False",",","help","=","'do not write anything to standard output'",")","parser",".","add_argument","(","'files'",",","nargs","=","'+'",",","help","=","'input files'",")","args","=","parser",".","parse_args","(",")","if","not","args",".","output_dir",".","endswith","(","os",".","path",".","sep",")",":","args",".","output_dir","+=","os",".","path",".","sep","# Read in source language .json file, which provides any values missing","# in target languages' .json files.","source_defs","=","read_json_file","(","os",".","path",".","join","(","os",".","curdir",",","args",".","source_lang_file",")",")","# Make sure the source file doesn't contain a newline or carriage return.","for","key",",","value","in","source_defs",".","items","(",")",":","if","_NEWLINE_PATTERN",".","search","(","value",")",":","print","(","'ERROR: definition of {0} in {1} contained a newline character.'",".","format","(","key",",","args",".","source_lang_file",")",")","sys",".","exit","(","1",")","sorted_keys","=","source_defs",".","keys","(",")","sorted_keys",".","sort","(",")","# Read in synonyms file, which must be output in every language.","synonym_defs","=","read_json_file","(","os",".","path",".","join","(","os",".","curdir",",","args",".","source_synonym_file",")",")","synonym_text","=","'\\n'",".","join","(","[","'Blockscad.Msg.{0} = Blockscad.Msg.{1};'",".","format","(","key",",","synonym_defs","[","key","]",")","for","key","in","synonym_defs","]",")","# Create each output file.","for","arg_file","in","args",".","files",":","(","_",",","filename",")","=","os",".","path",".","split","(","arg_file",")","target_lang","=","filename","[",":","filename",".","index","(","'.'",")","]","if","target_lang","not","in","(","'qqq'",",","'keys'",",","'synonyms'",")",":","target_defs","=","read_json_file","(","os",".","path",".","join","(","os",".","curdir",",","arg_file",")",")","# Verify that keys are 'ascii'","bad_keys","=","[","key","for","key","in","target_defs","if","not","string_is_ascii","(","key",")","]","if","bad_keys",":","print","(","u'These keys in {0} contain non ascii characters: {1}'",".","format","(","filename",",","', '",".","join","(","bad_keys",")",")",")","# If there's a '\\n' or '\\r', remove it and print a warning.","for","key",",","value","in","target_defs",".","items","(",")",":","if","_NEWLINE_PATTERN",".","search","(","value",")",":","print","(","u'WARNING: definition of {0} in {1} contained '","'a newline character.'",".","format","(","key",",","arg_file",")",")","target_defs","[","key","]","=","_NEWLINE_PATTERN",".","sub","(","' '",",","value",")","# Output file.","outname","=","os",".","path",".","join","(","os",".","curdir",",","args",".","output_dir",",","target_lang","+","'.js'",")","with","codecs",".","open","(","outname",",","'w'",",","'utf-8'",")","as","outfile",":","outfile",".","write","(","\"\"\"\/\/ This file was automatically generated. Do not modify.\n\n'use strict';\n\ngoog.provide('Blockscad.Msg.{0}');\n\n\n\"\"\"",".","format","(","target_lang",".","replace","(","'-'",",","'.'",")",")",")","# For each key in the source language file, output the target value","# if present; otherwise, output the source language value with a","# warning comment.","for","key","in","sorted_keys",":","if","key","in","target_defs",":","value","=","target_defs","[","key","]","comment","=","''","del","target_defs","[","key","]","else",":","value","=","source_defs","[","key","]","comment","=","' \/\/ untranslated'","value","=","value",".","replace","(","'\"'",",","'\\\\\"'",")","outfile",".","write","(","u'Blockscad.Msg.{0} = \"{1}\";{2}\\n'",".","format","(","key",",","value",",","comment",")",")","# Announce any keys defined only for target language.","if","target_defs",":","extra_keys","=","[","key","for","key","in","target_defs","if","key","not","in","synonym_defs","]","synonym_keys","=","[","key","for","key","in","target_defs","if","key","in","synonym_defs","]","if","not","args",".","quiet",":","if","extra_keys",":","print","(","u'These extra keys appeared in {0}: {1}'",".","format","(","filename",",","', '",".","join","(","extra_keys",")",")",")","if","synonym_keys",":","print","(","u'These synonym keys appeared in {0}: {1}'",".","format","(","filename",",","', '",".","join","(","synonym_keys",")",")",")","outfile",".","write","(","synonym_text",")","if","not","args",".","quiet",":","print","(","'Created {0}.'",".","format","(","outname",")",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/blockscad\/msg\/create_messages.py#L39-L144"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"blockscad\/msg\/json_to_js.py","language":"python","identifier":"_create_xlf","parameters":"(target_lang)","argument_list":"","return_statement":"return out_file","docstring":"Creates a <target_lang>.xlf file for Soy.\n\n Args:\n target_lang: The ISO 639 language code for the target language.\n This is used in the name of the file and in the metadata.\n\n Returns:\n A pointer to a file to which the metadata has been written.\n\n Raises:\n IOError: An error occurred while opening or writing the file.","docstring_summary":"Creates a <target_lang>.xlf file for Soy.","docstring_tokens":["Creates","a","<target_lang",">",".","xlf","file","for","Soy","."],"function":"def _create_xlf(target_lang):\n \"\"\"Creates a <target_lang>.xlf file for Soy.\n\n Args:\n target_lang: The ISO 639 language code for the target language.\n This is used in the name of the file and in the metadata.\n\n Returns:\n A pointer to a file to which the metadata has been written.\n\n Raises:\n IOError: An error occurred while opening or writing the file.\n \"\"\"\n filename = os.path.join(os.curdir, args.output_dir, target_lang + '.xlf')\n out_file = codecs.open(filename, 'w', 'utf-8')\n out_file.write(\"\"\"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xliff version=\"1.2\" xmlns=\"urn:oasis:names:tc:xliff:document:1.2\">\n <file original=\"SoyMsgBundle\"\n datatype=\"x-soy-msg-bundle\"\n xml:space=\"preserve\"\n source-language=\"{0}\"\n target-language=\"{1}\">\n <body>\"\"\".format(args.source_lang, target_lang))\n return out_file","function_tokens":["def","_create_xlf","(","target_lang",")",":","filename","=","os",".","path",".","join","(","os",".","curdir",",","args",".","output_dir",",","target_lang","+","'.xlf'",")","out_file","=","codecs",".","open","(","filename",",","'w'",",","'utf-8'",")","out_file",".","write","(","\"\"\"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xliff version=\"1.2\" xmlns=\"urn:oasis:names:tc:xliff:document:1.2\">\n <file original=\"SoyMsgBundle\"\n datatype=\"x-soy-msg-bundle\"\n xml:space=\"preserve\"\n source-language=\"{0}\"\n target-language=\"{1}\">\n <body>\"\"\"",".","format","(","args",".","source_lang",",","target_lang",")",")","return","out_file"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/blockscad\/msg\/json_to_js.py#L34-L57"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"blockscad\/msg\/json_to_js.py","language":"python","identifier":"_close_xlf","parameters":"(xlf_file)","argument_list":"","return_statement":"","docstring":"Closes a <target_lang>.xlf file created with create_xlf().\n\n This includes writing the terminating XML.\n\n Args:\n xlf_file: A pointer to a file created by _create_xlf().\n\n Raises:\n IOError: An error occurred while writing to or closing the file.","docstring_summary":"Closes a <target_lang>.xlf file created with create_xlf().","docstring_tokens":["Closes","a","<target_lang",">",".","xlf","file","created","with","create_xlf","()","."],"function":"def _close_xlf(xlf_file):\n \"\"\"Closes a <target_lang>.xlf file created with create_xlf().\n\n This includes writing the terminating XML.\n\n Args:\n xlf_file: A pointer to a file created by _create_xlf().\n\n Raises:\n IOError: An error occurred while writing to or closing the file.\n \"\"\"\n xlf_file.write(\"\"\"\n <\/body>\n <\/file>\n<\/xliff>\n\"\"\")\n xlf_file.close()","function_tokens":["def","_close_xlf","(","xlf_file",")",":","xlf_file",".","write","(","\"\"\"\n <\/body>\n <\/file>\n<\/xliff>\n\"\"\"",")","xlf_file",".","close","(",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/blockscad\/msg\/json_to_js.py#L60-L76"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"blockscad\/msg\/json_to_js.py","language":"python","identifier":"_process_file","parameters":"(path_to_json, target_lang, key_dict)","argument_list":"","return_statement":"","docstring":"Creates an .xlf file corresponding to the specified .json input file.\n\n The name of the input file must be target_lang followed by '.json'.\n The name of the output file will be target_lang followed by '.js'.\n\n Args:\n path_to_json: Path to the directory of xx.json files.\n target_lang: A IETF language code (RFC 4646), such as 'es' or 'pt-br'.\n key_dict: Dictionary mapping Blockly keys (e.g., Maze.turnLeft) to\n Closure keys (hash numbers).\n\n Raises:\n IOError: An I\/O error occurred with an input or output file.\n InputError: Input JSON could not be parsed.\n KeyError: Key found in input file but not in key file.","docstring_summary":"Creates an .xlf file corresponding to the specified .json input file.","docstring_tokens":["Creates","an",".","xlf","file","corresponding","to","the","specified",".","json","input","file","."],"function":"def _process_file(path_to_json, target_lang, key_dict):\n \"\"\"Creates an .xlf file corresponding to the specified .json input file.\n\n The name of the input file must be target_lang followed by '.json'.\n The name of the output file will be target_lang followed by '.js'.\n\n Args:\n path_to_json: Path to the directory of xx.json files.\n target_lang: A IETF language code (RFC 4646), such as 'es' or 'pt-br'.\n key_dict: Dictionary mapping Blockly keys (e.g., Maze.turnLeft) to\n Closure keys (hash numbers).\n\n Raises:\n IOError: An I\/O error occurred with an input or output file.\n InputError: Input JSON could not be parsed.\n KeyError: Key found in input file but not in key file.\n \"\"\"\n keyfile = os.path.join(path_to_json, target_lang + '.json')\n j = read_json_file(keyfile)\n out_file = _create_xlf(target_lang)\n for key in j:\n if key != '@metadata':\n try:\n identifier = key_dict[key]\n except KeyError, e:\n print('Key \"%s\" is in %s but not in %s' %\n (key, keyfile, args.key_file))\n raise e\n target = j.get(key)\n out_file.write(u\"\"\"\n <trans-unit id=\"{0}\" datatype=\"html\">\n <target>{1}<\/target>\n <\/trans-unit>\"\"\".format(identifier, target))\n _close_xlf(out_file)","function_tokens":["def","_process_file","(","path_to_json",",","target_lang",",","key_dict",")",":","keyfile","=","os",".","path",".","join","(","path_to_json",",","target_lang","+","'.json'",")","j","=","read_json_file","(","keyfile",")","out_file","=","_create_xlf","(","target_lang",")","for","key","in","j",":","if","key","!=","'@metadata'",":","try",":","identifier","=","key_dict","[","key","]","except","KeyError",",","e",":","print","(","'Key \"%s\" is in %s but not in %s'","%","(","key",",","keyfile",",","args",".","key_file",")",")","raise","e","target","=","j",".","get","(","key",")","out_file",".","write","(","u\"\"\"\n <trans-unit id=\"{0}\" datatype=\"html\">\n <target>{1}<\/target>\n <\/trans-unit>\"\"\"",".","format","(","identifier",",","target",")",")","_close_xlf","(","out_file",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/blockscad\/msg\/json_to_js.py#L79-L112"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"blockscad\/msg\/json_to_js.py","language":"python","identifier":"main","parameters":"()","argument_list":"","return_statement":"","docstring":"Parses arguments and iterates over files.","docstring_summary":"Parses arguments and iterates over files.","docstring_tokens":["Parses","arguments","and","iterates","over","files","."],"function":"def main():\n \"\"\"Parses arguments and iterates over files.\"\"\"\n\n # Set up argument parser.\n parser = argparse.ArgumentParser(description='Convert JSON files to JS.')\n parser.add_argument('--source_lang', default='en',\n help='ISO 639-1 source language code')\n parser.add_argument('--output_dir', default='generated',\n help='relative directory for output files')\n parser.add_argument('--key_file', default='json' + os.path.sep + 'keys.json',\n help='relative path to input keys file')\n parser.add_argument('--template', default='template.soy')\n parser.add_argument('--path_to_jar',\n default='..' + os.path.sep + 'apps' + os.path.sep\n + '_soy',\n help='relative path from working directory to '\n 'SoyToJsSrcCompiler.jar')\n parser.add_argument('files', nargs='+', help='input files')\n\n # Initialize global variables.\n global args\n args = parser.parse_args()\n\n # Make sure output_dir ends with slash.\n if (not args.output_dir.endswith(os.path.sep)):\n args.output_dir += os.path.sep\n\n # Read in keys.json, mapping descriptions (e.g., Maze.turnLeft) to\n # Closure keys (long hash numbers).\n key_file = open(args.key_file)\n key_dict = json.load(key_file)\n key_file.close()\n\n # Process each input file.\n print('Creating .xlf files...')\n processed_langs = []\n if len(args.files) == 1:\n # Windows does not expand globs automatically.\n args.files = glob.glob(args.files[0])\n for arg_file in args.files:\n (path_to_json, filename) = os.path.split(arg_file)\n if not filename.endswith('.json'):\n raise InputError(filename, 'filenames must end with \".json\"')\n target_lang = filename[:filename.index('.')]\n if not target_lang in ('qqq', 'keys'):\n processed_langs.append(target_lang)\n _process_file(path_to_json, target_lang, key_dict)\n\n # Output command line for Closure compiler.\n if processed_langs:\n print('Creating .js files...')\n processed_lang_list = ','.join(processed_langs)\n subprocess.check_call([\n 'java',\n '-jar', os.path.join(args.path_to_jar, 'SoyToJsSrcCompiler.jar'),\n '--locales', processed_lang_list,\n '--messageFilePathFormat', args.output_dir + '{LOCALE}.xlf',\n '--outputPathFormat', args.output_dir + '{LOCALE}.js',\n '--srcs', args.template])\n if len(processed_langs) == 1:\n print('Created ' + processed_lang_list + '.js in ' + args.output_dir)\n else:\n print('Created {' + processed_lang_list + '}.js in ' + args.output_dir)\n\n for lang in processed_langs:\n os.remove(args.output_dir + lang + '.xlf')\n print('Removed .xlf files.')","function_tokens":["def","main","(",")",":","# Set up argument parser.","parser","=","argparse",".","ArgumentParser","(","description","=","'Convert JSON files to JS.'",")","parser",".","add_argument","(","'--source_lang'",",","default","=","'en'",",","help","=","'ISO 639-1 source language code'",")","parser",".","add_argument","(","'--output_dir'",",","default","=","'generated'",",","help","=","'relative directory for output files'",")","parser",".","add_argument","(","'--key_file'",",","default","=","'json'","+","os",".","path",".","sep","+","'keys.json'",",","help","=","'relative path to input keys file'",")","parser",".","add_argument","(","'--template'",",","default","=","'template.soy'",")","parser",".","add_argument","(","'--path_to_jar'",",","default","=","'..'","+","os",".","path",".","sep","+","'apps'","+","os",".","path",".","sep","+","'_soy'",",","help","=","'relative path from working directory to '","'SoyToJsSrcCompiler.jar'",")","parser",".","add_argument","(","'files'",",","nargs","=","'+'",",","help","=","'input files'",")","# Initialize global variables.","global","args","args","=","parser",".","parse_args","(",")","# Make sure output_dir ends with slash.","if","(","not","args",".","output_dir",".","endswith","(","os",".","path",".","sep",")",")",":","args",".","output_dir","+=","os",".","path",".","sep","# Read in keys.json, mapping descriptions (e.g., Maze.turnLeft) to","# Closure keys (long hash numbers).","key_file","=","open","(","args",".","key_file",")","key_dict","=","json",".","load","(","key_file",")","key_file",".","close","(",")","# Process each input file.","print","(","'Creating .xlf files...'",")","processed_langs","=","[","]","if","len","(","args",".","files",")","==","1",":","# Windows does not expand globs automatically.","args",".","files","=","glob",".","glob","(","args",".","files","[","0","]",")","for","arg_file","in","args",".","files",":","(","path_to_json",",","filename",")","=","os",".","path",".","split","(","arg_file",")","if","not","filename",".","endswith","(","'.json'",")",":","raise","InputError","(","filename",",","'filenames must end with \".json\"'",")","target_lang","=","filename","[",":","filename",".","index","(","'.'",")","]","if","not","target_lang","in","(","'qqq'",",","'keys'",")",":","processed_langs",".","append","(","target_lang",")","_process_file","(","path_to_json",",","target_lang",",","key_dict",")","# Output command line for Closure compiler.","if","processed_langs",":","print","(","'Creating .js files...'",")","processed_lang_list","=","','",".","join","(","processed_langs",")","subprocess",".","check_call","(","[","'java'",",","'-jar'",",","os",".","path",".","join","(","args",".","path_to_jar",",","'SoyToJsSrcCompiler.jar'",")",",","'--locales'",",","processed_lang_list",",","'--messageFilePathFormat'",",","args",".","output_dir","+","'{LOCALE}.xlf'",",","'--outputPathFormat'",",","args",".","output_dir","+","'{LOCALE}.js'",",","'--srcs'",",","args",".","template","]",")","if","len","(","processed_langs",")","==","1",":","print","(","'Created '","+","processed_lang_list","+","'.js in '","+","args",".","output_dir",")","else",":","print","(","'Created {'","+","processed_lang_list","+","'}.js in '","+","args",".","output_dir",")","for","lang","in","processed_langs",":","os",".","remove","(","args",".","output_dir","+","lang","+","'.xlf'",")","print","(","'Removed .xlf files.'",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/blockscad\/msg\/json_to_js.py#L115-L181"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"blockscad\/msg\/common.py","language":"python","identifier":"read_json_file","parameters":"(filename)","argument_list":"","return_statement":"","docstring":"Read a JSON file as UTF-8 into a dictionary, discarding @metadata.\n\n Args:\n filename: The filename, which must end \".json\".\n\n Returns:\n The dictionary.\n\n Raises:\n InputError: The filename did not end with \".json\" or an error occurred\n while opening or reading the file.","docstring_summary":"Read a JSON file as UTF-8 into a dictionary, discarding @metadata.","docstring_tokens":["Read","a","JSON","file","as","UTF","-","8","into","a","dictionary","discarding","@metadata","."],"function":"def read_json_file(filename):\n \"\"\"Read a JSON file as UTF-8 into a dictionary, discarding @metadata.\n\n Args:\n filename: The filename, which must end \".json\".\n\n Returns:\n The dictionary.\n\n Raises:\n InputError: The filename did not end with \".json\" or an error occurred\n while opening or reading the file.\n \"\"\"\n if not filename.endswith('.json'):\n raise InputError(filename, 'filenames must end with \".json\"')\n try:\n # Read in file.\n with codecs.open(filename, 'r', 'utf-8') as infile:\n defs = json.load(infile)\n if '@metadata' in defs:\n del defs['@metadata']\n return defs\n except ValueError, e:\n print('Error reading ' + filename)\n raise InputError(filename, str(e))","function_tokens":["def","read_json_file","(","filename",")",":","if","not","filename",".","endswith","(","'.json'",")",":","raise","InputError","(","filename",",","'filenames must end with \".json\"'",")","try",":","# Read in file.","with","codecs",".","open","(","filename",",","'r'",",","'utf-8'",")","as","infile",":","defs","=","json",".","load","(","infile",")","if","'@metadata'","in","defs",":","del","defs","[","'@metadata'","]","return","defs","except","ValueError",",","e",":","print","(","'Error reading '","+","filename",")","raise","InputError","(","filename",",","str","(","e",")",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/blockscad\/msg\/common.py#L40-L64"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"blockscad\/msg\/common.py","language":"python","identifier":"_create_qqq_file","parameters":"(output_dir)","argument_list":"","return_statement":"return qqq_file","docstring":"Creates a qqq.json file with message documentation for translatewiki.net.\n\n The file consists of key-value pairs, where the keys are message ids and\n the values are descriptions for the translators of the messages.\n What documentation exists for the format can be found at:\n http:\/\/translatewiki.net\/wiki\/Translating:Localisation_for_developers#Message_documentation\n\n The file should be closed by _close_qqq_file().\n\n Parameters:\n output_dir: The output directory.\n\n Returns:\n A pointer to a file to which a left brace and newline have been written.\n\n Raises:\n IOError: An error occurred while opening or writing the file.","docstring_summary":"Creates a qqq.json file with message documentation for translatewiki.net.","docstring_tokens":["Creates","a","qqq",".","json","file","with","message","documentation","for","translatewiki",".","net","."],"function":"def _create_qqq_file(output_dir):\n \"\"\"Creates a qqq.json file with message documentation for translatewiki.net.\n\n The file consists of key-value pairs, where the keys are message ids and\n the values are descriptions for the translators of the messages.\n What documentation exists for the format can be found at:\n http:\/\/translatewiki.net\/wiki\/Translating:Localisation_for_developers#Message_documentation\n\n The file should be closed by _close_qqq_file().\n\n Parameters:\n output_dir: The output directory.\n\n Returns:\n A pointer to a file to which a left brace and newline have been written.\n\n Raises:\n IOError: An error occurred while opening or writing the file.\n \"\"\"\n qqq_file_name = os.path.join(os.curdir, output_dir, 'qqq.json')\n qqq_file = codecs.open(qqq_file_name, 'w', 'utf-8')\n print 'Created file: ' + qqq_file_name\n qqq_file.write('{\\n')\n return qqq_file","function_tokens":["def","_create_qqq_file","(","output_dir",")",":","qqq_file_name","=","os",".","path",".","join","(","os",".","curdir",",","output_dir",",","'qqq.json'",")","qqq_file","=","codecs",".","open","(","qqq_file_name",",","'w'",",","'utf-8'",")","print","'Created file: '","+","qqq_file_name","qqq_file",".","write","(","'{\\n'",")","return","qqq_file"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/blockscad\/msg\/common.py#L67-L90"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"blockscad\/msg\/common.py","language":"python","identifier":"_close_qqq_file","parameters":"(qqq_file)","argument_list":"","return_statement":"","docstring":"Closes a qqq.json file created and opened by _create_qqq_file().\n\n This writes the final newlines and right brace.\n\n Args:\n qqq_file: A file created by _create_qqq_file().\n\n Raises:\n IOError: An error occurred while writing to or closing the file.","docstring_summary":"Closes a qqq.json file created and opened by _create_qqq_file().","docstring_tokens":["Closes","a","qqq",".","json","file","created","and","opened","by","_create_qqq_file","()","."],"function":"def _close_qqq_file(qqq_file):\n \"\"\"Closes a qqq.json file created and opened by _create_qqq_file().\n\n This writes the final newlines and right brace.\n\n Args:\n qqq_file: A file created by _create_qqq_file().\n\n Raises:\n IOError: An error occurred while writing to or closing the file.\n \"\"\"\n qqq_file.write('\\n}\\n')\n qqq_file.close()","function_tokens":["def","_close_qqq_file","(","qqq_file",")",":","qqq_file",".","write","(","'\\n}\\n'",")","qqq_file",".","close","(",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/blockscad\/msg\/common.py#L93-L105"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"blockscad\/msg\/common.py","language":"python","identifier":"_create_lang_file","parameters":"(author, lang, output_dir)","argument_list":"","return_statement":"return lang_file","docstring":"Creates a <lang>.json file for translatewiki.net.\n\n The file consists of metadata, followed by key-value pairs, where the keys\n are message ids and the values are the messages in the language specified\n by the corresponding command-line argument. The file should be closed by\n _close_lang_file().\n\n Args:\n author: Name and email address of contact for translators.\n lang: ISO 639-1 source language code.\n output_dir: Relative directory for output files.\n\n Returns:\n A pointer to a file to which the metadata has been written.\n\n Raises:\n IOError: An error occurred while opening or writing the file.","docstring_summary":"Creates a <lang>.json file for translatewiki.net.","docstring_tokens":["Creates","a","<lang",">",".","json","file","for","translatewiki",".","net","."],"function":"def _create_lang_file(author, lang, output_dir):\n \"\"\"Creates a <lang>.json file for translatewiki.net.\n\n The file consists of metadata, followed by key-value pairs, where the keys\n are message ids and the values are the messages in the language specified\n by the corresponding command-line argument. The file should be closed by\n _close_lang_file().\n\n Args:\n author: Name and email address of contact for translators.\n lang: ISO 639-1 source language code.\n output_dir: Relative directory for output files.\n\n Returns:\n A pointer to a file to which the metadata has been written.\n\n Raises:\n IOError: An error occurred while opening or writing the file.\n \"\"\"\n lang_file_name = os.path.join(os.curdir, output_dir, lang + '.json')\n lang_file = codecs.open(lang_file_name, 'w', 'utf-8')\n print 'Created file: ' + lang_file_name\n # string.format doesn't like printing braces, so break up our writes.\n lang_file.write('{\\n\\t\"@metadata\": {')\n lang_file.write(\"\"\"\n\\t\\t\"author\": \"{0}\",\n\\t\\t\"lastupdated\": \"{1}\",\n\\t\\t\"locale\": \"{2}\",\n\\t\\t\"messagedocumentation\" : \"qqq\"\n\"\"\".format(author, str(datetime.now()), lang))\n lang_file.write('\\t},\\n')\n return lang_file","function_tokens":["def","_create_lang_file","(","author",",","lang",",","output_dir",")",":","lang_file_name","=","os",".","path",".","join","(","os",".","curdir",",","output_dir",",","lang","+","'.json'",")","lang_file","=","codecs",".","open","(","lang_file_name",",","'w'",",","'utf-8'",")","print","'Created file: '","+","lang_file_name","# string.format doesn't like printing braces, so break up our writes.","lang_file",".","write","(","'{\\n\\t\"@metadata\": {'",")","lang_file",".","write","(","\"\"\"\n\\t\\t\"author\": \"{0}\",\n\\t\\t\"lastupdated\": \"{1}\",\n\\t\\t\"locale\": \"{2}\",\n\\t\\t\"messagedocumentation\" : \"qqq\"\n\"\"\"",".","format","(","author",",","str","(","datetime",".","now","(",")",")",",","lang",")",")","lang_file",".","write","(","'\\t},\\n'",")","return","lang_file"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/blockscad\/msg\/common.py#L108-L139"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"blockscad\/msg\/common.py","language":"python","identifier":"_close_lang_file","parameters":"(lang_file)","argument_list":"","return_statement":"","docstring":"Closes a <lang>.json file created with _create_lang_file().\n\n This also writes the terminating left brace and newline.\n\n Args:\n lang_file: A file opened with _create_lang_file().\n\n Raises:\n IOError: An error occurred while writing to or closing the file.","docstring_summary":"Closes a <lang>.json file created with _create_lang_file().","docstring_tokens":["Closes","a","<lang",">",".","json","file","created","with","_create_lang_file","()","."],"function":"def _close_lang_file(lang_file):\n \"\"\"Closes a <lang>.json file created with _create_lang_file().\n\n This also writes the terminating left brace and newline.\n\n Args:\n lang_file: A file opened with _create_lang_file().\n\n Raises:\n IOError: An error occurred while writing to or closing the file.\n \"\"\"\n lang_file.write('\\n}\\n')\n lang_file.close()","function_tokens":["def","_close_lang_file","(","lang_file",")",":","lang_file",".","write","(","'\\n}\\n'",")","lang_file",".","close","(",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/blockscad\/msg\/common.py#L142-L154"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"blockscad\/msg\/common.py","language":"python","identifier":"_create_key_file","parameters":"(output_dir)","argument_list":"","return_statement":"return key_file","docstring":"Creates a keys.json file mapping Closure keys to Blockly keys.\n\n Args:\n output_dir: Relative directory for output files.\n\n Raises:\n IOError: An error occurred while creating the file.","docstring_summary":"Creates a keys.json file mapping Closure keys to Blockly keys.","docstring_tokens":["Creates","a","keys",".","json","file","mapping","Closure","keys","to","Blockly","keys","."],"function":"def _create_key_file(output_dir):\n \"\"\"Creates a keys.json file mapping Closure keys to Blockly keys.\n\n Args:\n output_dir: Relative directory for output files.\n\n Raises:\n IOError: An error occurred while creating the file.\n \"\"\"\n key_file_name = os.path.join(os.curdir, output_dir, 'keys.json')\n key_file = open(key_file_name, 'w')\n key_file.write('{\\n')\n print 'Created file: ' + key_file_name\n return key_file","function_tokens":["def","_create_key_file","(","output_dir",")",":","key_file_name","=","os",".","path",".","join","(","os",".","curdir",",","output_dir",",","'keys.json'",")","key_file","=","open","(","key_file_name",",","'w'",")","key_file",".","write","(","'{\\n'",")","print","'Created file: '","+","key_file_name","return","key_file"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/blockscad\/msg\/common.py#L157-L170"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"blockscad\/msg\/common.py","language":"python","identifier":"_close_key_file","parameters":"(key_file)","argument_list":"","return_statement":"","docstring":"Closes a key file created and opened with _create_key_file().\n\n Args:\n key_file: A file created by _create_key_file().\n\n Raises:\n IOError: An error occurred while writing to or closing the file.","docstring_summary":"Closes a key file created and opened with _create_key_file().","docstring_tokens":["Closes","a","key","file","created","and","opened","with","_create_key_file","()","."],"function":"def _close_key_file(key_file):\n \"\"\"Closes a key file created and opened with _create_key_file().\n\n Args:\n key_file: A file created by _create_key_file().\n\n Raises:\n IOError: An error occurred while writing to or closing the file.\n \"\"\"\n key_file.write('\\n}\\n')\n key_file.close()","function_tokens":["def","_close_key_file","(","key_file",")",":","key_file",".","write","(","'\\n}\\n'",")","key_file",".","close","(",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/blockscad\/msg\/common.py#L173-L183"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"blockscad\/msg\/common.py","language":"python","identifier":"write_files","parameters":"(author, lang, output_dir, units, write_key_file)","argument_list":"","return_statement":"","docstring":"Writes the output files for the given units.\n\n There are three possible output files:\n * lang_file: JSON file mapping meanings (e.g., Maze.turnLeft) to the\n English text. The base name of the language file is specified by the\n \"lang\" command-line argument.\n * key_file: JSON file mapping meanings to Soy-generated keys (long hash\n codes). This is only output if the parameter write_key_file is True.\n * qqq_file: JSON file mapping meanings to descriptions.\n\n Args:\n author: Name and email address of contact for translators.\n lang: ISO 639-1 source language code.\n output_dir: Relative directory for output files.\n units: A list of dictionaries with entries for 'meaning', 'source',\n 'description', and 'keys' (the last only if write_key_file is true),\n in the order desired in the output files.\n write_key_file: Whether to output a keys.json file.\n\n Raises:\n IOError: An error occurs opening, writing to, or closing a file.\n KeyError: An expected key is missing from units.","docstring_summary":"Writes the output files for the given units.","docstring_tokens":["Writes","the","output","files","for","the","given","units","."],"function":"def write_files(author, lang, output_dir, units, write_key_file):\n \"\"\"Writes the output files for the given units.\n\n There are three possible output files:\n * lang_file: JSON file mapping meanings (e.g., Maze.turnLeft) to the\n English text. The base name of the language file is specified by the\n \"lang\" command-line argument.\n * key_file: JSON file mapping meanings to Soy-generated keys (long hash\n codes). This is only output if the parameter write_key_file is True.\n * qqq_file: JSON file mapping meanings to descriptions.\n\n Args:\n author: Name and email address of contact for translators.\n lang: ISO 639-1 source language code.\n output_dir: Relative directory for output files.\n units: A list of dictionaries with entries for 'meaning', 'source',\n 'description', and 'keys' (the last only if write_key_file is true),\n in the order desired in the output files.\n write_key_file: Whether to output a keys.json file.\n\n Raises:\n IOError: An error occurs opening, writing to, or closing a file.\n KeyError: An expected key is missing from units.\n \"\"\"\n lang_file = _create_lang_file(author, lang, output_dir)\n qqq_file = _create_qqq_file(output_dir)\n if write_key_file:\n key_file = _create_key_file(output_dir)\n first_entry = True\n for unit in units:\n if not first_entry:\n lang_file.write(',\\n')\n if write_key_file:\n key_file.write(',\\n')\n qqq_file.write(',\\n')\n lang_file.write(u'\\t\"{0}\": \"{1}\"'.format(\n unit['meaning'],\n unit['source'].replace('\"', \"'\")))\n if write_key_file:\n key_file.write('\"{0}\": \"{1}\"'.format(unit['meaning'], unit['key']))\n qqq_file.write(u'\\t\"{0}\": \"{1}\"'.format(\n unit['meaning'],\n unit['description'].replace('\"', \"'\").replace(\n '{lb}', '{').replace('{rb}', '}')))\n first_entry = False\n _close_lang_file(lang_file)\n if write_key_file:\n _close_key_file(key_file)\n _close_qqq_file(qqq_file)","function_tokens":["def","write_files","(","author",",","lang",",","output_dir",",","units",",","write_key_file",")",":","lang_file","=","_create_lang_file","(","author",",","lang",",","output_dir",")","qqq_file","=","_create_qqq_file","(","output_dir",")","if","write_key_file",":","key_file","=","_create_key_file","(","output_dir",")","first_entry","=","True","for","unit","in","units",":","if","not","first_entry",":","lang_file",".","write","(","',\\n'",")","if","write_key_file",":","key_file",".","write","(","',\\n'",")","qqq_file",".","write","(","',\\n'",")","lang_file",".","write","(","u'\\t\"{0}\": \"{1}\"'",".","format","(","unit","[","'meaning'","]",",","unit","[","'source'","]",".","replace","(","'\"'",",","\"'\"",")",")",")","if","write_key_file",":","key_file",".","write","(","'\"{0}\": \"{1}\"'",".","format","(","unit","[","'meaning'","]",",","unit","[","'key'","]",")",")","qqq_file",".","write","(","u'\\t\"{0}\": \"{1}\"'",".","format","(","unit","[","'meaning'","]",",","unit","[","'description'","]",".","replace","(","'\"'",",","\"'\"",")",".","replace","(","'{lb}'",",","'{'",")",".","replace","(","'{rb}'",",","'}'",")",")",")","first_entry","=","False","_close_lang_file","(","lang_file",")","if","write_key_file",":","_close_key_file","(","key_file",")","_close_qqq_file","(","qqq_file",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/blockscad\/msg\/common.py#L186-L234"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"blockly\/build.py","language":"python","identifier":"import_path","parameters":"(fullpath)","argument_list":"","return_statement":"return module","docstring":"Import a file with full path specification.\n Allows one to import from any directory, something __import__ does not do.\n\n Args:\n fullpath: Path and filename of import.\n\n Returns:\n An imported module.","docstring_summary":"Import a file with full path specification.\n Allows one to import from any directory, something __import__ does not do.","docstring_tokens":["Import","a","file","with","full","path","specification",".","Allows","one","to","import","from","any","directory","something","__import__","does","not","do","."],"function":"def import_path(fullpath):\n \"\"\"Import a file with full path specification.\n Allows one to import from any directory, something __import__ does not do.\n\n Args:\n fullpath: Path and filename of import.\n\n Returns:\n An imported module.\n \"\"\"\n path, filename = os.path.split(fullpath)\n filename, ext = os.path.splitext(filename)\n sys.path.append(path)\n module = __import__(filename)\n reload(module) # Might be out of date.\n del sys.path[-1]\n return module","function_tokens":["def","import_path","(","fullpath",")",":","path",",","filename","=","os",".","path",".","split","(","fullpath",")","filename",",","ext","=","os",".","path",".","splitext","(","filename",")","sys",".","path",".","append","(","path",")","module","=","__import__","(","filename",")","reload","(","module",")","# Might be out of date.","del","sys",".","path","[","-","1","]","return","module"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/blockly\/build.py#L47-L63"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"blockly\/i18n\/create_messages.py","language":"python","identifier":"main","parameters":"()","argument_list":"","return_statement":"","docstring":"Generate .js files defining Blockly core and language messages.","docstring_summary":"Generate .js files defining Blockly core and language messages.","docstring_tokens":["Generate",".","js","files","defining","Blockly","core","and","language","messages","."],"function":"def main():\n \"\"\"Generate .js files defining Blockly core and language messages.\"\"\"\n\n # Process command-line arguments.\n parser = argparse.ArgumentParser(description='Convert JSON files to JS.')\n parser.add_argument('--source_lang', default='en',\n help='ISO 639-1 source language code')\n parser.add_argument('--source_lang_file',\n default=os.path.join('json', 'en.json'),\n help='Path to .json file for source language')\n parser.add_argument('--source_synonym_file',\n default=os.path.join('json', 'synonyms.json'),\n help='Path to .json file with synonym definitions')\n parser.add_argument('--output_dir', default='js\/',\n help='relative directory for output files')\n parser.add_argument('--key_file', default='keys.json',\n help='relative path to input keys file')\n parser.add_argument('--quiet', action='store_true', default=False,\n help='do not write anything to standard output')\n parser.add_argument('files', nargs='+', help='input files')\n args = parser.parse_args()\n if not args.output_dir.endswith(os.path.sep):\n args.output_dir += os.path.sep\n\n # Read in source language .json file, which provides any values missing\n # in target languages' .json files.\n source_defs = read_json_file(os.path.join(os.curdir, args.source_lang_file))\n # Make sure the source file doesn't contain a newline or carriage return.\n for key, value in source_defs.items():\n if _NEWLINE_PATTERN.search(value):\n print('ERROR: definition of {0} in {1} contained a newline character.'.\n format(key, args.source_lang_file))\n sys.exit(1)\n sorted_keys = source_defs.keys()\n sorted_keys.sort()\n\n # Read in synonyms file, which must be output in every language.\n synonym_defs = read_json_file(os.path.join(\n os.curdir, args.source_synonym_file))\n synonym_text = '\\n'.join(['Blockly.Msg.{0} = Blockly.Msg.{1};'.format(\n key, synonym_defs[key]) for key in synonym_defs])\n\n # Create each output file.\n for arg_file in args.files:\n (_, filename) = os.path.split(arg_file)\n target_lang = filename[:filename.index('.')]\n if target_lang not in ('qqq', 'keys', 'synonyms'):\n target_defs = read_json_file(os.path.join(os.curdir, arg_file))\n\n # Verify that keys are 'ascii'\n bad_keys = [key for key in target_defs if not string_is_ascii(key)]\n if bad_keys:\n print(u'These keys in {0} contain non ascii characters: {1}'.format(\n filename, ', '.join(bad_keys)))\n\n # If there's a '\\n' or '\\r', remove it and print a warning.\n for key, value in target_defs.items():\n if _NEWLINE_PATTERN.search(value):\n print(u'WARNING: definition of {0} in {1} contained '\n 'a newline character.'.\n format(key, arg_file))\n target_defs[key] = _NEWLINE_PATTERN.sub(' ', value)\n\n # Output file.\n outname = os.path.join(os.curdir, args.output_dir, target_lang + '.js')\n with codecs.open(outname, 'w', 'utf-8') as outfile:\n outfile.write(\n \"\"\"\/\/ This file was automatically generated. Do not modify.\n\n'use strict';\n\ngoog.provide('Blockly.Msg.{0}');\n\ngoog.require('Blockly.Msg');\n\n\"\"\".format(target_lang.replace('-', '.')))\n # For each key in the source language file, output the target value\n # if present; otherwise, output the source language value with a\n # warning comment.\n for key in sorted_keys:\n if key in target_defs:\n value = target_defs[key]\n comment = ''\n del target_defs[key]\n else:\n value = source_defs[key]\n comment = ' \/\/ untranslated'\n value = value.replace('\"', '\\\\\"')\n outfile.write(u'Blockly.Msg.{0} = \"{1}\";{2}\\n'.format(\n key, value, comment))\n\n # Announce any keys defined only for target language.\n if target_defs:\n extra_keys = [key for key in target_defs if key not in synonym_defs]\n synonym_keys = [key for key in target_defs if key in synonym_defs]\n if not args.quiet:\n if extra_keys:\n print(u'These extra keys appeared in {0}: {1}'.format(\n filename, ', '.join(extra_keys)))\n if synonym_keys:\n print(u'These synonym keys appeared in {0}: {1}'.format(\n filename, ', '.join(synonym_keys)))\n\n outfile.write(synonym_text)\n\n if not args.quiet:\n print('Created {0}.'.format(outname))","function_tokens":["def","main","(",")",":","# Process command-line arguments.","parser","=","argparse",".","ArgumentParser","(","description","=","'Convert JSON files to JS.'",")","parser",".","add_argument","(","'--source_lang'",",","default","=","'en'",",","help","=","'ISO 639-1 source language code'",")","parser",".","add_argument","(","'--source_lang_file'",",","default","=","os",".","path",".","join","(","'json'",",","'en.json'",")",",","help","=","'Path to .json file for source language'",")","parser",".","add_argument","(","'--source_synonym_file'",",","default","=","os",".","path",".","join","(","'json'",",","'synonyms.json'",")",",","help","=","'Path to .json file with synonym definitions'",")","parser",".","add_argument","(","'--output_dir'",",","default","=","'js\/'",",","help","=","'relative directory for output files'",")","parser",".","add_argument","(","'--key_file'",",","default","=","'keys.json'",",","help","=","'relative path to input keys file'",")","parser",".","add_argument","(","'--quiet'",",","action","=","'store_true'",",","default","=","False",",","help","=","'do not write anything to standard output'",")","parser",".","add_argument","(","'files'",",","nargs","=","'+'",",","help","=","'input files'",")","args","=","parser",".","parse_args","(",")","if","not","args",".","output_dir",".","endswith","(","os",".","path",".","sep",")",":","args",".","output_dir","+=","os",".","path",".","sep","# Read in source language .json file, which provides any values missing","# in target languages' .json files.","source_defs","=","read_json_file","(","os",".","path",".","join","(","os",".","curdir",",","args",".","source_lang_file",")",")","# Make sure the source file doesn't contain a newline or carriage return.","for","key",",","value","in","source_defs",".","items","(",")",":","if","_NEWLINE_PATTERN",".","search","(","value",")",":","print","(","'ERROR: definition of {0} in {1} contained a newline character.'",".","format","(","key",",","args",".","source_lang_file",")",")","sys",".","exit","(","1",")","sorted_keys","=","source_defs",".","keys","(",")","sorted_keys",".","sort","(",")","# Read in synonyms file, which must be output in every language.","synonym_defs","=","read_json_file","(","os",".","path",".","join","(","os",".","curdir",",","args",".","source_synonym_file",")",")","synonym_text","=","'\\n'",".","join","(","[","'Blockly.Msg.{0} = Blockly.Msg.{1};'",".","format","(","key",",","synonym_defs","[","key","]",")","for","key","in","synonym_defs","]",")","# Create each output file.","for","arg_file","in","args",".","files",":","(","_",",","filename",")","=","os",".","path",".","split","(","arg_file",")","target_lang","=","filename","[",":","filename",".","index","(","'.'",")","]","if","target_lang","not","in","(","'qqq'",",","'keys'",",","'synonyms'",")",":","target_defs","=","read_json_file","(","os",".","path",".","join","(","os",".","curdir",",","arg_file",")",")","# Verify that keys are 'ascii'","bad_keys","=","[","key","for","key","in","target_defs","if","not","string_is_ascii","(","key",")","]","if","bad_keys",":","print","(","u'These keys in {0} contain non ascii characters: {1}'",".","format","(","filename",",","', '",".","join","(","bad_keys",")",")",")","# If there's a '\\n' or '\\r', remove it and print a warning.","for","key",",","value","in","target_defs",".","items","(",")",":","if","_NEWLINE_PATTERN",".","search","(","value",")",":","print","(","u'WARNING: definition of {0} in {1} contained '","'a newline character.'",".","format","(","key",",","arg_file",")",")","target_defs","[","key","]","=","_NEWLINE_PATTERN",".","sub","(","' '",",","value",")","# Output file.","outname","=","os",".","path",".","join","(","os",".","curdir",",","args",".","output_dir",",","target_lang","+","'.js'",")","with","codecs",".","open","(","outname",",","'w'",",","'utf-8'",")","as","outfile",":","outfile",".","write","(","\"\"\"\/\/ This file was automatically generated. Do not modify.\n\n'use strict';\n\ngoog.provide('Blockly.Msg.{0}');\n\ngoog.require('Blockly.Msg');\n\n\"\"\"",".","format","(","target_lang",".","replace","(","'-'",",","'.'",")",")",")","# For each key in the source language file, output the target value","# if present; otherwise, output the source language value with a","# warning comment.","for","key","in","sorted_keys",":","if","key","in","target_defs",":","value","=","target_defs","[","key","]","comment","=","''","del","target_defs","[","key","]","else",":","value","=","source_defs","[","key","]","comment","=","' \/\/ untranslated'","value","=","value",".","replace","(","'\"'",",","'\\\\\"'",")","outfile",".","write","(","u'Blockly.Msg.{0} = \"{1}\";{2}\\n'",".","format","(","key",",","value",",","comment",")",")","# Announce any keys defined only for target language.","if","target_defs",":","extra_keys","=","[","key","for","key","in","target_defs","if","key","not","in","synonym_defs","]","synonym_keys","=","[","key","for","key","in","target_defs","if","key","in","synonym_defs","]","if","not","args",".","quiet",":","if","extra_keys",":","print","(","u'These extra keys appeared in {0}: {1}'",".","format","(","filename",",","', '",".","join","(","extra_keys",")",")",")","if","synonym_keys",":","print","(","u'These synonym keys appeared in {0}: {1}'",".","format","(","filename",",","', '",".","join","(","synonym_keys",")",")",")","outfile",".","write","(","synonym_text",")","if","not","args",".","quiet",":","print","(","'Created {0}.'",".","format","(","outname",")",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/blockly\/i18n\/create_messages.py#L39-L145"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"blockly\/i18n\/dedup_json.py","language":"python","identifier":"main","parameters":"()","argument_list":"","return_statement":"","docstring":"Parses arguments and iterates over files.\n\n Raises:\n IOError: An I\/O error occurred with an input or output file.\n InputError: Input JSON could not be parsed.","docstring_summary":"Parses arguments and iterates over files.","docstring_tokens":["Parses","arguments","and","iterates","over","files","."],"function":"def main():\n \"\"\"Parses arguments and iterates over files.\n\n Raises:\n IOError: An I\/O error occurred with an input or output file.\n InputError: Input JSON could not be parsed.\n \"\"\"\n\n # Set up argument parser.\n parser = argparse.ArgumentParser(\n description='Removes duplicate key-value pairs from JSON files.')\n parser.add_argument('--suffix', default='',\n help='optional suffix for output files; '\n 'if empty, files will be changed in place')\n parser.add_argument('files', nargs='+', help='input files')\n args = parser.parse_args()\n\n # Iterate over files.\n for filename in args.files:\n # Read in json using Python libraries. This eliminates duplicates.\n print('Processing ' + filename + '...')\n try:\n with codecs.open(filename, 'r', 'utf-8') as infile:\n j = json.load(infile)\n except ValueError, e:\n print('Error reading ' + filename)\n raise InputError(file, str(e))\n\n # Built up output strings as an array to make output of delimiters easier.\n output = []\n for key in j:\n if key != '@metadata':\n output.append('\\t\"' + key + '\": \"' +\n j[key].replace('\\n', '\\\\n') + '\"')\n\n # Output results.\n with codecs.open(filename + args.suffix, 'w', 'utf-8') as outfile:\n outfile.write('{\\n')\n outfile.write(',\\n'.join(output))\n outfile.write('\\n}\\n')","function_tokens":["def","main","(",")",":","# Set up argument parser.","parser","=","argparse",".","ArgumentParser","(","description","=","'Removes duplicate key-value pairs from JSON files.'",")","parser",".","add_argument","(","'--suffix'",",","default","=","''",",","help","=","'optional suffix for output files; '","'if empty, files will be changed in place'",")","parser",".","add_argument","(","'files'",",","nargs","=","'+'",",","help","=","'input files'",")","args","=","parser",".","parse_args","(",")","# Iterate over files.","for","filename","in","args",".","files",":","# Read in json using Python libraries. This eliminates duplicates.","print","(","'Processing '","+","filename","+","'...'",")","try",":","with","codecs",".","open","(","filename",",","'r'",",","'utf-8'",")","as","infile",":","j","=","json",".","load","(","infile",")","except","ValueError",",","e",":","print","(","'Error reading '","+","filename",")","raise","InputError","(","file",",","str","(","e",")",")","# Built up output strings as an array to make output of delimiters easier.","output","=","[","]","for","key","in","j",":","if","key","!=","'@metadata'",":","output",".","append","(","'\\t\"'","+","key","+","'\": \"'","+","j","[","key","]",".","replace","(","'\\n'",",","'\\\\n'",")","+","'\"'",")","# Output results.","with","codecs",".","open","(","filename","+","args",".","suffix",",","'w'",",","'utf-8'",")","as","outfile",":","outfile",".","write","(","'{\\n'",")","outfile",".","write","(","',\\n'",".","join","(","output",")",")","outfile",".","write","(","'\\n}\\n'",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/blockly\/i18n\/dedup_json.py#L30-L69"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"blockly\/i18n\/json_to_js.py","language":"python","identifier":"_create_xlf","parameters":"(target_lang)","argument_list":"","return_statement":"return out_file","docstring":"Creates a <target_lang>.xlf file for Soy.\n\n Args:\n target_lang: The ISO 639 language code for the target language.\n This is used in the name of the file and in the metadata.\n\n Returns:\n A pointer to a file to which the metadata has been written.\n\n Raises:\n IOError: An error occurred while opening or writing the file.","docstring_summary":"Creates a <target_lang>.xlf file for Soy.","docstring_tokens":["Creates","a","<target_lang",">",".","xlf","file","for","Soy","."],"function":"def _create_xlf(target_lang):\n \"\"\"Creates a <target_lang>.xlf file for Soy.\n\n Args:\n target_lang: The ISO 639 language code for the target language.\n This is used in the name of the file and in the metadata.\n\n Returns:\n A pointer to a file to which the metadata has been written.\n\n Raises:\n IOError: An error occurred while opening or writing the file.\n \"\"\"\n filename = os.path.join(os.curdir, args.output_dir, target_lang + '.xlf')\n out_file = codecs.open(filename, 'w', 'utf-8')\n out_file.write(\"\"\"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xliff version=\"1.2\" xmlns=\"urn:oasis:names:tc:xliff:document:1.2\">\n <file original=\"SoyMsgBundle\"\n datatype=\"x-soy-msg-bundle\"\n xml:space=\"preserve\"\n source-language=\"{0}\"\n target-language=\"{1}\">\n <body>\"\"\".format(args.source_lang, target_lang))\n return out_file","function_tokens":["def","_create_xlf","(","target_lang",")",":","filename","=","os",".","path",".","join","(","os",".","curdir",",","args",".","output_dir",",","target_lang","+","'.xlf'",")","out_file","=","codecs",".","open","(","filename",",","'w'",",","'utf-8'",")","out_file",".","write","(","\"\"\"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xliff version=\"1.2\" xmlns=\"urn:oasis:names:tc:xliff:document:1.2\">\n <file original=\"SoyMsgBundle\"\n datatype=\"x-soy-msg-bundle\"\n xml:space=\"preserve\"\n source-language=\"{0}\"\n target-language=\"{1}\">\n <body>\"\"\"",".","format","(","args",".","source_lang",",","target_lang",")",")","return","out_file"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/blockly\/i18n\/json_to_js.py#L34-L57"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"blockly\/i18n\/json_to_js.py","language":"python","identifier":"_close_xlf","parameters":"(xlf_file)","argument_list":"","return_statement":"","docstring":"Closes a <target_lang>.xlf file created with create_xlf().\n\n This includes writing the terminating XML.\n\n Args:\n xlf_file: A pointer to a file created by _create_xlf().\n\n Raises:\n IOError: An error occurred while writing to or closing the file.","docstring_summary":"Closes a <target_lang>.xlf file created with create_xlf().","docstring_tokens":["Closes","a","<target_lang",">",".","xlf","file","created","with","create_xlf","()","."],"function":"def _close_xlf(xlf_file):\n \"\"\"Closes a <target_lang>.xlf file created with create_xlf().\n\n This includes writing the terminating XML.\n\n Args:\n xlf_file: A pointer to a file created by _create_xlf().\n\n Raises:\n IOError: An error occurred while writing to or closing the file.\n \"\"\"\n xlf_file.write(\"\"\"\n <\/body>\n <\/file>\n<\/xliff>\n\"\"\")\n xlf_file.close()","function_tokens":["def","_close_xlf","(","xlf_file",")",":","xlf_file",".","write","(","\"\"\"\n <\/body>\n <\/file>\n<\/xliff>\n\"\"\"",")","xlf_file",".","close","(",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/blockly\/i18n\/json_to_js.py#L60-L76"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"blockly\/i18n\/json_to_js.py","language":"python","identifier":"_process_file","parameters":"(path_to_json, target_lang, key_dict)","argument_list":"","return_statement":"","docstring":"Creates an .xlf file corresponding to the specified .json input file.\n\n The name of the input file must be target_lang followed by '.json'.\n The name of the output file will be target_lang followed by '.js'.\n\n Args:\n path_to_json: Path to the directory of xx.json files.\n target_lang: A IETF language code (RFC 4646), such as 'es' or 'pt-br'.\n key_dict: Dictionary mapping Blockly keys (e.g., Maze.turnLeft) to\n Closure keys (hash numbers).\n\n Raises:\n IOError: An I\/O error occurred with an input or output file.\n InputError: Input JSON could not be parsed.\n KeyError: Key found in input file but not in key file.","docstring_summary":"Creates an .xlf file corresponding to the specified .json input file.","docstring_tokens":["Creates","an",".","xlf","file","corresponding","to","the","specified",".","json","input","file","."],"function":"def _process_file(path_to_json, target_lang, key_dict):\n \"\"\"Creates an .xlf file corresponding to the specified .json input file.\n\n The name of the input file must be target_lang followed by '.json'.\n The name of the output file will be target_lang followed by '.js'.\n\n Args:\n path_to_json: Path to the directory of xx.json files.\n target_lang: A IETF language code (RFC 4646), such as 'es' or 'pt-br'.\n key_dict: Dictionary mapping Blockly keys (e.g., Maze.turnLeft) to\n Closure keys (hash numbers).\n\n Raises:\n IOError: An I\/O error occurred with an input or output file.\n InputError: Input JSON could not be parsed.\n KeyError: Key found in input file but not in key file.\n \"\"\"\n keyfile = os.path.join(path_to_json, target_lang + '.json')\n j = read_json_file(keyfile)\n out_file = _create_xlf(target_lang)\n for key in j:\n if key != '@metadata':\n try:\n identifier = key_dict[key]\n except KeyError, e:\n print('Key \"%s\" is in %s but not in %s' %\n (key, keyfile, args.key_file))\n raise e\n target = j.get(key)\n out_file.write(u\"\"\"\n <trans-unit id=\"{0}\" datatype=\"html\">\n <target>{1}<\/target>\n <\/trans-unit>\"\"\".format(identifier, target))\n _close_xlf(out_file)","function_tokens":["def","_process_file","(","path_to_json",",","target_lang",",","key_dict",")",":","keyfile","=","os",".","path",".","join","(","path_to_json",",","target_lang","+","'.json'",")","j","=","read_json_file","(","keyfile",")","out_file","=","_create_xlf","(","target_lang",")","for","key","in","j",":","if","key","!=","'@metadata'",":","try",":","identifier","=","key_dict","[","key","]","except","KeyError",",","e",":","print","(","'Key \"%s\" is in %s but not in %s'","%","(","key",",","keyfile",",","args",".","key_file",")",")","raise","e","target","=","j",".","get","(","key",")","out_file",".","write","(","u\"\"\"\n <trans-unit id=\"{0}\" datatype=\"html\">\n <target>{1}<\/target>\n <\/trans-unit>\"\"\"",".","format","(","identifier",",","target",")",")","_close_xlf","(","out_file",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/blockly\/i18n\/json_to_js.py#L79-L112"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"blockly\/i18n\/json_to_js.py","language":"python","identifier":"main","parameters":"()","argument_list":"","return_statement":"","docstring":"Parses arguments and iterates over files.","docstring_summary":"Parses arguments and iterates over files.","docstring_tokens":["Parses","arguments","and","iterates","over","files","."],"function":"def main():\n \"\"\"Parses arguments and iterates over files.\"\"\"\n\n # Set up argument parser.\n parser = argparse.ArgumentParser(description='Convert JSON files to JS.')\n parser.add_argument('--source_lang', default='en',\n help='ISO 639-1 source language code')\n parser.add_argument('--output_dir', default='generated',\n help='relative directory for output files')\n parser.add_argument('--key_file', default='json' + os.path.sep + 'keys.json',\n help='relative path to input keys file')\n parser.add_argument('--template', default='template.soy')\n parser.add_argument('--path_to_jar',\n default='..' + os.path.sep + 'apps' + os.path.sep\n + '_soy',\n help='relative path from working directory to '\n 'SoyToJsSrcCompiler.jar')\n parser.add_argument('files', nargs='+', help='input files')\n\n # Initialize global variables.\n global args\n args = parser.parse_args()\n\n # Make sure output_dir ends with slash.\n if (not args.output_dir.endswith(os.path.sep)):\n args.output_dir += os.path.sep\n\n # Read in keys.json, mapping descriptions (e.g., Maze.turnLeft) to\n # Closure keys (long hash numbers).\n key_file = open(args.key_file)\n key_dict = json.load(key_file)\n key_file.close()\n\n # Process each input file.\n print('Creating .xlf files...')\n processed_langs = []\n if len(args.files) == 1:\n # Windows does not expand globs automatically.\n args.files = glob.glob(args.files[0])\n for arg_file in args.files:\n (path_to_json, filename) = os.path.split(arg_file)\n if not filename.endswith('.json'):\n raise InputError(filename, 'filenames must end with \".json\"')\n target_lang = filename[:filename.index('.')]\n if not target_lang in ('qqq', 'keys'):\n processed_langs.append(target_lang)\n _process_file(path_to_json, target_lang, key_dict)\n\n # Output command line for Closure compiler.\n if processed_langs:\n print('Creating .js files...')\n processed_lang_list = ','.join(processed_langs)\n subprocess.check_call([\n 'java',\n '-jar', os.path.join(args.path_to_jar, 'SoyToJsSrcCompiler.jar'),\n '--locales', processed_lang_list,\n '--messageFilePathFormat', args.output_dir + '{LOCALE}.xlf',\n '--outputPathFormat', args.output_dir + '{LOCALE}.js',\n '--srcs', args.template])\n if len(processed_langs) == 1:\n print('Created ' + processed_lang_list + '.js in ' + args.output_dir)\n else:\n print('Created {' + processed_lang_list + '}.js in ' + args.output_dir)\n\n for lang in processed_langs:\n os.remove(args.output_dir + lang + '.xlf')\n print('Removed .xlf files.')","function_tokens":["def","main","(",")",":","# Set up argument parser.","parser","=","argparse",".","ArgumentParser","(","description","=","'Convert JSON files to JS.'",")","parser",".","add_argument","(","'--source_lang'",",","default","=","'en'",",","help","=","'ISO 639-1 source language code'",")","parser",".","add_argument","(","'--output_dir'",",","default","=","'generated'",",","help","=","'relative directory for output files'",")","parser",".","add_argument","(","'--key_file'",",","default","=","'json'","+","os",".","path",".","sep","+","'keys.json'",",","help","=","'relative path to input keys file'",")","parser",".","add_argument","(","'--template'",",","default","=","'template.soy'",")","parser",".","add_argument","(","'--path_to_jar'",",","default","=","'..'","+","os",".","path",".","sep","+","'apps'","+","os",".","path",".","sep","+","'_soy'",",","help","=","'relative path from working directory to '","'SoyToJsSrcCompiler.jar'",")","parser",".","add_argument","(","'files'",",","nargs","=","'+'",",","help","=","'input files'",")","# Initialize global variables.","global","args","args","=","parser",".","parse_args","(",")","# Make sure output_dir ends with slash.","if","(","not","args",".","output_dir",".","endswith","(","os",".","path",".","sep",")",")",":","args",".","output_dir","+=","os",".","path",".","sep","# Read in keys.json, mapping descriptions (e.g., Maze.turnLeft) to","# Closure keys (long hash numbers).","key_file","=","open","(","args",".","key_file",")","key_dict","=","json",".","load","(","key_file",")","key_file",".","close","(",")","# Process each input file.","print","(","'Creating .xlf files...'",")","processed_langs","=","[","]","if","len","(","args",".","files",")","==","1",":","# Windows does not expand globs automatically.","args",".","files","=","glob",".","glob","(","args",".","files","[","0","]",")","for","arg_file","in","args",".","files",":","(","path_to_json",",","filename",")","=","os",".","path",".","split","(","arg_file",")","if","not","filename",".","endswith","(","'.json'",")",":","raise","InputError","(","filename",",","'filenames must end with \".json\"'",")","target_lang","=","filename","[",":","filename",".","index","(","'.'",")","]","if","not","target_lang","in","(","'qqq'",",","'keys'",")",":","processed_langs",".","append","(","target_lang",")","_process_file","(","path_to_json",",","target_lang",",","key_dict",")","# Output command line for Closure compiler.","if","processed_langs",":","print","(","'Creating .js files...'",")","processed_lang_list","=","','",".","join","(","processed_langs",")","subprocess",".","check_call","(","[","'java'",",","'-jar'",",","os",".","path",".","join","(","args",".","path_to_jar",",","'SoyToJsSrcCompiler.jar'",")",",","'--locales'",",","processed_lang_list",",","'--messageFilePathFormat'",",","args",".","output_dir","+","'{LOCALE}.xlf'",",","'--outputPathFormat'",",","args",".","output_dir","+","'{LOCALE}.js'",",","'--srcs'",",","args",".","template","]",")","if","len","(","processed_langs",")","==","1",":","print","(","'Created '","+","processed_lang_list","+","'.js in '","+","args",".","output_dir",")","else",":","print","(","'Created {'","+","processed_lang_list","+","'}.js in '","+","args",".","output_dir",")","for","lang","in","processed_langs",":","os",".","remove","(","args",".","output_dir","+","lang","+","'.xlf'",")","print","(","'Removed .xlf files.'",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/blockly\/i18n\/json_to_js.py#L115-L181"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"blockly\/i18n\/common.py","language":"python","identifier":"read_json_file","parameters":"(filename)","argument_list":"","return_statement":"","docstring":"Read a JSON file as UTF-8 into a dictionary, discarding @metadata.\n\n Args:\n filename: The filename, which must end \".json\".\n\n Returns:\n The dictionary.\n\n Raises:\n InputError: The filename did not end with \".json\" or an error occurred\n while opening or reading the file.","docstring_summary":"Read a JSON file as UTF-8 into a dictionary, discarding @metadata.","docstring_tokens":["Read","a","JSON","file","as","UTF","-","8","into","a","dictionary","discarding","@metadata","."],"function":"def read_json_file(filename):\n \"\"\"Read a JSON file as UTF-8 into a dictionary, discarding @metadata.\n\n Args:\n filename: The filename, which must end \".json\".\n\n Returns:\n The dictionary.\n\n Raises:\n InputError: The filename did not end with \".json\" or an error occurred\n while opening or reading the file.\n \"\"\"\n if not filename.endswith('.json'):\n raise InputError(filename, 'filenames must end with \".json\"')\n try:\n # Read in file.\n with codecs.open(filename, 'r', 'utf-8') as infile:\n defs = json.load(infile)\n if '@metadata' in defs:\n del defs['@metadata']\n return defs\n except ValueError, e:\n print('Error reading ' + filename)\n raise InputError(filename, str(e))","function_tokens":["def","read_json_file","(","filename",")",":","if","not","filename",".","endswith","(","'.json'",")",":","raise","InputError","(","filename",",","'filenames must end with \".json\"'",")","try",":","# Read in file.","with","codecs",".","open","(","filename",",","'r'",",","'utf-8'",")","as","infile",":","defs","=","json",".","load","(","infile",")","if","'@metadata'","in","defs",":","del","defs","[","'@metadata'","]","return","defs","except","ValueError",",","e",":","print","(","'Error reading '","+","filename",")","raise","InputError","(","filename",",","str","(","e",")",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/blockly\/i18n\/common.py#L40-L64"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"blockly\/i18n\/common.py","language":"python","identifier":"_create_qqq_file","parameters":"(output_dir)","argument_list":"","return_statement":"return qqq_file","docstring":"Creates a qqq.json file with message documentation for translatewiki.net.\n\n The file consists of key-value pairs, where the keys are message ids and\n the values are descriptions for the translators of the messages.\n What documentation exists for the format can be found at:\n http:\/\/translatewiki.net\/wiki\/Translating:Localisation_for_developers#Message_documentation\n\n The file should be closed by _close_qqq_file().\n\n Parameters:\n output_dir: The output directory.\n\n Returns:\n A pointer to a file to which a left brace and newline have been written.\n\n Raises:\n IOError: An error occurred while opening or writing the file.","docstring_summary":"Creates a qqq.json file with message documentation for translatewiki.net.","docstring_tokens":["Creates","a","qqq",".","json","file","with","message","documentation","for","translatewiki",".","net","."],"function":"def _create_qqq_file(output_dir):\n \"\"\"Creates a qqq.json file with message documentation for translatewiki.net.\n\n The file consists of key-value pairs, where the keys are message ids and\n the values are descriptions for the translators of the messages.\n What documentation exists for the format can be found at:\n http:\/\/translatewiki.net\/wiki\/Translating:Localisation_for_developers#Message_documentation\n\n The file should be closed by _close_qqq_file().\n\n Parameters:\n output_dir: The output directory.\n\n Returns:\n A pointer to a file to which a left brace and newline have been written.\n\n Raises:\n IOError: An error occurred while opening or writing the file.\n \"\"\"\n qqq_file_name = os.path.join(os.curdir, output_dir, 'qqq.json')\n qqq_file = codecs.open(qqq_file_name, 'w', 'utf-8')\n print 'Created file: ' + qqq_file_name\n qqq_file.write('{\\n')\n return qqq_file","function_tokens":["def","_create_qqq_file","(","output_dir",")",":","qqq_file_name","=","os",".","path",".","join","(","os",".","curdir",",","output_dir",",","'qqq.json'",")","qqq_file","=","codecs",".","open","(","qqq_file_name",",","'w'",",","'utf-8'",")","print","'Created file: '","+","qqq_file_name","qqq_file",".","write","(","'{\\n'",")","return","qqq_file"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/blockly\/i18n\/common.py#L67-L90"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"blockly\/i18n\/common.py","language":"python","identifier":"_close_qqq_file","parameters":"(qqq_file)","argument_list":"","return_statement":"","docstring":"Closes a qqq.json file created and opened by _create_qqq_file().\n\n This writes the final newlines and right brace.\n\n Args:\n qqq_file: A file created by _create_qqq_file().\n\n Raises:\n IOError: An error occurred while writing to or closing the file.","docstring_summary":"Closes a qqq.json file created and opened by _create_qqq_file().","docstring_tokens":["Closes","a","qqq",".","json","file","created","and","opened","by","_create_qqq_file","()","."],"function":"def _close_qqq_file(qqq_file):\n \"\"\"Closes a qqq.json file created and opened by _create_qqq_file().\n\n This writes the final newlines and right brace.\n\n Args:\n qqq_file: A file created by _create_qqq_file().\n\n Raises:\n IOError: An error occurred while writing to or closing the file.\n \"\"\"\n qqq_file.write('\\n}\\n')\n qqq_file.close()","function_tokens":["def","_close_qqq_file","(","qqq_file",")",":","qqq_file",".","write","(","'\\n}\\n'",")","qqq_file",".","close","(",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/blockly\/i18n\/common.py#L93-L105"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"blockly\/i18n\/common.py","language":"python","identifier":"_create_lang_file","parameters":"(author, lang, output_dir)","argument_list":"","return_statement":"return lang_file","docstring":"Creates a <lang>.json file for translatewiki.net.\n\n The file consists of metadata, followed by key-value pairs, where the keys\n are message ids and the values are the messages in the language specified\n by the corresponding command-line argument. The file should be closed by\n _close_lang_file().\n\n Args:\n author: Name and email address of contact for translators.\n lang: ISO 639-1 source language code.\n output_dir: Relative directory for output files.\n\n Returns:\n A pointer to a file to which the metadata has been written.\n\n Raises:\n IOError: An error occurred while opening or writing the file.","docstring_summary":"Creates a <lang>.json file for translatewiki.net.","docstring_tokens":["Creates","a","<lang",">",".","json","file","for","translatewiki",".","net","."],"function":"def _create_lang_file(author, lang, output_dir):\n \"\"\"Creates a <lang>.json file for translatewiki.net.\n\n The file consists of metadata, followed by key-value pairs, where the keys\n are message ids and the values are the messages in the language specified\n by the corresponding command-line argument. The file should be closed by\n _close_lang_file().\n\n Args:\n author: Name and email address of contact for translators.\n lang: ISO 639-1 source language code.\n output_dir: Relative directory for output files.\n\n Returns:\n A pointer to a file to which the metadata has been written.\n\n Raises:\n IOError: An error occurred while opening or writing the file.\n \"\"\"\n lang_file_name = os.path.join(os.curdir, output_dir, lang + '.json')\n lang_file = codecs.open(lang_file_name, 'w', 'utf-8')\n print 'Created file: ' + lang_file_name\n # string.format doesn't like printing braces, so break up our writes.\n lang_file.write('{\\n\\t\"@metadata\": {')\n lang_file.write(\"\"\"\n\\t\\t\"author\": \"{0}\",\n\\t\\t\"lastupdated\": \"{1}\",\n\\t\\t\"locale\": \"{2}\",\n\\t\\t\"messagedocumentation\" : \"qqq\"\n\"\"\".format(author, str(datetime.now()), lang))\n lang_file.write('\\t},\\n')\n return lang_file","function_tokens":["def","_create_lang_file","(","author",",","lang",",","output_dir",")",":","lang_file_name","=","os",".","path",".","join","(","os",".","curdir",",","output_dir",",","lang","+","'.json'",")","lang_file","=","codecs",".","open","(","lang_file_name",",","'w'",",","'utf-8'",")","print","'Created file: '","+","lang_file_name","# string.format doesn't like printing braces, so break up our writes.","lang_file",".","write","(","'{\\n\\t\"@metadata\": {'",")","lang_file",".","write","(","\"\"\"\n\\t\\t\"author\": \"{0}\",\n\\t\\t\"lastupdated\": \"{1}\",\n\\t\\t\"locale\": \"{2}\",\n\\t\\t\"messagedocumentation\" : \"qqq\"\n\"\"\"",".","format","(","author",",","str","(","datetime",".","now","(",")",")",",","lang",")",")","lang_file",".","write","(","'\\t},\\n'",")","return","lang_file"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/blockly\/i18n\/common.py#L108-L139"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"blockly\/i18n\/common.py","language":"python","identifier":"_close_lang_file","parameters":"(lang_file)","argument_list":"","return_statement":"","docstring":"Closes a <lang>.json file created with _create_lang_file().\n\n This also writes the terminating left brace and newline.\n\n Args:\n lang_file: A file opened with _create_lang_file().\n\n Raises:\n IOError: An error occurred while writing to or closing the file.","docstring_summary":"Closes a <lang>.json file created with _create_lang_file().","docstring_tokens":["Closes","a","<lang",">",".","json","file","created","with","_create_lang_file","()","."],"function":"def _close_lang_file(lang_file):\n \"\"\"Closes a <lang>.json file created with _create_lang_file().\n\n This also writes the terminating left brace and newline.\n\n Args:\n lang_file: A file opened with _create_lang_file().\n\n Raises:\n IOError: An error occurred while writing to or closing the file.\n \"\"\"\n lang_file.write('\\n}\\n')\n lang_file.close()","function_tokens":["def","_close_lang_file","(","lang_file",")",":","lang_file",".","write","(","'\\n}\\n'",")","lang_file",".","close","(",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/blockly\/i18n\/common.py#L142-L154"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"blockly\/i18n\/common.py","language":"python","identifier":"_create_key_file","parameters":"(output_dir)","argument_list":"","return_statement":"return key_file","docstring":"Creates a keys.json file mapping Closure keys to Blockly keys.\n\n Args:\n output_dir: Relative directory for output files.\n\n Raises:\n IOError: An error occurred while creating the file.","docstring_summary":"Creates a keys.json file mapping Closure keys to Blockly keys.","docstring_tokens":["Creates","a","keys",".","json","file","mapping","Closure","keys","to","Blockly","keys","."],"function":"def _create_key_file(output_dir):\n \"\"\"Creates a keys.json file mapping Closure keys to Blockly keys.\n\n Args:\n output_dir: Relative directory for output files.\n\n Raises:\n IOError: An error occurred while creating the file.\n \"\"\"\n key_file_name = os.path.join(os.curdir, output_dir, 'keys.json')\n key_file = open(key_file_name, 'w')\n key_file.write('{\\n')\n print 'Created file: ' + key_file_name\n return key_file","function_tokens":["def","_create_key_file","(","output_dir",")",":","key_file_name","=","os",".","path",".","join","(","os",".","curdir",",","output_dir",",","'keys.json'",")","key_file","=","open","(","key_file_name",",","'w'",")","key_file",".","write","(","'{\\n'",")","print","'Created file: '","+","key_file_name","return","key_file"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/blockly\/i18n\/common.py#L157-L170"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"blockly\/i18n\/common.py","language":"python","identifier":"_close_key_file","parameters":"(key_file)","argument_list":"","return_statement":"","docstring":"Closes a key file created and opened with _create_key_file().\n\n Args:\n key_file: A file created by _create_key_file().\n\n Raises:\n IOError: An error occurred while writing to or closing the file.","docstring_summary":"Closes a key file created and opened with _create_key_file().","docstring_tokens":["Closes","a","key","file","created","and","opened","with","_create_key_file","()","."],"function":"def _close_key_file(key_file):\n \"\"\"Closes a key file created and opened with _create_key_file().\n\n Args:\n key_file: A file created by _create_key_file().\n\n Raises:\n IOError: An error occurred while writing to or closing the file.\n \"\"\"\n key_file.write('\\n}\\n')\n key_file.close()","function_tokens":["def","_close_key_file","(","key_file",")",":","key_file",".","write","(","'\\n}\\n'",")","key_file",".","close","(",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/blockly\/i18n\/common.py#L173-L183"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"blockly\/i18n\/common.py","language":"python","identifier":"write_files","parameters":"(author, lang, output_dir, units, write_key_file)","argument_list":"","return_statement":"","docstring":"Writes the output files for the given units.\n\n There are three possible output files:\n * lang_file: JSON file mapping meanings (e.g., Maze.turnLeft) to the\n English text. The base name of the language file is specified by the\n \"lang\" command-line argument.\n * key_file: JSON file mapping meanings to Soy-generated keys (long hash\n codes). This is only output if the parameter write_key_file is True.\n * qqq_file: JSON file mapping meanings to descriptions.\n\n Args:\n author: Name and email address of contact for translators.\n lang: ISO 639-1 source language code.\n output_dir: Relative directory for output files.\n units: A list of dictionaries with entries for 'meaning', 'source',\n 'description', and 'keys' (the last only if write_key_file is true),\n in the order desired in the output files.\n write_key_file: Whether to output a keys.json file.\n\n Raises:\n IOError: An error occurs opening, writing to, or closing a file.\n KeyError: An expected key is missing from units.","docstring_summary":"Writes the output files for the given units.","docstring_tokens":["Writes","the","output","files","for","the","given","units","."],"function":"def write_files(author, lang, output_dir, units, write_key_file):\n \"\"\"Writes the output files for the given units.\n\n There are three possible output files:\n * lang_file: JSON file mapping meanings (e.g., Maze.turnLeft) to the\n English text. The base name of the language file is specified by the\n \"lang\" command-line argument.\n * key_file: JSON file mapping meanings to Soy-generated keys (long hash\n codes). This is only output if the parameter write_key_file is True.\n * qqq_file: JSON file mapping meanings to descriptions.\n\n Args:\n author: Name and email address of contact for translators.\n lang: ISO 639-1 source language code.\n output_dir: Relative directory for output files.\n units: A list of dictionaries with entries for 'meaning', 'source',\n 'description', and 'keys' (the last only if write_key_file is true),\n in the order desired in the output files.\n write_key_file: Whether to output a keys.json file.\n\n Raises:\n IOError: An error occurs opening, writing to, or closing a file.\n KeyError: An expected key is missing from units.\n \"\"\"\n lang_file = _create_lang_file(author, lang, output_dir)\n qqq_file = _create_qqq_file(output_dir)\n if write_key_file:\n key_file = _create_key_file(output_dir)\n first_entry = True\n for unit in units:\n if not first_entry:\n lang_file.write(',\\n')\n if write_key_file:\n key_file.write(',\\n')\n qqq_file.write(',\\n')\n lang_file.write(u'\\t\"{0}\": \"{1}\"'.format(\n unit['meaning'],\n unit['source'].replace('\"', \"'\")))\n if write_key_file:\n key_file.write('\"{0}\": \"{1}\"'.format(unit['meaning'], unit['key']))\n qqq_file.write(u'\\t\"{0}\": \"{1}\"'.format(\n unit['meaning'],\n unit['description'].replace('\"', \"'\").replace(\n '{lb}', '{').replace('{rb}', '}')))\n first_entry = False\n _close_lang_file(lang_file)\n if write_key_file:\n _close_key_file(key_file)\n _close_qqq_file(qqq_file)","function_tokens":["def","write_files","(","author",",","lang",",","output_dir",",","units",",","write_key_file",")",":","lang_file","=","_create_lang_file","(","author",",","lang",",","output_dir",")","qqq_file","=","_create_qqq_file","(","output_dir",")","if","write_key_file",":","key_file","=","_create_key_file","(","output_dir",")","first_entry","=","True","for","unit","in","units",":","if","not","first_entry",":","lang_file",".","write","(","',\\n'",")","if","write_key_file",":","key_file",".","write","(","',\\n'",")","qqq_file",".","write","(","',\\n'",")","lang_file",".","write","(","u'\\t\"{0}\": \"{1}\"'",".","format","(","unit","[","'meaning'","]",",","unit","[","'source'","]",".","replace","(","'\"'",",","\"'\"",")",")",")","if","write_key_file",":","key_file",".","write","(","'\"{0}\": \"{1}\"'",".","format","(","unit","[","'meaning'","]",",","unit","[","'key'","]",")",")","qqq_file",".","write","(","u'\\t\"{0}\": \"{1}\"'",".","format","(","unit","[","'meaning'","]",",","unit","[","'description'","]",".","replace","(","'\"'",",","\"'\"",")",".","replace","(","'{lb}'",",","'{'",")",".","replace","(","'{rb}'",",","'}'",")",")",")","first_entry","=","False","_close_lang_file","(","lang_file",")","if","write_key_file",":","_close_key_file","(","key_file",")","_close_qqq_file","(","qqq_file",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/blockly\/i18n\/common.py#L186-L234"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"blockly\/i18n\/xliff_to_json.py","language":"python","identifier":"_parse_trans_unit","parameters":"(trans_unit)","argument_list":"","return_statement":"return result","docstring":"Converts a trans-unit XML node into a more convenient dictionary format.\n\n Args:\n trans_unit: An XML representation of a .xlf translation unit.\n\n Returns:\n A dictionary with useful information about the translation unit.\n The returned dictionary is guaranteed to have an entry for 'key' and\n may have entries for 'source', 'target', 'description', and 'meaning'\n if present in the argument.\n\n Raises:\n InputError: A required field was not present.","docstring_summary":"Converts a trans-unit XML node into a more convenient dictionary format.","docstring_tokens":["Converts","a","trans","-","unit","XML","node","into","a","more","convenient","dictionary","format","."],"function":"def _parse_trans_unit(trans_unit):\n \"\"\"Converts a trans-unit XML node into a more convenient dictionary format.\n\n Args:\n trans_unit: An XML representation of a .xlf translation unit.\n\n Returns:\n A dictionary with useful information about the translation unit.\n The returned dictionary is guaranteed to have an entry for 'key' and\n may have entries for 'source', 'target', 'description', and 'meaning'\n if present in the argument.\n\n Raises:\n InputError: A required field was not present.\n \"\"\"\n\n def get_value(tag_name):\n elts = trans_unit.getElementsByTagName(tag_name)\n if not elts:\n return None\n elif len(elts) == 1:\n return ''.join([child.toxml() for child in elts[0].childNodes])\n else:\n raise InputError('', 'Unable to extract ' + tag_name)\n\n result = {}\n key = trans_unit.getAttribute('id')\n if not key:\n raise InputError('', 'id attribute not found')\n result['key'] = key\n\n # Get source and target, if present.\n try:\n result['source'] = get_value('source')\n result['target'] = get_value('target')\n except InputError, e:\n raise InputError(key, e.msg)\n\n # Get notes, using the from value as key and the data as value.\n notes = trans_unit.getElementsByTagName('note')\n for note in notes:\n from_value = note.getAttribute('from')\n if from_value and len(note.childNodes) == 1:\n result[from_value] = note.childNodes[0].data\n else:\n raise InputError(key, 'Unable to extract ' + from_value)\n\n return result","function_tokens":["def","_parse_trans_unit","(","trans_unit",")",":","def","get_value","(","tag_name",")",":","elts","=","trans_unit",".","getElementsByTagName","(","tag_name",")","if","not","elts",":","return","None","elif","len","(","elts",")","==","1",":","return","''",".","join","(","[","child",".","toxml","(",")","for","child","in","elts","[","0","]",".","childNodes","]",")","else",":","raise","InputError","(","''",",","'Unable to extract '","+","tag_name",")","result","=","{","}","key","=","trans_unit",".","getAttribute","(","'id'",")","if","not","key",":","raise","InputError","(","''",",","'id attribute not found'",")","result","[","'key'","]","=","key","# Get source and target, if present.","try",":","result","[","'source'","]","=","get_value","(","'source'",")","result","[","'target'","]","=","get_value","(","'target'",")","except","InputError",",","e",":","raise","InputError","(","key",",","e",".","msg",")","# Get notes, using the from value as key and the data as value.","notes","=","trans_unit",".","getElementsByTagName","(","'note'",")","for","note","in","notes",":","from_value","=","note",".","getAttribute","(","'from'",")","if","from_value","and","len","(","note",".","childNodes",")","==","1",":","result","[","from_value","]","=","note",".","childNodes","[","0","]",".","data","else",":","raise","InputError","(","key",",","'Unable to extract '","+","from_value",")","return","result"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/blockly\/i18n\/xliff_to_json.py#L33-L80"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"blockly\/i18n\/xliff_to_json.py","language":"python","identifier":"_process_file","parameters":"(filename)","argument_list":"","return_statement":"","docstring":"Builds list of translation units from input file.\n\n Each translation unit in the input file includes:\n - an id (opaquely generated by Soy)\n - the Blockly name for the message\n - the text in the source language (generally English)\n - a description for the translator\n\n The Soy and Blockly ids are joined with a hyphen and serve as the\n keys in both output files. The value is the corresponding text (in the\n <lang>.json file) or the description (in the qqq.json file).\n\n Args:\n filename: The name of an .xlf file produced by Closure.\n\n Raises:\n IOError: An I\/O error occurred with an input or output file.\n InputError: The input file could not be parsed or lacked required\n fields.\n\n Returns:\n A list of dictionaries produced by parse_trans_unit().","docstring_summary":"Builds list of translation units from input file.","docstring_tokens":["Builds","list","of","translation","units","from","input","file","."],"function":"def _process_file(filename):\n \"\"\"Builds list of translation units from input file.\n\n Each translation unit in the input file includes:\n - an id (opaquely generated by Soy)\n - the Blockly name for the message\n - the text in the source language (generally English)\n - a description for the translator\n\n The Soy and Blockly ids are joined with a hyphen and serve as the\n keys in both output files. The value is the corresponding text (in the\n <lang>.json file) or the description (in the qqq.json file).\n\n Args:\n filename: The name of an .xlf file produced by Closure.\n\n Raises:\n IOError: An I\/O error occurred with an input or output file.\n InputError: The input file could not be parsed or lacked required\n fields.\n\n Returns:\n A list of dictionaries produced by parse_trans_unit().\n \"\"\"\n try:\n results = [] # list of dictionaries (return value)\n names = [] # list of names of encountered keys (local variable)\n try:\n parsed_xml = minidom.parse(filename)\n except IOError:\n # Don't get caught by below handler\n raise\n except Exception, e:\n print\n raise InputError(filename, str(e))\n\n # Make sure needed fields are present and non-empty.\n for trans_unit in parsed_xml.getElementsByTagName('trans-unit'):\n unit = _parse_trans_unit(trans_unit)\n for key in ['description', 'meaning', 'source']:\n if not key in unit or not unit[key]:\n raise InputError(filename + ':' + unit['key'],\n key + ' not found')\n if unit['description'].lower() == 'ibid':\n if unit['meaning'] not in names:\n # If the term has not already been described, the use of 'ibid'\n # is an error.\n raise InputError(\n filename,\n 'First encountered definition of: ' + unit['meaning']\n + ' has definition: ' + unit['description']\n + '. This error can occur if the definition was not'\n + ' provided on the first appearance of the message'\n + ' or if the source (English-language) messages differ.')\n else:\n # If term has already been described, 'ibid' was used correctly,\n # and we output nothing.\n pass\n else:\n if unit['meaning'] in names:\n raise InputError(filename,\n 'Second definition of: ' + unit['meaning'])\n names.append(unit['meaning'])\n results.append(unit)\n\n return results\n except IOError, e:\n print 'Error with file {0}: {1}'.format(filename, e.strerror)\n sys.exit(1)","function_tokens":["def","_process_file","(","filename",")",":","try",":","results","=","[","]","# list of dictionaries (return value)","names","=","[","]","# list of names of encountered keys (local variable)","try",":","parsed_xml","=","minidom",".","parse","(","filename",")","except","IOError",":","# Don't get caught by below handler","raise","except","Exception",",","e",":","print","raise","InputError","(","filename",",","str","(","e",")",")","# Make sure needed fields are present and non-empty.","for","trans_unit","in","parsed_xml",".","getElementsByTagName","(","'trans-unit'",")",":","unit","=","_parse_trans_unit","(","trans_unit",")","for","key","in","[","'description'",",","'meaning'",",","'source'","]",":","if","not","key","in","unit","or","not","unit","[","key","]",":","raise","InputError","(","filename","+","':'","+","unit","[","'key'","]",",","key","+","' not found'",")","if","unit","[","'description'","]",".","lower","(",")","==","'ibid'",":","if","unit","[","'meaning'","]","not","in","names",":","# If the term has not already been described, the use of 'ibid'","# is an error.","raise","InputError","(","filename",",","'First encountered definition of: '","+","unit","[","'meaning'","]","+","' has definition: '","+","unit","[","'description'","]","+","'. This error can occur if the definition was not'","+","' provided on the first appearance of the message'","+","' or if the source (English-language) messages differ.'",")","else",":","# If term has already been described, 'ibid' was used correctly,","# and we output nothing.","pass","else",":","if","unit","[","'meaning'","]","in","names",":","raise","InputError","(","filename",",","'Second definition of: '","+","unit","[","'meaning'","]",")","names",".","append","(","unit","[","'meaning'","]",")","results",".","append","(","unit",")","return","results","except","IOError",",","e",":","print","'Error with file {0}: {1}'",".","format","(","filename",",","e",".","strerror",")","sys",".","exit","(","1",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/blockly\/i18n\/xliff_to_json.py#L83-L151"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"blockly\/i18n\/xliff_to_json.py","language":"python","identifier":"sort_units","parameters":"(units, templates)","argument_list":"","return_statement":"return sorted(units, key=key_function)","docstring":"Sorts the translation units by their definition order in the template.\n\n Args:\n units: A list of dictionaries produced by parse_trans_unit()\n that have a non-empty value for the key 'meaning'.\n templates: A string containing the Soy templates in which each of\n the units' meanings is defined.\n\n Returns:\n A new list of translation units, sorted by the order in which\n their meaning is defined in the templates.\n\n Raises:\n InputError: If a meaning definition cannot be found in the\n templates.","docstring_summary":"Sorts the translation units by their definition order in the template.","docstring_tokens":["Sorts","the","translation","units","by","their","definition","order","in","the","template","."],"function":"def sort_units(units, templates):\n \"\"\"Sorts the translation units by their definition order in the template.\n\n Args:\n units: A list of dictionaries produced by parse_trans_unit()\n that have a non-empty value for the key 'meaning'.\n templates: A string containing the Soy templates in which each of\n the units' meanings is defined.\n\n Returns:\n A new list of translation units, sorted by the order in which\n their meaning is defined in the templates.\n\n Raises:\n InputError: If a meaning definition cannot be found in the\n templates.\n \"\"\"\n def key_function(unit):\n match = re.search(\n '\\\\smeaning\\\\s*=\\\\s*\"{0}\"\\\\s'.format(unit['meaning']),\n templates)\n if match:\n return match.start()\n else:\n raise InputError(args.templates,\n 'msg definition for meaning not found: ' +\n unit['meaning'])\n return sorted(units, key=key_function)","function_tokens":["def","sort_units","(","units",",","templates",")",":","def","key_function","(","unit",")",":","match","=","re",".","search","(","'\\\\smeaning\\\\s*=\\\\s*\"{0}\"\\\\s'",".","format","(","unit","[","'meaning'","]",")",",","templates",")","if","match",":","return","match",".","start","(",")","else",":","raise","InputError","(","args",".","templates",",","'msg definition for meaning not found: '","+","unit","[","'meaning'","]",")","return","sorted","(","units",",","key","=","key_function",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/blockly\/i18n\/xliff_to_json.py#L154-L181"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"blockly\/i18n\/xliff_to_json.py","language":"python","identifier":"main","parameters":"()","argument_list":"","return_statement":"","docstring":"Parses arguments and processes the specified file.\n\n Raises:\n IOError: An I\/O error occurred with an input or output file.\n InputError: Input files lacked required fields.","docstring_summary":"Parses arguments and processes the specified file.","docstring_tokens":["Parses","arguments","and","processes","the","specified","file","."],"function":"def main():\n \"\"\"Parses arguments and processes the specified file.\n\n Raises:\n IOError: An I\/O error occurred with an input or output file.\n InputError: Input files lacked required fields.\n \"\"\"\n # Set up argument parser.\n parser = argparse.ArgumentParser(description='Create translation files.')\n parser.add_argument(\n '--author',\n default='Ellen Spertus <ellen.spertus@gmail.com>',\n help='name and email address of contact for translators')\n parser.add_argument('--lang', default='en',\n help='ISO 639-1 source language code')\n parser.add_argument('--output_dir', default='json',\n help='relative directory for output files')\n parser.add_argument('--xlf', help='file containing xlf definitions')\n parser.add_argument('--templates', default=['template.soy'], nargs='+',\n help='relative path to Soy templates, comma or space '\n 'separated (used for ordering messages)')\n global args\n args = parser.parse_args()\n\n # Make sure output_dir ends with slash.\n if (not args.output_dir.endswith(os.path.sep)):\n args.output_dir += os.path.sep\n\n # Process the input file, and sort the entries.\n units = _process_file(args.xlf)\n files = []\n for arg in args.templates:\n for filename in arg.split(','):\n filename = filename.strip();\n if filename:\n with open(filename) as myfile:\n files.append(' '.join(line.strip() for line in myfile))\n sorted_units = sort_units(units, ' '.join(files))\n\n # Write the output files.\n write_files(args.author, args.lang, args.output_dir, sorted_units, True)\n\n # Delete the input .xlf file.\n os.remove(args.xlf)\n print('Removed ' + args.xlf)","function_tokens":["def","main","(",")",":","# Set up argument parser.","parser","=","argparse",".","ArgumentParser","(","description","=","'Create translation files.'",")","parser",".","add_argument","(","'--author'",",","default","=","'Ellen Spertus <ellen.spertus@gmail.com>'",",","help","=","'name and email address of contact for translators'",")","parser",".","add_argument","(","'--lang'",",","default","=","'en'",",","help","=","'ISO 639-1 source language code'",")","parser",".","add_argument","(","'--output_dir'",",","default","=","'json'",",","help","=","'relative directory for output files'",")","parser",".","add_argument","(","'--xlf'",",","help","=","'file containing xlf definitions'",")","parser",".","add_argument","(","'--templates'",",","default","=","[","'template.soy'","]",",","nargs","=","'+'",",","help","=","'relative path to Soy templates, comma or space '","'separated (used for ordering messages)'",")","global","args","args","=","parser",".","parse_args","(",")","# Make sure output_dir ends with slash.","if","(","not","args",".","output_dir",".","endswith","(","os",".","path",".","sep",")",")",":","args",".","output_dir","+=","os",".","path",".","sep","# Process the input file, and sort the entries.","units","=","_process_file","(","args",".","xlf",")","files","=","[","]","for","arg","in","args",".","templates",":","for","filename","in","arg",".","split","(","','",")",":","filename","=","filename",".","strip","(",")","if","filename",":","with","open","(","filename",")","as","myfile",":","files",".","append","(","' '",".","join","(","line",".","strip","(",")","for","line","in","myfile",")",")","sorted_units","=","sort_units","(","units",",","' '",".","join","(","files",")",")","# Write the output files.","write_files","(","args",".","author",",","args",".","lang",",","args",".","output_dir",",","sorted_units",",","True",")","# Delete the input .xlf file.","os",".","remove","(","args",".","xlf",")","print","(","'Removed '","+","args",".","xlf",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/blockly\/i18n\/xliff_to_json.py#L184-L228"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/scopify.py","language":"python","identifier":"Transform","parameters":"(lines)","argument_list":"","return_statement":"","docstring":"Converts the contents of a file into javascript that uses goog.scope.\n\n Arguments:\n lines: A list of strings, corresponding to each line of the file.\n Returns:\n A new list of strings, or None if the file was not modified.","docstring_summary":"Converts the contents of a file into javascript that uses goog.scope.","docstring_tokens":["Converts","the","contents","of","a","file","into","javascript","that","uses","goog",".","scope","."],"function":"def Transform(lines):\n \"\"\"Converts the contents of a file into javascript that uses goog.scope.\n\n Arguments:\n lines: A list of strings, corresponding to each line of the file.\n Returns:\n A new list of strings, or None if the file was not modified.\n \"\"\"\n requires = []\n\n # Do an initial scan to be sure that this file can be processed.\n for line in lines:\n # Skip this file if it has already been scopified.\n if line.find('goog.scope') != -1:\n return None\n\n # If there are any global vars or functions, then we also have\n # to skip the whole file. We might be able to deal with this\n # more elegantly.\n if line.find('var ') == 0 or line.find('function ') == 0:\n return None\n\n for match in REQUIRES_RE.finditer(line):\n requires.append(match.group(1))\n\n if len(requires) == 0:\n return None\n\n # Backwards-sort the requires, so that when one is a substring of another,\n # we match the longer one first.\n for val in DEFAULT_ALIASES.values():\n if requires.count(val) == 0:\n requires.append(val)\n\n requires.sort()\n requires.reverse()\n\n # Generate a map of requires to their aliases\n aliases_to_globals = DEFAULT_ALIASES.copy()\n for req in requires:\n index = req.rfind('.')\n if index == -1:\n alias = req\n else:\n alias = req[(index + 1):]\n\n # Don't scopify lowercase namespaces, because they may conflict with\n # local variables.\n if alias[0].isupper():\n aliases_to_globals[alias] = req\n\n aliases_to_matchers = {}\n globals_to_aliases = {}\n for alias, symbol in aliases_to_globals.items():\n globals_to_aliases[symbol] = alias\n aliases_to_matchers[alias] = re.compile('\\\\b%s\\\\b' % symbol)\n\n # Insert a goog.scope that aliases all required symbols.\n result = []\n\n START = 0\n SEEN_REQUIRES = 1\n IN_SCOPE = 2\n\n mode = START\n aliases_used = set()\n insertion_index = None\n num_blank_lines = 0\n for line in lines:\n if mode == START:\n result.append(line)\n\n if re.search(REQUIRES_RE, line):\n mode = SEEN_REQUIRES\n\n elif mode == SEEN_REQUIRES:\n if (line and\n not re.search(REQUIRES_RE, line) and\n not line.isspace()):\n # There should be two blank lines before goog.scope\n result += ['\\n'] * 2\n result.append('goog.scope(function() {\\n')\n insertion_index = len(result)\n result += ['\\n'] * num_blank_lines\n mode = IN_SCOPE\n elif line.isspace():\n # Keep track of the number of blank lines before each block of code so\n # that we can move them after the goog.scope line if necessary.\n num_blank_lines += 1\n else:\n # Print the blank lines we saw before this code block\n result += ['\\n'] * num_blank_lines\n num_blank_lines = 0\n result.append(line)\n\n if mode == IN_SCOPE:\n for symbol in requires:\n if not symbol in globals_to_aliases:\n continue\n\n alias = globals_to_aliases[symbol]\n matcher = aliases_to_matchers[alias]\n for match in matcher.finditer(line):\n # Check to make sure we're not in a string.\n # We do this by being as conservative as possible:\n # if there are any quote or double quote characters\n # before the symbol on this line, then bail out.\n before_symbol = line[:match.start(0)]\n if before_symbol.count('\"') > 0 or before_symbol.count(\"'\") > 0:\n continue\n\n line = line.replace(match.group(0), alias)\n aliases_used.add(alias)\n\n if line.isspace():\n # Truncate all-whitespace lines\n result.append('\\n')\n else:\n result.append(line)\n\n if len(aliases_used):\n aliases_used = [alias for alias in aliases_used]\n aliases_used.sort()\n aliases_used.reverse()\n for alias in aliases_used:\n symbol = aliases_to_globals[alias]\n result.insert(insertion_index,\n 'var %s = %s;\\n' % (alias, symbol))\n result.append('}); \/\/ goog.scope\\n')\n return result\n else:\n return None","function_tokens":["def","Transform","(","lines",")",":","requires","=","[","]","# Do an initial scan to be sure that this file can be processed.","for","line","in","lines",":","# Skip this file if it has already been scopified.","if","line",".","find","(","'goog.scope'",")","!=","-","1",":","return","None","# If there are any global vars or functions, then we also have","# to skip the whole file. We might be able to deal with this","# more elegantly.","if","line",".","find","(","'var '",")","==","0","or","line",".","find","(","'function '",")","==","0",":","return","None","for","match","in","REQUIRES_RE",".","finditer","(","line",")",":","requires",".","append","(","match",".","group","(","1",")",")","if","len","(","requires",")","==","0",":","return","None","# Backwards-sort the requires, so that when one is a substring of another,","# we match the longer one first.","for","val","in","DEFAULT_ALIASES",".","values","(",")",":","if","requires",".","count","(","val",")","==","0",":","requires",".","append","(","val",")","requires",".","sort","(",")","requires",".","reverse","(",")","# Generate a map of requires to their aliases","aliases_to_globals","=","DEFAULT_ALIASES",".","copy","(",")","for","req","in","requires",":","index","=","req",".","rfind","(","'.'",")","if","index","==","-","1",":","alias","=","req","else",":","alias","=","req","[","(","index","+","1",")",":","]","# Don't scopify lowercase namespaces, because they may conflict with","# local variables.","if","alias","[","0","]",".","isupper","(",")",":","aliases_to_globals","[","alias","]","=","req","aliases_to_matchers","=","{","}","globals_to_aliases","=","{","}","for","alias",",","symbol","in","aliases_to_globals",".","items","(",")",":","globals_to_aliases","[","symbol","]","=","alias","aliases_to_matchers","[","alias","]","=","re",".","compile","(","'\\\\b%s\\\\b'","%","symbol",")","# Insert a goog.scope that aliases all required symbols.","result","=","[","]","START","=","0","SEEN_REQUIRES","=","1","IN_SCOPE","=","2","mode","=","START","aliases_used","=","set","(",")","insertion_index","=","None","num_blank_lines","=","0","for","line","in","lines",":","if","mode","==","START",":","result",".","append","(","line",")","if","re",".","search","(","REQUIRES_RE",",","line",")",":","mode","=","SEEN_REQUIRES","elif","mode","==","SEEN_REQUIRES",":","if","(","line","and","not","re",".","search","(","REQUIRES_RE",",","line",")","and","not","line",".","isspace","(",")",")",":","# There should be two blank lines before goog.scope","result","+=","[","'\\n'","]","*","2","result",".","append","(","'goog.scope(function() {\\n'",")","insertion_index","=","len","(","result",")","result","+=","[","'\\n'","]","*","num_blank_lines","mode","=","IN_SCOPE","elif","line",".","isspace","(",")",":","# Keep track of the number of blank lines before each block of code so","# that we can move them after the goog.scope line if necessary.","num_blank_lines","+=","1","else",":","# Print the blank lines we saw before this code block","result","+=","[","'\\n'","]","*","num_blank_lines","num_blank_lines","=","0","result",".","append","(","line",")","if","mode","==","IN_SCOPE",":","for","symbol","in","requires",":","if","not","symbol","in","globals_to_aliases",":","continue","alias","=","globals_to_aliases","[","symbol","]","matcher","=","aliases_to_matchers","[","alias","]","for","match","in","matcher",".","finditer","(","line",")",":","# Check to make sure we're not in a string.","# We do this by being as conservative as possible:","# if there are any quote or double quote characters","# before the symbol on this line, then bail out.","before_symbol","=","line","[",":","match",".","start","(","0",")","]","if","before_symbol",".","count","(","'\"'",")",">","0","or","before_symbol",".","count","(","\"'\"",")",">","0",":","continue","line","=","line",".","replace","(","match",".","group","(","0",")",",","alias",")","aliases_used",".","add","(","alias",")","if","line",".","isspace","(",")",":","# Truncate all-whitespace lines","result",".","append","(","'\\n'",")","else",":","result",".","append","(","line",")","if","len","(","aliases_used",")",":","aliases_used","=","[","alias","for","alias","in","aliases_used","]","aliases_used",".","sort","(",")","aliases_used",".","reverse","(",")","for","alias","in","aliases_used",":","symbol","=","aliases_to_globals","[","alias","]","result",".","insert","(","insertion_index",",","'var %s = %s;\\n'","%","(","alias",",","symbol",")",")","result",".","append","(","'}); \/\/ goog.scope\\n'",")","return","result","else",":","return","None"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/scopify.py#L59-L190"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/scopify.py","language":"python","identifier":"TransformFileAt","parameters":"(path)","argument_list":"","return_statement":"","docstring":"Converts a file into javascript that uses goog.scope.\n\n Arguments:\n path: A path to a file.","docstring_summary":"Converts a file into javascript that uses goog.scope.","docstring_tokens":["Converts","a","file","into","javascript","that","uses","goog",".","scope","."],"function":"def TransformFileAt(path):\n \"\"\"Converts a file into javascript that uses goog.scope.\n\n Arguments:\n path: A path to a file.\n \"\"\"\n f = open(path)\n lines = Transform(f.readlines())\n if lines:\n f = open(path, 'w')\n for l in lines:\n f.write(l)\n f.close()","function_tokens":["def","TransformFileAt","(","path",")",":","f","=","open","(","path",")","lines","=","Transform","(","f",".","readlines","(",")",")","if","lines",":","f","=","open","(","path",",","'w'",")","for","l","in","lines",":","f",".","write","(","l",")","f",".","close","(",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/scopify.py#L192-L204"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/calcdeps.py","language":"python","identifier":"IsValidFile","parameters":"(ref)","argument_list":"","return_statement":"return os.path.isfile(ref)","docstring":"Returns true if the provided reference is a file and exists.","docstring_summary":"Returns true if the provided reference is a file and exists.","docstring_tokens":["Returns","true","if","the","provided","reference","is","a","file","and","exists","."],"function":"def IsValidFile(ref):\n \"\"\"Returns true if the provided reference is a file and exists.\"\"\"\n return os.path.isfile(ref)","function_tokens":["def","IsValidFile","(","ref",")",":","return","os",".","path",".","isfile","(","ref",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/calcdeps.py#L53-L55"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/calcdeps.py","language":"python","identifier":"IsJsFile","parameters":"(ref)","argument_list":"","return_statement":"return ref.endswith('.js')","docstring":"Returns true if the provided reference is a Javascript file.","docstring_summary":"Returns true if the provided reference is a Javascript file.","docstring_tokens":["Returns","true","if","the","provided","reference","is","a","Javascript","file","."],"function":"def IsJsFile(ref):\n \"\"\"Returns true if the provided reference is a Javascript file.\"\"\"\n return ref.endswith('.js')","function_tokens":["def","IsJsFile","(","ref",")",":","return","ref",".","endswith","(","'.js'",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/calcdeps.py#L58-L60"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/calcdeps.py","language":"python","identifier":"IsNamespace","parameters":"(ref)","argument_list":"","return_statement":"return re.match(ns_regex, ref) is not None","docstring":"Returns true if the provided reference is a namespace.","docstring_summary":"Returns true if the provided reference is a namespace.","docstring_tokens":["Returns","true","if","the","provided","reference","is","a","namespace","."],"function":"def IsNamespace(ref):\n \"\"\"Returns true if the provided reference is a namespace.\"\"\"\n return re.match(ns_regex, ref) is not None","function_tokens":["def","IsNamespace","(","ref",")",":","return","re",".","match","(","ns_regex",",","ref",")","is","not","None"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/calcdeps.py#L63-L65"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/calcdeps.py","language":"python","identifier":"IsDirectory","parameters":"(ref)","argument_list":"","return_statement":"return os.path.isdir(ref)","docstring":"Returns true if the provided reference is a directory.","docstring_summary":"Returns true if the provided reference is a directory.","docstring_tokens":["Returns","true","if","the","provided","reference","is","a","directory","."],"function":"def IsDirectory(ref):\n \"\"\"Returns true if the provided reference is a directory.\"\"\"\n return os.path.isdir(ref)","function_tokens":["def","IsDirectory","(","ref",")",":","return","os",".","path",".","isdir","(","ref",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/calcdeps.py#L68-L70"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/calcdeps.py","language":"python","identifier":"ExpandDirectories","parameters":"(refs)","argument_list":"","return_statement":"return map(os.path.normpath, result)","docstring":"Expands any directory references into inputs.\n\n Description:\n Looks for any directories in the provided references. Found directories\n are recursively searched for .js files, which are then added to the result\n list.\n\n Args:\n refs: a list of references such as files, directories, and namespaces\n\n Returns:\n A list of references with directories removed and replaced by any\n .js files that are found in them. Also, the paths will be normalized.","docstring_summary":"Expands any directory references into inputs.","docstring_tokens":["Expands","any","directory","references","into","inputs","."],"function":"def ExpandDirectories(refs):\n \"\"\"Expands any directory references into inputs.\n\n Description:\n Looks for any directories in the provided references. Found directories\n are recursively searched for .js files, which are then added to the result\n list.\n\n Args:\n refs: a list of references such as files, directories, and namespaces\n\n Returns:\n A list of references with directories removed and replaced by any\n .js files that are found in them. Also, the paths will be normalized.\n \"\"\"\n result = []\n for ref in refs:\n if IsDirectory(ref):\n # Disable 'Unused variable' for subdirs\n # pylint: disable=unused-variable\n for (directory, subdirs, filenames) in os.walk(ref):\n for filename in filenames:\n if IsJsFile(filename):\n result.append(os.path.join(directory, filename))\n else:\n result.append(ref)\n return map(os.path.normpath, result)","function_tokens":["def","ExpandDirectories","(","refs",")",":","result","=","[","]","for","ref","in","refs",":","if","IsDirectory","(","ref",")",":","# Disable 'Unused variable' for subdirs","# pylint: disable=unused-variable","for","(","directory",",","subdirs",",","filenames",")","in","os",".","walk","(","ref",")",":","for","filename","in","filenames",":","if","IsJsFile","(","filename",")",":","result",".","append","(","os",".","path",".","join","(","directory",",","filename",")",")","else",":","result",".","append","(","ref",")","return","map","(","os",".","path",".","normpath",",","result",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/calcdeps.py#L73-L99"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/calcdeps.py","language":"python","identifier":"BuildDependenciesFromFiles","parameters":"(files)","argument_list":"","return_statement":"return result","docstring":"Build a list of dependencies from a list of files.\n\n Description:\n Takes a list of files, extracts their provides and requires, and builds\n out a list of dependency objects.\n\n Args:\n files: a list of files to be parsed for goog.provides and goog.requires.\n\n Returns:\n A list of dependency objects, one for each file in the files argument.","docstring_summary":"Build a list of dependencies from a list of files.","docstring_tokens":["Build","a","list","of","dependencies","from","a","list","of","files","."],"function":"def BuildDependenciesFromFiles(files):\n \"\"\"Build a list of dependencies from a list of files.\n\n Description:\n Takes a list of files, extracts their provides and requires, and builds\n out a list of dependency objects.\n\n Args:\n files: a list of files to be parsed for goog.provides and goog.requires.\n\n Returns:\n A list of dependency objects, one for each file in the files argument.\n \"\"\"\n result = []\n filenames = set()\n for filename in files:\n if filename in filenames:\n continue\n\n # Python 3 requires the file encoding to be specified\n if (sys.version_info[0] < 3):\n file_handle = open(filename, 'r')\n else:\n file_handle = open(filename, 'r', encoding='utf8')\n\n try:\n dep = CreateDependencyInfo(filename, file_handle)\n result.append(dep)\n finally:\n file_handle.close()\n\n filenames.add(filename)\n\n return result","function_tokens":["def","BuildDependenciesFromFiles","(","files",")",":","result","=","[","]","filenames","=","set","(",")","for","filename","in","files",":","if","filename","in","filenames",":","continue","# Python 3 requires the file encoding to be specified","if","(","sys",".","version_info","[","0","]","<","3",")",":","file_handle","=","open","(","filename",",","'r'",")","else",":","file_handle","=","open","(","filename",",","'r'",",","encoding","=","'utf8'",")","try",":","dep","=","CreateDependencyInfo","(","filename",",","file_handle",")","result",".","append","(","dep",")","finally",":","file_handle",".","close","(",")","filenames",".","add","(","filename",")","return","result"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/calcdeps.py#L116-L149"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/calcdeps.py","language":"python","identifier":"CreateDependencyInfo","parameters":"(filename, source)","argument_list":"","return_statement":"return dep","docstring":"Create dependency info.\n\n Args:\n filename: Filename for source.\n source: File-like object containing source.\n\n Returns:\n A DependencyInfo object with provides and requires filled.","docstring_summary":"Create dependency info.","docstring_tokens":["Create","dependency","info","."],"function":"def CreateDependencyInfo(filename, source):\n \"\"\"Create dependency info.\n\n Args:\n filename: Filename for source.\n source: File-like object containing source.\n\n Returns:\n A DependencyInfo object with provides and requires filled.\n \"\"\"\n dep = DependencyInfo(filename)\n for line in source:\n if re.match(req_regex, line):\n dep.requires.append(re.search(req_regex, line).group(1))\n if re.match(prov_regex, line):\n dep.provides.append(re.search(prov_regex, line).group(1))\n return dep","function_tokens":["def","CreateDependencyInfo","(","filename",",","source",")",":","dep","=","DependencyInfo","(","filename",")","for","line","in","source",":","if","re",".","match","(","req_regex",",","line",")",":","dep",".","requires",".","append","(","re",".","search","(","req_regex",",","line",")",".","group","(","1",")",")","if","re",".","match","(","prov_regex",",","line",")",":","dep",".","provides",".","append","(","re",".","search","(","prov_regex",",","line",")",".","group","(","1",")",")","return","dep"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/calcdeps.py#L152-L168"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/calcdeps.py","language":"python","identifier":"BuildDependencyHashFromDependencies","parameters":"(deps)","argument_list":"","return_statement":"return dep_hash","docstring":"Builds a hash for searching dependencies by the namespaces they provide.\n\n Description:\n Dependency objects can provide multiple namespaces. This method enumerates\n the provides of each dependency and adds them to a hash that can be used\n to easily resolve a given dependency by a namespace it provides.\n\n Args:\n deps: a list of dependency objects used to build the hash.\n\n Raises:\n Exception: If a multiple files try to provide the same namepace.\n\n Returns:\n A hash table { namespace: dependency } that can be used to resolve a\n dependency by a namespace it provides.","docstring_summary":"Builds a hash for searching dependencies by the namespaces they provide.","docstring_tokens":["Builds","a","hash","for","searching","dependencies","by","the","namespaces","they","provide","."],"function":"def BuildDependencyHashFromDependencies(deps):\n \"\"\"Builds a hash for searching dependencies by the namespaces they provide.\n\n Description:\n Dependency objects can provide multiple namespaces. This method enumerates\n the provides of each dependency and adds them to a hash that can be used\n to easily resolve a given dependency by a namespace it provides.\n\n Args:\n deps: a list of dependency objects used to build the hash.\n\n Raises:\n Exception: If a multiple files try to provide the same namepace.\n\n Returns:\n A hash table { namespace: dependency } that can be used to resolve a\n dependency by a namespace it provides.\n \"\"\"\n dep_hash = {}\n for dep in deps:\n for provide in dep.provides:\n if provide in dep_hash:\n raise Exception('Duplicate provide (%s) in (%s, %s)' % (\n provide,\n dep_hash[provide].filename,\n dep.filename))\n dep_hash[provide] = dep\n return dep_hash","function_tokens":["def","BuildDependencyHashFromDependencies","(","deps",")",":","dep_hash","=","{","}","for","dep","in","deps",":","for","provide","in","dep",".","provides",":","if","provide","in","dep_hash",":","raise","Exception","(","'Duplicate provide (%s) in (%s, %s)'","%","(","provide",",","dep_hash","[","provide","]",".","filename",",","dep",".","filename",")",")","dep_hash","[","provide","]","=","dep","return","dep_hash"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/calcdeps.py#L171-L198"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/calcdeps.py","language":"python","identifier":"CalculateDependencies","parameters":"(paths, inputs)","argument_list":"","return_statement":"return result_list","docstring":"Calculates the dependencies for given inputs.\n\n Description:\n This method takes a list of paths (files, directories) and builds a\n searchable data structure based on the namespaces that each .js file\n provides. It then parses through each input, resolving dependencies\n against this data structure. The final output is a list of files,\n including the inputs, that represent all of the code that is needed to\n compile the given inputs.\n\n Args:\n paths: the references (files, directories) that are used to build the\n dependency hash.\n inputs: the inputs (files, directories, namespaces) that have dependencies\n that need to be calculated.\n\n Raises:\n Exception: if a provided input is invalid.\n\n Returns:\n A list of all files, including inputs, that are needed to compile the given\n inputs.","docstring_summary":"Calculates the dependencies for given inputs.","docstring_tokens":["Calculates","the","dependencies","for","given","inputs","."],"function":"def CalculateDependencies(paths, inputs):\n \"\"\"Calculates the dependencies for given inputs.\n\n Description:\n This method takes a list of paths (files, directories) and builds a\n searchable data structure based on the namespaces that each .js file\n provides. It then parses through each input, resolving dependencies\n against this data structure. The final output is a list of files,\n including the inputs, that represent all of the code that is needed to\n compile the given inputs.\n\n Args:\n paths: the references (files, directories) that are used to build the\n dependency hash.\n inputs: the inputs (files, directories, namespaces) that have dependencies\n that need to be calculated.\n\n Raises:\n Exception: if a provided input is invalid.\n\n Returns:\n A list of all files, including inputs, that are needed to compile the given\n inputs.\n \"\"\"\n deps = BuildDependenciesFromFiles(paths + inputs)\n search_hash = BuildDependencyHashFromDependencies(deps)\n result_list = []\n seen_list = []\n for input_file in inputs:\n if IsNamespace(input_file):\n namespace = re.search(ns_regex, input_file).group(1)\n if namespace not in search_hash:\n raise Exception('Invalid namespace (%s)' % namespace)\n input_file = search_hash[namespace].filename\n if not IsValidFile(input_file) or not IsJsFile(input_file):\n raise Exception('Invalid file (%s)' % input_file)\n seen_list.append(input_file)\n file_handle = open(input_file, 'r')\n try:\n for line in file_handle:\n if re.match(req_regex, line):\n require = re.search(req_regex, line).group(1)\n ResolveDependencies(require, search_hash, result_list, seen_list)\n finally:\n file_handle.close()\n result_list.append(input_file)\n\n # All files depend on base.js, so put it first.\n base_js_path = FindClosureBasePath(paths)\n if base_js_path:\n result_list.insert(0, base_js_path)\n else:\n logging.warning('Closure Library base.js not found.')\n\n return result_list","function_tokens":["def","CalculateDependencies","(","paths",",","inputs",")",":","deps","=","BuildDependenciesFromFiles","(","paths","+","inputs",")","search_hash","=","BuildDependencyHashFromDependencies","(","deps",")","result_list","=","[","]","seen_list","=","[","]","for","input_file","in","inputs",":","if","IsNamespace","(","input_file",")",":","namespace","=","re",".","search","(","ns_regex",",","input_file",")",".","group","(","1",")","if","namespace","not","in","search_hash",":","raise","Exception","(","'Invalid namespace (%s)'","%","namespace",")","input_file","=","search_hash","[","namespace","]",".","filename","if","not","IsValidFile","(","input_file",")","or","not","IsJsFile","(","input_file",")",":","raise","Exception","(","'Invalid file (%s)'","%","input_file",")","seen_list",".","append","(","input_file",")","file_handle","=","open","(","input_file",",","'r'",")","try",":","for","line","in","file_handle",":","if","re",".","match","(","req_regex",",","line",")",":","require","=","re",".","search","(","req_regex",",","line",")",".","group","(","1",")","ResolveDependencies","(","require",",","search_hash",",","result_list",",","seen_list",")","finally",":","file_handle",".","close","(",")","result_list",".","append","(","input_file",")","# All files depend on base.js, so put it first.","base_js_path","=","FindClosureBasePath","(","paths",")","if","base_js_path",":","result_list",".","insert","(","0",",","base_js_path",")","else",":","logging",".","warning","(","'Closure Library base.js not found.'",")","return","result_list"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/calcdeps.py#L201-L255"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/calcdeps.py","language":"python","identifier":"FindClosureBasePath","parameters":"(paths)","argument_list":"","return_statement":"","docstring":"Given a list of file paths, return Closure base.js path, if any.\n\n Args:\n paths: A list of paths.\n\n Returns:\n The path to Closure's base.js file including filename, if found.","docstring_summary":"Given a list of file paths, return Closure base.js path, if any.","docstring_tokens":["Given","a","list","of","file","paths","return","Closure","base",".","js","path","if","any","."],"function":"def FindClosureBasePath(paths):\n \"\"\"Given a list of file paths, return Closure base.js path, if any.\n\n Args:\n paths: A list of paths.\n\n Returns:\n The path to Closure's base.js file including filename, if found.\n \"\"\"\n\n for path in paths:\n pathname, filename = os.path.split(path)\n\n if filename == 'base.js':\n f = open(path)\n\n is_base = False\n\n # Sanity check that this is the Closure base file. Check that this\n # is where goog is defined. This is determined by the @provideGoog\n # flag.\n for line in f:\n if '@provideGoog' in line:\n is_base = True\n break\n\n f.close()\n\n if is_base:\n return path","function_tokens":["def","FindClosureBasePath","(","paths",")",":","for","path","in","paths",":","pathname",",","filename","=","os",".","path",".","split","(","path",")","if","filename","==","'base.js'",":","f","=","open","(","path",")","is_base","=","False","# Sanity check that this is the Closure base file. Check that this","# is where goog is defined. This is determined by the @provideGoog","# flag.","for","line","in","f",":","if","'@provideGoog'","in","line",":","is_base","=","True","break","f",".","close","(",")","if","is_base",":","return","path"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/calcdeps.py#L258-L287"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/calcdeps.py","language":"python","identifier":"ResolveDependencies","parameters":"(require, search_hash, result_list, seen_list)","argument_list":"","return_statement":"","docstring":"Takes a given requirement and resolves all of the dependencies for it.\n\n Description:\n A given requirement may require other dependencies. This method\n recursively resolves all dependencies for the given requirement.\n\n Raises:\n Exception: when require does not exist in the search_hash.\n\n Args:\n require: the namespace to resolve dependencies for.\n search_hash: the data structure used for resolving dependencies.\n result_list: a list of filenames that have been calculated as dependencies.\n This variable is the output for this function.\n seen_list: a list of filenames that have been 'seen'. This is required\n for the dependency->dependant ordering.","docstring_summary":"Takes a given requirement and resolves all of the dependencies for it.","docstring_tokens":["Takes","a","given","requirement","and","resolves","all","of","the","dependencies","for","it","."],"function":"def ResolveDependencies(require, search_hash, result_list, seen_list):\n \"\"\"Takes a given requirement and resolves all of the dependencies for it.\n\n Description:\n A given requirement may require other dependencies. This method\n recursively resolves all dependencies for the given requirement.\n\n Raises:\n Exception: when require does not exist in the search_hash.\n\n Args:\n require: the namespace to resolve dependencies for.\n search_hash: the data structure used for resolving dependencies.\n result_list: a list of filenames that have been calculated as dependencies.\n This variable is the output for this function.\n seen_list: a list of filenames that have been 'seen'. This is required\n for the dependency->dependant ordering.\n \"\"\"\n if require not in search_hash:\n raise Exception('Missing provider for (%s)' % require)\n\n dep = search_hash[require]\n if not dep.filename in seen_list:\n seen_list.append(dep.filename)\n for sub_require in dep.requires:\n ResolveDependencies(sub_require, search_hash, result_list, seen_list)\n result_list.append(dep.filename)","function_tokens":["def","ResolveDependencies","(","require",",","search_hash",",","result_list",",","seen_list",")",":","if","require","not","in","search_hash",":","raise","Exception","(","'Missing provider for (%s)'","%","require",")","dep","=","search_hash","[","require","]","if","not","dep",".","filename","in","seen_list",":","seen_list",".","append","(","dep",".","filename",")","for","sub_require","in","dep",".","requires",":","ResolveDependencies","(","sub_require",",","search_hash",",","result_list",",","seen_list",")","result_list",".","append","(","dep",".","filename",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/calcdeps.py#L289-L315"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/calcdeps.py","language":"python","identifier":"GetDepsLine","parameters":"(dep, base_path)","argument_list":"","return_statement":"return 'goog.addDependency(\"%s\", %s, %s);' % (\n GetRelpath(dep.filename, base_path), dep.provides, dep.requires)","docstring":"Returns a JS string for a dependency statement in the deps.js file.\n\n Args:\n dep: The dependency that we're printing.\n base_path: The path to Closure's base.js including filename.","docstring_summary":"Returns a JS string for a dependency statement in the deps.js file.","docstring_tokens":["Returns","a","JS","string","for","a","dependency","statement","in","the","deps",".","js","file","."],"function":"def GetDepsLine(dep, base_path):\n \"\"\"Returns a JS string for a dependency statement in the deps.js file.\n\n Args:\n dep: The dependency that we're printing.\n base_path: The path to Closure's base.js including filename.\n \"\"\"\n return 'goog.addDependency(\"%s\", %s, %s);' % (\n GetRelpath(dep.filename, base_path), dep.provides, dep.requires)","function_tokens":["def","GetDepsLine","(","dep",",","base_path",")",":","return","'goog.addDependency(\"%s\", %s, %s);'","%","(","GetRelpath","(","dep",".","filename",",","base_path",")",",","dep",".","provides",",","dep",".","requires",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/calcdeps.py#L318-L326"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/calcdeps.py","language":"python","identifier":"GetRelpath","parameters":"(path, start)","argument_list":"","return_statement":"return '\/'.join(['..'] * (len(start_list) - common_prefix_count) +\n path_list[common_prefix_count:])","docstring":"Return a relative path to |path| from |start|.","docstring_summary":"Return a relative path to |path| from |start|.","docstring_tokens":["Return","a","relative","path","to","|path|","from","|start|","."],"function":"def GetRelpath(path, start):\n \"\"\"Return a relative path to |path| from |start|.\"\"\"\n # NOTE: Python 2.6 provides os.path.relpath, which has almost the same\n # functionality as this function. Since we want to support 2.4, we have\n # to implement it manually. :(\n path_list = os.path.abspath(os.path.normpath(path)).split(os.sep)\n start_list = os.path.abspath(\n os.path.normpath(os.path.dirname(start))).split(os.sep)\n\n common_prefix_count = 0\n for i in range(0, min(len(path_list), len(start_list))):\n if path_list[i] != start_list[i]:\n break\n common_prefix_count += 1\n\n # Always use forward slashes, because this will get expanded to a url,\n # not a file path.\n return '\/'.join(['..'] * (len(start_list) - common_prefix_count) +\n path_list[common_prefix_count:])","function_tokens":["def","GetRelpath","(","path",",","start",")",":","# NOTE: Python 2.6 provides os.path.relpath, which has almost the same","# functionality as this function. Since we want to support 2.4, we have","# to implement it manually. :(","path_list","=","os",".","path",".","abspath","(","os",".","path",".","normpath","(","path",")",")",".","split","(","os",".","sep",")","start_list","=","os",".","path",".","abspath","(","os",".","path",".","normpath","(","os",".","path",".","dirname","(","start",")",")",")",".","split","(","os",".","sep",")","common_prefix_count","=","0","for","i","in","range","(","0",",","min","(","len","(","path_list",")",",","len","(","start_list",")",")",")",":","if","path_list","[","i","]","!=","start_list","[","i","]",":","break","common_prefix_count","+=","1","# Always use forward slashes, because this will get expanded to a url,","# not a file path.","return","'\/'",".","join","(","[","'..'","]","*","(","len","(","start_list",")","-","common_prefix_count",")","+","path_list","[","common_prefix_count",":","]",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/calcdeps.py#L329-L347"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/calcdeps.py","language":"python","identifier":"PrintDeps","parameters":"(source_paths, deps, out)","argument_list":"","return_statement":"return True","docstring":"Print out a deps.js file from a list of source paths.\n\n Args:\n source_paths: Paths that we should generate dependency info for.\n deps: Paths that provide dependency info. Their dependency info should\n not appear in the deps file.\n out: The output file.\n\n Returns:\n True on success, false if it was unable to find the base path\n to generate deps relative to.","docstring_summary":"Print out a deps.js file from a list of source paths.","docstring_tokens":["Print","out","a","deps",".","js","file","from","a","list","of","source","paths","."],"function":"def PrintDeps(source_paths, deps, out):\n \"\"\"Print out a deps.js file from a list of source paths.\n\n Args:\n source_paths: Paths that we should generate dependency info for.\n deps: Paths that provide dependency info. Their dependency info should\n not appear in the deps file.\n out: The output file.\n\n Returns:\n True on success, false if it was unable to find the base path\n to generate deps relative to.\n \"\"\"\n base_path = FindClosureBasePath(source_paths + deps)\n if not base_path:\n return False\n\n PrintLine('\/\/ This file was autogenerated by calcdeps.py', out)\n excludesSet = set(deps)\n\n for dep in BuildDependenciesFromFiles(source_paths + deps):\n if not dep.filename in excludesSet:\n PrintLine(GetDepsLine(dep, base_path), out)\n\n return True","function_tokens":["def","PrintDeps","(","source_paths",",","deps",",","out",")",":","base_path","=","FindClosureBasePath","(","source_paths","+","deps",")","if","not","base_path",":","return","False","PrintLine","(","'\/\/ This file was autogenerated by calcdeps.py'",",","out",")","excludesSet","=","set","(","deps",")","for","dep","in","BuildDependenciesFromFiles","(","source_paths","+","deps",")",":","if","not","dep",".","filename","in","excludesSet",":","PrintLine","(","GetDepsLine","(","dep",",","base_path",")",",","out",")","return","True"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/calcdeps.py#L355-L379"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/calcdeps.py","language":"python","identifier":"GetJavaVersion","parameters":"()","argument_list":"","return_statement":"return version_regex.search(version_line).group()","docstring":"Returns the string for the current version of Java installed.","docstring_summary":"Returns the string for the current version of Java installed.","docstring_tokens":["Returns","the","string","for","the","current","version","of","Java","installed","."],"function":"def GetJavaVersion():\n \"\"\"Returns the string for the current version of Java installed.\"\"\"\n proc = subprocess.Popen(['java', '-version'], stderr=subprocess.PIPE)\n proc.wait()\n version_line = proc.stderr.read().splitlines()[0]\n return version_regex.search(version_line).group()","function_tokens":["def","GetJavaVersion","(",")",":","proc","=","subprocess",".","Popen","(","[","'java'",",","'-version'","]",",","stderr","=","subprocess",".","PIPE",")","proc",".","wait","(",")","version_line","=","proc",".","stderr",".","read","(",")",".","splitlines","(",")","[","0","]","return","version_regex",".","search","(","version_line",")",".","group","(",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/calcdeps.py#L390-L395"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/calcdeps.py","language":"python","identifier":"FilterByExcludes","parameters":"(options, files)","argument_list":"","return_statement":"return [i for i in files if not i in excludesSet]","docstring":"Filters the given files by the exlusions specified at the command line.\n\n Args:\n options: The flags to calcdeps.\n files: The files to filter.\n Returns:\n A list of files.","docstring_summary":"Filters the given files by the exlusions specified at the command line.","docstring_tokens":["Filters","the","given","files","by","the","exlusions","specified","at","the","command","line","."],"function":"def FilterByExcludes(options, files):\n \"\"\"Filters the given files by the exlusions specified at the command line.\n\n Args:\n options: The flags to calcdeps.\n files: The files to filter.\n Returns:\n A list of files.\n \"\"\"\n excludes = []\n if options.excludes:\n excludes = ExpandDirectories(options.excludes)\n\n excludesSet = set(excludes)\n return [i for i in files if not i in excludesSet]","function_tokens":["def","FilterByExcludes","(","options",",","files",")",":","excludes","=","[","]","if","options",".","excludes",":","excludes","=","ExpandDirectories","(","options",".","excludes",")","excludesSet","=","set","(","excludes",")","return","[","i","for","i","in","files","if","not","i","in","excludesSet","]"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/calcdeps.py#L398-L412"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/calcdeps.py","language":"python","identifier":"GetPathsFromOptions","parameters":"(options)","argument_list":"","return_statement":"return FilterByExcludes(options, search_paths)","docstring":"Generates the path files from flag options.\n\n Args:\n options: The flags to calcdeps.\n Returns:\n A list of files in the specified paths. (strings).","docstring_summary":"Generates the path files from flag options.","docstring_tokens":["Generates","the","path","files","from","flag","options","."],"function":"def GetPathsFromOptions(options):\n \"\"\"Generates the path files from flag options.\n\n Args:\n options: The flags to calcdeps.\n Returns:\n A list of files in the specified paths. (strings).\n \"\"\"\n\n search_paths = options.paths\n if not search_paths:\n search_paths = ['.'] # Add default folder if no path is specified.\n\n search_paths = ExpandDirectories(search_paths)\n return FilterByExcludes(options, search_paths)","function_tokens":["def","GetPathsFromOptions","(","options",")",":","search_paths","=","options",".","paths","if","not","search_paths",":","search_paths","=","[","'.'","]","# Add default folder if no path is specified.","search_paths","=","ExpandDirectories","(","search_paths",")","return","FilterByExcludes","(","options",",","search_paths",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/calcdeps.py#L415-L429"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/calcdeps.py","language":"python","identifier":"GetInputsFromOptions","parameters":"(options)","argument_list":"","return_statement":"return FilterByExcludes(options, inputs)","docstring":"Generates the inputs from flag options.\n\n Args:\n options: The flags to calcdeps.\n Returns:\n A list of inputs (strings).","docstring_summary":"Generates the inputs from flag options.","docstring_tokens":["Generates","the","inputs","from","flag","options","."],"function":"def GetInputsFromOptions(options):\n \"\"\"Generates the inputs from flag options.\n\n Args:\n options: The flags to calcdeps.\n Returns:\n A list of inputs (strings).\n \"\"\"\n inputs = options.inputs\n if not inputs: # Parse stdin\n logging.info('No inputs specified. Reading from stdin...')\n inputs = filter(None, [line.strip('\\n') for line in sys.stdin.readlines()])\n\n logging.info('Scanning files...')\n inputs = ExpandDirectories(inputs)\n\n return FilterByExcludes(options, inputs)","function_tokens":["def","GetInputsFromOptions","(","options",")",":","inputs","=","options",".","inputs","if","not","inputs",":","# Parse stdin","logging",".","info","(","'No inputs specified. Reading from stdin...'",")","inputs","=","filter","(","None",",","[","line",".","strip","(","'\\n'",")","for","line","in","sys",".","stdin",".","readlines","(",")","]",")","logging",".","info","(","'Scanning files...'",")","inputs","=","ExpandDirectories","(","inputs",")","return","FilterByExcludes","(","options",",","inputs",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/calcdeps.py#L432-L448"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/calcdeps.py","language":"python","identifier":"Compile","parameters":"(compiler_jar_path, source_paths, out, flags=None)","argument_list":"","return_statement":"","docstring":"Prepares command-line call to Closure compiler.\n\n Args:\n compiler_jar_path: Path to the Closure compiler .jar file.\n source_paths: Source paths to build, in order.\n flags: A list of additional flags to pass on to Closure compiler.","docstring_summary":"Prepares command-line call to Closure compiler.","docstring_tokens":["Prepares","command","-","line","call","to","Closure","compiler","."],"function":"def Compile(compiler_jar_path, source_paths, out, flags=None):\n \"\"\"Prepares command-line call to Closure compiler.\n\n Args:\n compiler_jar_path: Path to the Closure compiler .jar file.\n source_paths: Source paths to build, in order.\n flags: A list of additional flags to pass on to Closure compiler.\n \"\"\"\n args = ['java', '-jar', compiler_jar_path]\n for path in source_paths:\n args += ['--js', path]\n\n if flags:\n args += flags\n\n logging.info('Compiling with the following command: %s', ' '.join(args))\n proc = subprocess.Popen(args, stdout=subprocess.PIPE)\n (stdoutdata, stderrdata) = proc.communicate()\n if proc.returncode != 0:\n logging.error('JavaScript compilation failed.')\n sys.exit(1)\n else:\n out.write(stdoutdata)","function_tokens":["def","Compile","(","compiler_jar_path",",","source_paths",",","out",",","flags","=","None",")",":","args","=","[","'java'",",","'-jar'",",","compiler_jar_path","]","for","path","in","source_paths",":","args","+=","[","'--js'",",","path","]","if","flags",":","args","+=","flags","logging",".","info","(","'Compiling with the following command: %s'",",","' '",".","join","(","args",")",")","proc","=","subprocess",".","Popen","(","args",",","stdout","=","subprocess",".","PIPE",")","(","stdoutdata",",","stderrdata",")","=","proc",".","communicate","(",")","if","proc",".","returncode","!=","0",":","logging",".","error","(","'JavaScript compilation failed.'",")","sys",".","exit","(","1",")","else",":","out",".","write","(","stdoutdata",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/calcdeps.py#L451-L473"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/calcdeps.py","language":"python","identifier":"main","parameters":"()","argument_list":"","return_statement":"","docstring":"The entrypoint for this script.","docstring_summary":"The entrypoint for this script.","docstring_tokens":["The","entrypoint","for","this","script","."],"function":"def main():\n \"\"\"The entrypoint for this script.\"\"\"\n\n logging.basicConfig(format='calcdeps.py: %(message)s', level=logging.INFO)\n\n usage = 'usage: %prog [options] arg'\n parser = optparse.OptionParser(usage)\n parser.add_option('-i',\n '--input',\n dest='inputs',\n action='append',\n help='The inputs to calculate dependencies for. Valid '\n 'values can be files, directories, or namespaces '\n '(ns:goog.net.XhrIo). Only relevant to \"list\" and '\n '\"script\" output.')\n parser.add_option('-p',\n '--path',\n dest='paths',\n action='append',\n help='The paths that should be traversed to build the '\n 'dependencies.')\n parser.add_option('-d',\n '--dep',\n dest='deps',\n action='append',\n help='Directories or files that should be traversed to '\n 'find required dependencies for the deps file. '\n 'Does not generate dependency information for names '\n 'provided by these files. Only useful in \"deps\" mode.')\n parser.add_option('-e',\n '--exclude',\n dest='excludes',\n action='append',\n help='Files or directories to exclude from the --path '\n 'and --input flags')\n parser.add_option('-o',\n '--output_mode',\n dest='output_mode',\n action='store',\n default='list',\n help='The type of output to generate from this script. '\n 'Options are \"list\" for a list of filenames, \"script\" '\n 'for a single script containing the contents of all the '\n 'file, \"deps\" to generate a deps.js file for all '\n 'paths, or \"compiled\" to produce compiled output with '\n 'the Closure compiler.')\n parser.add_option('-c',\n '--compiler_jar',\n dest='compiler_jar',\n action='store',\n help='The location of the Closure compiler .jar file.')\n parser.add_option('-f',\n '--compiler_flag',\n '--compiler_flags', # for backwards compatability\n dest='compiler_flags',\n action='append',\n help='Additional flag to pass to the Closure compiler. '\n 'May be specified multiple times to pass multiple flags.')\n parser.add_option('--output_file',\n dest='output_file',\n action='store',\n help=('If specified, write output to this path instead of '\n 'writing to standard output.'))\n\n (options, args) = parser.parse_args()\n\n search_paths = GetPathsFromOptions(options)\n\n if options.output_file:\n out = open(options.output_file, 'w')\n else:\n out = sys.stdout\n\n if options.output_mode == 'deps':\n result = PrintDeps(search_paths, ExpandDirectories(options.deps or []), out)\n if not result:\n logging.error('Could not find Closure Library in the specified paths')\n sys.exit(1)\n\n return\n\n inputs = GetInputsFromOptions(options)\n\n logging.info('Finding Closure dependencies...')\n deps = CalculateDependencies(search_paths, inputs)\n output_mode = options.output_mode\n\n if output_mode == 'script':\n PrintScript(deps, out)\n elif output_mode == 'list':\n # Just print out a dep per line\n for dep in deps:\n PrintLine(dep, out)\n elif output_mode == 'compiled':\n # Make sure a .jar is specified.\n if not options.compiler_jar:\n logging.error('--compiler_jar flag must be specified if --output is '\n '\"compiled\"')\n sys.exit(1)\n\n # User friendly version check.\n if distutils and not (distutils.version.LooseVersion(GetJavaVersion()) >\n distutils.version.LooseVersion('1.6')):\n logging.error('Closure Compiler requires Java 1.6 or higher.')\n logging.error('Please visit http:\/\/www.java.com\/getjava')\n sys.exit(1)\n\n Compile(options.compiler_jar, deps, out, options.compiler_flags)\n\n else:\n logging.error('Invalid value for --output flag.')\n sys.exit(1)","function_tokens":["def","main","(",")",":","logging",".","basicConfig","(","format","=","'calcdeps.py: %(message)s'",",","level","=","logging",".","INFO",")","usage","=","'usage: %prog [options] arg'","parser","=","optparse",".","OptionParser","(","usage",")","parser",".","add_option","(","'-i'",",","'--input'",",","dest","=","'inputs'",",","action","=","'append'",",","help","=","'The inputs to calculate dependencies for. Valid '","'values can be files, directories, or namespaces '","'(ns:goog.net.XhrIo). Only relevant to \"list\" and '","'\"script\" output.'",")","parser",".","add_option","(","'-p'",",","'--path'",",","dest","=","'paths'",",","action","=","'append'",",","help","=","'The paths that should be traversed to build the '","'dependencies.'",")","parser",".","add_option","(","'-d'",",","'--dep'",",","dest","=","'deps'",",","action","=","'append'",",","help","=","'Directories or files that should be traversed to '","'find required dependencies for the deps file. '","'Does not generate dependency information for names '","'provided by these files. Only useful in \"deps\" mode.'",")","parser",".","add_option","(","'-e'",",","'--exclude'",",","dest","=","'excludes'",",","action","=","'append'",",","help","=","'Files or directories to exclude from the --path '","'and --input flags'",")","parser",".","add_option","(","'-o'",",","'--output_mode'",",","dest","=","'output_mode'",",","action","=","'store'",",","default","=","'list'",",","help","=","'The type of output to generate from this script. '","'Options are \"list\" for a list of filenames, \"script\" '","'for a single script containing the contents of all the '","'file, \"deps\" to generate a deps.js file for all '","'paths, or \"compiled\" to produce compiled output with '","'the Closure compiler.'",")","parser",".","add_option","(","'-c'",",","'--compiler_jar'",",","dest","=","'compiler_jar'",",","action","=","'store'",",","help","=","'The location of the Closure compiler .jar file.'",")","parser",".","add_option","(","'-f'",",","'--compiler_flag'",",","'--compiler_flags'",",","# for backwards compatability","dest","=","'compiler_flags'",",","action","=","'append'",",","help","=","'Additional flag to pass to the Closure compiler. '","'May be specified multiple times to pass multiple flags.'",")","parser",".","add_option","(","'--output_file'",",","dest","=","'output_file'",",","action","=","'store'",",","help","=","(","'If specified, write output to this path instead of '","'writing to standard output.'",")",")","(","options",",","args",")","=","parser",".","parse_args","(",")","search_paths","=","GetPathsFromOptions","(","options",")","if","options",".","output_file",":","out","=","open","(","options",".","output_file",",","'w'",")","else",":","out","=","sys",".","stdout","if","options",".","output_mode","==","'deps'",":","result","=","PrintDeps","(","search_paths",",","ExpandDirectories","(","options",".","deps","or","[","]",")",",","out",")","if","not","result",":","logging",".","error","(","'Could not find Closure Library in the specified paths'",")","sys",".","exit","(","1",")","return","inputs","=","GetInputsFromOptions","(","options",")","logging",".","info","(","'Finding Closure dependencies...'",")","deps","=","CalculateDependencies","(","search_paths",",","inputs",")","output_mode","=","options",".","output_mode","if","output_mode","==","'script'",":","PrintScript","(","deps",",","out",")","elif","output_mode","==","'list'",":","# Just print out a dep per line","for","dep","in","deps",":","PrintLine","(","dep",",","out",")","elif","output_mode","==","'compiled'",":","# Make sure a .jar is specified.","if","not","options",".","compiler_jar",":","logging",".","error","(","'--compiler_jar flag must be specified if --output is '","'\"compiled\"'",")","sys",".","exit","(","1",")","# User friendly version check.","if","distutils","and","not","(","distutils",".","version",".","LooseVersion","(","GetJavaVersion","(",")",")",">","distutils",".","version",".","LooseVersion","(","'1.6'",")",")",":","logging",".","error","(","'Closure Compiler requires Java 1.6 or higher.'",")","logging",".","error","(","'Please visit http:\/\/www.java.com\/getjava'",")","sys",".","exit","(","1",")","Compile","(","options",".","compiler_jar",",","deps",",","out",",","options",".","compiler_flags",")","else",":","logging",".","error","(","'Invalid value for --output flag.'",")","sys",".","exit","(","1",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/calcdeps.py#L476-L587"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/labs\/code\/generate_jsdoc.py","language":"python","identifier":"_MatchFirstFunction","parameters":"(script)","argument_list":"","return_statement":"return _FUNCTION_REGEX.search(script)","docstring":"Match the first function seen in the script.","docstring_summary":"Match the first function seen in the script.","docstring_tokens":["Match","the","first","function","seen","in","the","script","."],"function":"def _MatchFirstFunction(script):\n \"\"\"Match the first function seen in the script.\"\"\"\n return _FUNCTION_REGEX.search(script)","function_tokens":["def","_MatchFirstFunction","(","script",")",":","return","_FUNCTION_REGEX",".","search","(","script",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/labs\/code\/generate_jsdoc.py#L58-L60"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/labs\/code\/generate_jsdoc.py","language":"python","identifier":"_ParseArgString","parameters":"(arg_string)","argument_list":"","return_statement":"","docstring":"Parse an argument string (inside parens) into parameter names.","docstring_summary":"Parse an argument string (inside parens) into parameter names.","docstring_tokens":["Parse","an","argument","string","(","inside","parens",")","into","parameter","names","."],"function":"def _ParseArgString(arg_string):\n \"\"\"Parse an argument string (inside parens) into parameter names.\"\"\"\n for arg in arg_string.split(','):\n arg = arg.strip()\n if arg:\n yield arg","function_tokens":["def","_ParseArgString","(","arg_string",")",":","for","arg","in","arg_string",".","split","(","','",")",":","arg","=","arg",".","strip","(",")","if","arg",":","yield","arg"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/labs\/code\/generate_jsdoc.py#L63-L68"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/labs\/code\/generate_jsdoc.py","language":"python","identifier":"_ExtractFunctionBody","parameters":"(script, indentation=0)","argument_list":"","return_statement":"","docstring":"Attempt to return the function body.","docstring_summary":"Attempt to return the function body.","docstring_tokens":["Attempt","to","return","the","function","body","."],"function":"def _ExtractFunctionBody(script, indentation=0):\n \"\"\"Attempt to return the function body.\"\"\"\n\n # Real extraction would require a token parser and state machines.\n # We look for first bracket at the same level of indentation.\n regex_str = r'{(.*?)^[ ]{%d}}' % indentation\n\n function_regex = re.compile(regex_str, re.MULTILINE | re.DOTALL)\n match = function_regex.search(script)\n if match:\n return match.group(1)","function_tokens":["def","_ExtractFunctionBody","(","script",",","indentation","=","0",")",":","# Real extraction would require a token parser and state machines.","# We look for first bracket at the same level of indentation.","regex_str","=","r'{(.*?)^[ ]{%d}}'","%","indentation","function_regex","=","re",".","compile","(","regex_str",",","re",".","MULTILINE","|","re",".","DOTALL",")","match","=","function_regex",".","search","(","script",")","if","match",":","return","match",".","group","(","1",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/labs\/code\/generate_jsdoc.py#L71-L81"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/labs\/code\/generate_jsdoc.py","language":"python","identifier":"_ContainsReturnValue","parameters":"(function_body)","argument_list":"","return_statement":"return bool(return_regex.search(function_body))","docstring":"Attempt to determine if the function body returns a value.","docstring_summary":"Attempt to determine if the function body returns a value.","docstring_tokens":["Attempt","to","determine","if","the","function","body","returns","a","value","."],"function":"def _ContainsReturnValue(function_body):\n \"\"\"Attempt to determine if the function body returns a value.\"\"\"\n return_regex = re.compile(r'\\breturn\\b[^;]')\n\n # If this matches, we assume they're returning something.\n return bool(return_regex.search(function_body))","function_tokens":["def","_ContainsReturnValue","(","function_body",")",":","return_regex","=","re",".","compile","(","r'\\breturn\\b[^;]'",")","# If this matches, we assume they're returning something.","return","bool","(","return_regex",".","search","(","function_body",")",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/labs\/code\/generate_jsdoc.py#L84-L89"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/labs\/code\/generate_jsdoc.py","language":"python","identifier":"_InsertString","parameters":"(original_string, inserted_string, index)","argument_list":"","return_statement":"return original_string[0:index] + inserted_string + original_string[index:]","docstring":"Insert a string into another string at a given index.","docstring_summary":"Insert a string into another string at a given index.","docstring_tokens":["Insert","a","string","into","another","string","at","a","given","index","."],"function":"def _InsertString(original_string, inserted_string, index):\n \"\"\"Insert a string into another string at a given index.\"\"\"\n return original_string[0:index] + inserted_string + original_string[index:]","function_tokens":["def","_InsertString","(","original_string",",","inserted_string",",","index",")",":","return","original_string","[","0",":","index","]","+","inserted_string","+","original_string","[","index",":","]"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/labs\/code\/generate_jsdoc.py#L92-L94"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/labs\/code\/generate_jsdoc.py","language":"python","identifier":"_GenerateJsDoc","parameters":"(args, return_val=False)","argument_list":"","return_statement":"return '\\n'.join(lines) + '\\n'","docstring":"Generate JSDoc for a function.\n\n Args:\n args: A list of names of the argument.\n return_val: Whether the function has a return value.\n\n Returns:\n The JSDoc as a string.","docstring_summary":"Generate JSDoc for a function.","docstring_tokens":["Generate","JSDoc","for","a","function","."],"function":"def _GenerateJsDoc(args, return_val=False):\n \"\"\"Generate JSDoc for a function.\n\n Args:\n args: A list of names of the argument.\n return_val: Whether the function has a return value.\n\n Returns:\n The JSDoc as a string.\n \"\"\"\n\n lines = []\n lines.append('\/**')\n\n lines += [' * @param {} %s' % arg for arg in args]\n\n if return_val:\n lines.append(' * @return')\n\n lines.append(' *\/')\n\n return '\\n'.join(lines) + '\\n'","function_tokens":["def","_GenerateJsDoc","(","args",",","return_val","=","False",")",":","lines","=","[","]","lines",".","append","(","'\/**'",")","lines","+=","[","' * @param {} %s'","%","arg","for","arg","in","args","]","if","return_val",":","lines",".","append","(","' * @return'",")","lines",".","append","(","' *\/'",")","return","'\\n'",".","join","(","lines",")","+","'\\n'"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/labs\/code\/generate_jsdoc.py#L97-L118"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/labs\/code\/generate_jsdoc.py","language":"python","identifier":"_IndentString","parameters":"(source_string, indentation)","argument_list":"","return_statement":"return ''.join(lines)","docstring":"Indent string some number of characters.","docstring_summary":"Indent string some number of characters.","docstring_tokens":["Indent","string","some","number","of","characters","."],"function":"def _IndentString(source_string, indentation):\n \"\"\"Indent string some number of characters.\"\"\"\n lines = [(indentation * ' ') + line\n for line in source_string.splitlines(True)]\n return ''.join(lines)","function_tokens":["def","_IndentString","(","source_string",",","indentation",")",":","lines","=","[","(","indentation","*","' '",")","+","line","for","line","in","source_string",".","splitlines","(","True",")","]","return","''",".","join","(","lines",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/labs\/code\/generate_jsdoc.py#L121-L125"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/labs\/code\/generate_jsdoc.py","language":"python","identifier":"InsertJsDoc","parameters":"(script)","argument_list":"","return_statement":"return _InsertString(script, jsdoc, start_index)","docstring":"Attempt to insert JSDoc for the first seen function in the script.\n\n Args:\n script: The script, as a string.\n\n Returns:\n Returns the new string if function was found and JSDoc inserted. Otherwise\n returns None.","docstring_summary":"Attempt to insert JSDoc for the first seen function in the script.","docstring_tokens":["Attempt","to","insert","JSDoc","for","the","first","seen","function","in","the","script","."],"function":"def InsertJsDoc(script):\n \"\"\"Attempt to insert JSDoc for the first seen function in the script.\n\n Args:\n script: The script, as a string.\n\n Returns:\n Returns the new string if function was found and JSDoc inserted. Otherwise\n returns None.\n \"\"\"\n\n match = _MatchFirstFunction(script)\n if not match:\n return\n\n # Add argument flags.\n args_string = match.group('arguments')\n args = _ParseArgString(args_string)\n\n start_index = match.start(0)\n function_to_end = script[start_index:]\n\n lvalue_indentation = len(match.group('indentation'))\n\n return_val = False\n function_body = _ExtractFunctionBody(function_to_end, lvalue_indentation)\n if function_body:\n return_val = _ContainsReturnValue(function_body)\n\n jsdoc = _GenerateJsDoc(args, return_val)\n if lvalue_indentation:\n jsdoc = _IndentString(jsdoc, lvalue_indentation)\n\n return _InsertString(script, jsdoc, start_index)","function_tokens":["def","InsertJsDoc","(","script",")",":","match","=","_MatchFirstFunction","(","script",")","if","not","match",":","return","# Add argument flags.","args_string","=","match",".","group","(","'arguments'",")","args","=","_ParseArgString","(","args_string",")","start_index","=","match",".","start","(","0",")","function_to_end","=","script","[","start_index",":","]","lvalue_indentation","=","len","(","match",".","group","(","'indentation'",")",")","return_val","=","False","function_body","=","_ExtractFunctionBody","(","function_to_end",",","lvalue_indentation",")","if","function_body",":","return_val","=","_ContainsReturnValue","(","function_body",")","jsdoc","=","_GenerateJsDoc","(","args",",","return_val",")","if","lvalue_indentation",":","jsdoc","=","_IndentString","(","jsdoc",",","lvalue_indentation",")","return","_InsertString","(","script",",","jsdoc",",","start_index",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/labs\/code\/generate_jsdoc.py#L128-L161"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/build\/depstree.py","language":"python","identifier":"DepsTree.__init__","parameters":"(self, sources)","argument_list":"","return_statement":"","docstring":"Initializes the tree with a set of sources.\n\n Args:\n sources: A set of JavaScript sources.\n\n Raises:\n MultipleProvideError: A namespace is provided by muplitple sources.\n NamespaceNotFoundError: A namespace is required but never provided.","docstring_summary":"Initializes the tree with a set of sources.","docstring_tokens":["Initializes","the","tree","with","a","set","of","sources","."],"function":"def __init__(self, sources):\n \"\"\"Initializes the tree with a set of sources.\n\n Args:\n sources: A set of JavaScript sources.\n\n Raises:\n MultipleProvideError: A namespace is provided by muplitple sources.\n NamespaceNotFoundError: A namespace is required but never provided.\n \"\"\"\n\n self._sources = sources\n self._provides_map = dict()\n\n # Ensure nothing was provided twice.\n for source in sources:\n for provide in source.provides:\n if provide in self._provides_map:\n raise MultipleProvideError(\n provide, [self._provides_map[provide], source])\n\n self._provides_map[provide] = source\n\n # Check that all required namespaces are provided.\n for source in sources:\n for require in source.requires:\n if require not in self._provides_map:\n raise NamespaceNotFoundError(require, source)","function_tokens":["def","__init__","(","self",",","sources",")",":","self",".","_sources","=","sources","self",".","_provides_map","=","dict","(",")","# Ensure nothing was provided twice.","for","source","in","sources",":","for","provide","in","source",".","provides",":","if","provide","in","self",".","_provides_map",":","raise","MultipleProvideError","(","provide",",","[","self",".","_provides_map","[","provide","]",",","source","]",")","self",".","_provides_map","[","provide","]","=","source","# Check that all required namespaces are provided.","for","source","in","sources",":","for","require","in","source",".","requires",":","if","require","not","in","self",".","_provides_map",":","raise","NamespaceNotFoundError","(","require",",","source",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/build\/depstree.py#L29-L56"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/build\/depstree.py","language":"python","identifier":"DepsTree.GetDependencies","parameters":"(self, required_namespaces)","argument_list":"","return_statement":"return deps_sources","docstring":"Get source dependencies, in order, for the given namespaces.\n\n Args:\n required_namespaces: A string (for one) or list (for one or more) of\n namespaces.\n\n Returns:\n A list of source objects that provide those namespaces and all\n requirements, in dependency order.\n\n Raises:\n NamespaceNotFoundError: A namespace is requested but doesn't exist.\n CircularDependencyError: A cycle is detected in the dependency tree.","docstring_summary":"Get source dependencies, in order, for the given namespaces.","docstring_tokens":["Get","source","dependencies","in","order","for","the","given","namespaces","."],"function":"def GetDependencies(self, required_namespaces):\n \"\"\"Get source dependencies, in order, for the given namespaces.\n\n Args:\n required_namespaces: A string (for one) or list (for one or more) of\n namespaces.\n\n Returns:\n A list of source objects that provide those namespaces and all\n requirements, in dependency order.\n\n Raises:\n NamespaceNotFoundError: A namespace is requested but doesn't exist.\n CircularDependencyError: A cycle is detected in the dependency tree.\n \"\"\"\n if isinstance(required_namespaces, str):\n required_namespaces = [required_namespaces]\n\n deps_sources = []\n\n for namespace in required_namespaces:\n for source in DepsTree._ResolveDependencies(\n namespace, [], self._provides_map, []):\n if source not in deps_sources:\n deps_sources.append(source)\n\n return deps_sources","function_tokens":["def","GetDependencies","(","self",",","required_namespaces",")",":","if","isinstance","(","required_namespaces",",","str",")",":","required_namespaces","=","[","required_namespaces","]","deps_sources","=","[","]","for","namespace","in","required_namespaces",":","for","source","in","DepsTree",".","_ResolveDependencies","(","namespace",",","[","]",",","self",".","_provides_map",",","[","]",")",":","if","source","not","in","deps_sources",":","deps_sources",".","append","(","source",")","return","deps_sources"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/build\/depstree.py#L58-L84"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/build\/depstree.py","language":"python","identifier":"DepsTree._ResolveDependencies","parameters":"(required_namespace, deps_list, provides_map,\n traversal_path)","argument_list":"","return_statement":"return deps_list","docstring":"Resolve dependencies for Closure source files.\n\n Follows the dependency tree down and builds a list of sources in dependency\n order. This function will recursively call itself to fill all dependencies\n below the requested namespaces, and then append its sources at the end of\n the list.\n\n Args:\n required_namespace: String of required namespace.\n deps_list: List of sources in dependency order. This function will append\n the required source once all of its dependencies are satisfied.\n provides_map: Map from namespace to source that provides it.\n traversal_path: List of namespaces of our path from the root down the\n dependency\/recursion tree. Used to identify cyclical dependencies.\n This is a list used as a stack -- when the function is entered, the\n current namespace is pushed and popped right before returning.\n Each recursive call will check that the current namespace does not\n appear in the list, throwing a CircularDependencyError if it does.\n\n Returns:\n The given deps_list object filled with sources in dependency order.\n\n Raises:\n NamespaceNotFoundError: A namespace is requested but doesn't exist.\n CircularDependencyError: A cycle is detected in the dependency tree.","docstring_summary":"Resolve dependencies for Closure source files.","docstring_tokens":["Resolve","dependencies","for","Closure","source","files","."],"function":"def _ResolveDependencies(required_namespace, deps_list, provides_map,\n traversal_path):\n \"\"\"Resolve dependencies for Closure source files.\n\n Follows the dependency tree down and builds a list of sources in dependency\n order. This function will recursively call itself to fill all dependencies\n below the requested namespaces, and then append its sources at the end of\n the list.\n\n Args:\n required_namespace: String of required namespace.\n deps_list: List of sources in dependency order. This function will append\n the required source once all of its dependencies are satisfied.\n provides_map: Map from namespace to source that provides it.\n traversal_path: List of namespaces of our path from the root down the\n dependency\/recursion tree. Used to identify cyclical dependencies.\n This is a list used as a stack -- when the function is entered, the\n current namespace is pushed and popped right before returning.\n Each recursive call will check that the current namespace does not\n appear in the list, throwing a CircularDependencyError if it does.\n\n Returns:\n The given deps_list object filled with sources in dependency order.\n\n Raises:\n NamespaceNotFoundError: A namespace is requested but doesn't exist.\n CircularDependencyError: A cycle is detected in the dependency tree.\n \"\"\"\n\n source = provides_map.get(required_namespace)\n if not source:\n raise NamespaceNotFoundError(required_namespace)\n\n if required_namespace in traversal_path:\n traversal_path.append(required_namespace) # do this *after* the test\n\n # This must be a cycle.\n raise CircularDependencyError(traversal_path)\n\n # If we don't have the source yet, we'll have to visit this namespace and\n # add the required dependencies to deps_list.\n if source not in deps_list:\n traversal_path.append(required_namespace)\n\n for require in source.requires:\n\n # Append all other dependencies before we append our own.\n DepsTree._ResolveDependencies(require, deps_list, provides_map,\n traversal_path)\n deps_list.append(source)\n\n traversal_path.pop()\n\n return deps_list","function_tokens":["def","_ResolveDependencies","(","required_namespace",",","deps_list",",","provides_map",",","traversal_path",")",":","source","=","provides_map",".","get","(","required_namespace",")","if","not","source",":","raise","NamespaceNotFoundError","(","required_namespace",")","if","required_namespace","in","traversal_path",":","traversal_path",".","append","(","required_namespace",")","# do this *after* the test","# This must be a cycle.","raise","CircularDependencyError","(","traversal_path",")","# If we don't have the source yet, we'll have to visit this namespace and","# add the required dependencies to deps_list.","if","source","not","in","deps_list",":","traversal_path",".","append","(","required_namespace",")","for","require","in","source",".","requires",":","# Append all other dependencies before we append our own.","DepsTree",".","_ResolveDependencies","(","require",",","deps_list",",","provides_map",",","traversal_path",")","deps_list",".","append","(","source",")","traversal_path",".","pop","(",")","return","deps_list"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/build\/depstree.py#L87-L140"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/build\/jscompiler.py","language":"python","identifier":"_GetJavaVersionString","parameters":"()","argument_list":"","return_statement":"return subprocess.check_output(['java', '-version'], stderr=subprocess.STDOUT)","docstring":"Get the version string from the Java VM.","docstring_summary":"Get the version string from the Java VM.","docstring_tokens":["Get","the","version","string","from","the","Java","VM","."],"function":"def _GetJavaVersionString():\n \"\"\"Get the version string from the Java VM.\"\"\"\n return subprocess.check_output(['java', '-version'], stderr=subprocess.STDOUT)","function_tokens":["def","_GetJavaVersionString","(",")",":","return","subprocess",".","check_output","(","[","'java'",",","'-version'","]",",","stderr","=","subprocess",".","STDOUT",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/build\/jscompiler.py#L35-L37"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/build\/jscompiler.py","language":"python","identifier":"_ParseJavaVersion","parameters":"(version_string)","argument_list":"","return_statement":"","docstring":"Returns a 2-tuple for the current version of Java installed.\n\n Args:\n version_string: String of the Java version (e.g. '1.7.2-ea').\n\n Returns:\n The major and minor versions, as a 2-tuple (e.g. (1, 7)).","docstring_summary":"Returns a 2-tuple for the current version of Java installed.","docstring_tokens":["Returns","a","2","-","tuple","for","the","current","version","of","Java","installed","."],"function":"def _ParseJavaVersion(version_string):\n \"\"\"Returns a 2-tuple for the current version of Java installed.\n\n Args:\n version_string: String of the Java version (e.g. '1.7.2-ea').\n\n Returns:\n The major and minor versions, as a 2-tuple (e.g. (1, 7)).\n \"\"\"\n match = _VERSION_REGEX.search(version_string)\n if match:\n version = tuple(int(x, 10) for x in match.groups())\n assert len(version) == 2\n return version","function_tokens":["def","_ParseJavaVersion","(","version_string",")",":","match","=","_VERSION_REGEX",".","search","(","version_string",")","if","match",":","version","=","tuple","(","int","(","x",",","10",")","for","x","in","match",".","groups","(",")",")","assert","len","(","version",")","==","2","return","version"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/build\/jscompiler.py#L40-L53"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/build\/jscompiler.py","language":"python","identifier":"_JavaSupports32BitMode","parameters":"()","argument_list":"","return_statement":"return supported","docstring":"Determines whether the JVM supports 32-bit mode on the platform.","docstring_summary":"Determines whether the JVM supports 32-bit mode on the platform.","docstring_tokens":["Determines","whether","the","JVM","supports","32","-","bit","mode","on","the","platform","."],"function":"def _JavaSupports32BitMode():\n \"\"\"Determines whether the JVM supports 32-bit mode on the platform.\"\"\"\n # Suppresses process output to stderr and stdout from showing up in the\n # console as we're only trying to determine 32-bit JVM support.\n supported = False\n try:\n devnull = open(os.devnull, 'wb')\n return subprocess.call(\n ['java', '-d32', '-version'], stdout=devnull, stderr=devnull) == 0\n except IOError:\n pass\n else:\n devnull.close()\n return supported","function_tokens":["def","_JavaSupports32BitMode","(",")",":","# Suppresses process output to stderr and stdout from showing up in the","# console as we're only trying to determine 32-bit JVM support.","supported","=","False","try",":","devnull","=","open","(","os",".","devnull",",","'wb'",")","return","subprocess",".","call","(","[","'java'",",","'-d32'",",","'-version'","]",",","stdout","=","devnull",",","stderr","=","devnull",")","==","0","except","IOError",":","pass","else",":","devnull",".","close","(",")","return","supported"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/build\/jscompiler.py#L56-L69"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/build\/jscompiler.py","language":"python","identifier":"_GetJsCompilerArgs","parameters":"(compiler_jar_path, java_version, source_paths,\n jvm_flags, compiler_flags)","argument_list":"","return_statement":"return args","docstring":"Assembles arguments for call to JsCompiler.","docstring_summary":"Assembles arguments for call to JsCompiler.","docstring_tokens":["Assembles","arguments","for","call","to","JsCompiler","."],"function":"def _GetJsCompilerArgs(compiler_jar_path, java_version, source_paths,\n jvm_flags, compiler_flags):\n \"\"\"Assembles arguments for call to JsCompiler.\"\"\"\n\n if java_version < (1, 7):\n raise JsCompilerError('Closure Compiler requires Java 1.7 or higher. '\n 'Please visit http:\/\/www.java.com\/getjava')\n\n args = ['java']\n\n # Add JVM flags we believe will produce the best performance. See\n # https:\/\/groups.google.com\/forum\/#!topic\/closure-library-discuss\/7w_O9-vzlj4\n\n # Attempt 32-bit mode if available (Java 7 on Mac OS X does not support 32-bit\n # mode, for example).\n if _JavaSupports32BitMode():\n args += ['-d32']\n\n # Prefer the \"client\" VM.\n args += ['-client']\n\n # Add JVM flags, if any\n if jvm_flags:\n args += jvm_flags\n\n # Add the application JAR.\n args += ['-jar', compiler_jar_path]\n\n for path in source_paths:\n args += ['--js', path]\n\n # Add compiler flags, if any.\n if compiler_flags:\n args += compiler_flags\n\n return args","function_tokens":["def","_GetJsCompilerArgs","(","compiler_jar_path",",","java_version",",","source_paths",",","jvm_flags",",","compiler_flags",")",":","if","java_version","<","(","1",",","7",")",":","raise","JsCompilerError","(","'Closure Compiler requires Java 1.7 or higher. '","'Please visit http:\/\/www.java.com\/getjava'",")","args","=","[","'java'","]","# Add JVM flags we believe will produce the best performance. See","# https:\/\/groups.google.com\/forum\/#!topic\/closure-library-discuss\/7w_O9-vzlj4","# Attempt 32-bit mode if available (Java 7 on Mac OS X does not support 32-bit","# mode, for example).","if","_JavaSupports32BitMode","(",")",":","args","+=","[","'-d32'","]","# Prefer the \"client\" VM.","args","+=","[","'-client'","]","# Add JVM flags, if any","if","jvm_flags",":","args","+=","jvm_flags","# Add the application JAR.","args","+=","[","'-jar'",",","compiler_jar_path","]","for","path","in","source_paths",":","args","+=","[","'--js'",",","path","]","# Add compiler flags, if any.","if","compiler_flags",":","args","+=","compiler_flags","return","args"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/build\/jscompiler.py#L72-L107"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/build\/jscompiler.py","language":"python","identifier":"Compile","parameters":"(compiler_jar_path, source_paths,\n jvm_flags=None,\n compiler_flags=None)","argument_list":"","return_statement":"","docstring":"Prepares command-line call to Closure Compiler.\n\n Args:\n compiler_jar_path: Path to the Closure compiler .jar file.\n source_paths: Source paths to build, in order.\n jvm_flags: A list of additional flags to pass on to JVM.\n compiler_flags: A list of additional flags to pass on to Closure Compiler.\n\n Returns:\n The compiled source, as a string, or None if compilation failed.","docstring_summary":"Prepares command-line call to Closure Compiler.","docstring_tokens":["Prepares","command","-","line","call","to","Closure","Compiler","."],"function":"def Compile(compiler_jar_path, source_paths,\n jvm_flags=None,\n compiler_flags=None):\n \"\"\"Prepares command-line call to Closure Compiler.\n\n Args:\n compiler_jar_path: Path to the Closure compiler .jar file.\n source_paths: Source paths to build, in order.\n jvm_flags: A list of additional flags to pass on to JVM.\n compiler_flags: A list of additional flags to pass on to Closure Compiler.\n\n Returns:\n The compiled source, as a string, or None if compilation failed.\n \"\"\"\n\n java_version = _ParseJavaVersion(_GetJavaVersionString())\n\n args = _GetJsCompilerArgs(\n compiler_jar_path, java_version, source_paths, jvm_flags, compiler_flags)\n\n logging.info('Compiling with the following command: %s', ' '.join(args))\n\n try:\n return subprocess.check_output(args)\n except subprocess.CalledProcessError:\n raise JsCompilerError('JavaScript compilation failed.')","function_tokens":["def","Compile","(","compiler_jar_path",",","source_paths",",","jvm_flags","=","None",",","compiler_flags","=","None",")",":","java_version","=","_ParseJavaVersion","(","_GetJavaVersionString","(",")",")","args","=","_GetJsCompilerArgs","(","compiler_jar_path",",","java_version",",","source_paths",",","jvm_flags",",","compiler_flags",")","logging",".","info","(","'Compiling with the following command: %s'",",","' '",".","join","(","args",")",")","try",":","return","subprocess",".","check_output","(","args",")","except","subprocess",".","CalledProcessError",":","raise","JsCompilerError","(","'JavaScript compilation failed.'",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/build\/jscompiler.py#L110-L135"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/build\/closurebuilder.py","language":"python","identifier":"_GetOptionsParser","parameters":"()","argument_list":"","return_statement":"return parser","docstring":"Get the options parser.","docstring_summary":"Get the options parser.","docstring_tokens":["Get","the","options","parser","."],"function":"def _GetOptionsParser():\n \"\"\"Get the options parser.\"\"\"\n\n parser = optparse.OptionParser(__doc__)\n parser.add_option('-i',\n '--input',\n dest='inputs',\n action='append',\n default=[],\n help='One or more input files to calculate dependencies '\n 'for. The namespaces in this file will be combined with '\n 'those given with the -n flag to form the set of '\n 'namespaces to find dependencies for.')\n parser.add_option('-n',\n '--namespace',\n dest='namespaces',\n action='append',\n default=[],\n help='One or more namespaces to calculate dependencies '\n 'for. These namespaces will be combined with those given '\n 'with the -i flag to form the set of namespaces to find '\n 'dependencies for. A Closure namespace is a '\n 'dot-delimited path expression declared with a call to '\n 'goog.provide() (e.g. \"goog.array\" or \"foo.bar\").')\n parser.add_option('--root',\n dest='roots',\n action='append',\n default=[],\n help='The paths that should be traversed to build the '\n 'dependencies.')\n parser.add_option('-o',\n '--output_mode',\n dest='output_mode',\n type='choice',\n action='store',\n choices=['list', 'script', 'compiled'],\n default='list',\n help='The type of output to generate from this script. '\n 'Options are \"list\" for a list of filenames, \"script\" '\n 'for a single script containing the contents of all the '\n 'files, or \"compiled\" to produce compiled output with '\n 'the Closure Compiler. Default is \"list\".')\n parser.add_option('-c',\n '--compiler_jar',\n dest='compiler_jar',\n action='store',\n help='The location of the Closure compiler .jar file.')\n parser.add_option('-f',\n '--compiler_flags',\n dest='compiler_flags',\n default=[],\n action='append',\n help='Additional flags to pass to the Closure compiler. '\n 'To pass multiple flags, --compiler_flags has to be '\n 'specified multiple times.')\n parser.add_option('-j',\n '--jvm_flags',\n dest='jvm_flags',\n default=[],\n action='append',\n help='Additional flags to pass to the JVM compiler. '\n 'To pass multiple flags, --jvm_flags has to be '\n 'specified multiple times.')\n parser.add_option('--output_file',\n dest='output_file',\n action='store',\n help=('If specified, write output to this path instead of '\n 'writing to standard output.'))\n\n return parser","function_tokens":["def","_GetOptionsParser","(",")",":","parser","=","optparse",".","OptionParser","(","__doc__",")","parser",".","add_option","(","'-i'",",","'--input'",",","dest","=","'inputs'",",","action","=","'append'",",","default","=","[","]",",","help","=","'One or more input files to calculate dependencies '","'for. The namespaces in this file will be combined with '","'those given with the -n flag to form the set of '","'namespaces to find dependencies for.'",")","parser",".","add_option","(","'-n'",",","'--namespace'",",","dest","=","'namespaces'",",","action","=","'append'",",","default","=","[","]",",","help","=","'One or more namespaces to calculate dependencies '","'for. These namespaces will be combined with those given '","'with the -i flag to form the set of namespaces to find '","'dependencies for. A Closure namespace is a '","'dot-delimited path expression declared with a call to '","'goog.provide() (e.g. \"goog.array\" or \"foo.bar\").'",")","parser",".","add_option","(","'--root'",",","dest","=","'roots'",",","action","=","'append'",",","default","=","[","]",",","help","=","'The paths that should be traversed to build the '","'dependencies.'",")","parser",".","add_option","(","'-o'",",","'--output_mode'",",","dest","=","'output_mode'",",","type","=","'choice'",",","action","=","'store'",",","choices","=","[","'list'",",","'script'",",","'compiled'","]",",","default","=","'list'",",","help","=","'The type of output to generate from this script. '","'Options are \"list\" for a list of filenames, \"script\" '","'for a single script containing the contents of all the '","'files, or \"compiled\" to produce compiled output with '","'the Closure Compiler. Default is \"list\".'",")","parser",".","add_option","(","'-c'",",","'--compiler_jar'",",","dest","=","'compiler_jar'",",","action","=","'store'",",","help","=","'The location of the Closure compiler .jar file.'",")","parser",".","add_option","(","'-f'",",","'--compiler_flags'",",","dest","=","'compiler_flags'",",","default","=","[","]",",","action","=","'append'",",","help","=","'Additional flags to pass to the Closure compiler. '","'To pass multiple flags, --compiler_flags has to be '","'specified multiple times.'",")","parser",".","add_option","(","'-j'",",","'--jvm_flags'",",","dest","=","'jvm_flags'",",","default","=","[","]",",","action","=","'append'",",","help","=","'Additional flags to pass to the JVM compiler. '","'To pass multiple flags, --jvm_flags has to be '","'specified multiple times.'",")","parser",".","add_option","(","'--output_file'",",","dest","=","'output_file'",",","action","=","'store'",",","help","=","(","'If specified, write output to this path instead of '","'writing to standard output.'",")",")","return","parser"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/build\/closurebuilder.py#L44-L113"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/build\/closurebuilder.py","language":"python","identifier":"_GetInputByPath","parameters":"(path, sources)","argument_list":"","return_statement":"","docstring":"Get the source identified by a path.\n\n Args:\n path: str, A path to a file that identifies a source.\n sources: An iterable collection of source objects.\n\n Returns:\n The source from sources identified by path, if found. Converts to\n absolute paths for comparison.","docstring_summary":"Get the source identified by a path.","docstring_tokens":["Get","the","source","identified","by","a","path","."],"function":"def _GetInputByPath(path, sources):\n \"\"\"Get the source identified by a path.\n\n Args:\n path: str, A path to a file that identifies a source.\n sources: An iterable collection of source objects.\n\n Returns:\n The source from sources identified by path, if found. Converts to\n absolute paths for comparison.\n \"\"\"\n for js_source in sources:\n # Convert both to absolute paths for comparison.\n if os.path.abspath(path) == os.path.abspath(js_source.GetPath()):\n return js_source","function_tokens":["def","_GetInputByPath","(","path",",","sources",")",":","for","js_source","in","sources",":","# Convert both to absolute paths for comparison.","if","os",".","path",".","abspath","(","path",")","==","os",".","path",".","abspath","(","js_source",".","GetPath","(",")",")",":","return","js_source"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/build\/closurebuilder.py#L116-L130"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/build\/closurebuilder.py","language":"python","identifier":"_GetClosureBaseFile","parameters":"(sources)","argument_list":"","return_statement":"return base_files[0]","docstring":"Given a set of sources, returns the one base.js file.\n\n Note that if zero or two or more base.js files are found, an error message\n will be written and the program will be exited.\n\n Args:\n sources: An iterable of _PathSource objects.\n\n Returns:\n The _PathSource representing the base Closure file.","docstring_summary":"Given a set of sources, returns the one base.js file.","docstring_tokens":["Given","a","set","of","sources","returns","the","one","base",".","js","file","."],"function":"def _GetClosureBaseFile(sources):\n \"\"\"Given a set of sources, returns the one base.js file.\n\n Note that if zero or two or more base.js files are found, an error message\n will be written and the program will be exited.\n\n Args:\n sources: An iterable of _PathSource objects.\n\n Returns:\n The _PathSource representing the base Closure file.\n \"\"\"\n base_files = [\n js_source for js_source in sources if _IsClosureBaseFile(js_source)]\n\n if not base_files:\n logging.error('No Closure base.js file found.')\n sys.exit(1)\n if len(base_files) > 1:\n logging.error('More than one Closure base.js files found at these paths:')\n for base_file in base_files:\n logging.error(base_file.GetPath())\n sys.exit(1)\n return base_files[0]","function_tokens":["def","_GetClosureBaseFile","(","sources",")",":","base_files","=","[","js_source","for","js_source","in","sources","if","_IsClosureBaseFile","(","js_source",")","]","if","not","base_files",":","logging",".","error","(","'No Closure base.js file found.'",")","sys",".","exit","(","1",")","if","len","(","base_files",")",">","1",":","logging",".","error","(","'More than one Closure base.js files found at these paths:'",")","for","base_file","in","base_files",":","logging",".","error","(","base_file",".","GetPath","(",")",")","sys",".","exit","(","1",")","return","base_files","[","0","]"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/build\/closurebuilder.py#L133-L156"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/build\/closurebuilder.py","language":"python","identifier":"_IsClosureBaseFile","parameters":"(js_source)","argument_list":"","return_statement":"return (os.path.basename(js_source.GetPath()) == 'base.js' and\n js_source.provides == set(['goog']))","docstring":"Returns true if the given _PathSource is the Closure base.js source.","docstring_summary":"Returns true if the given _PathSource is the Closure base.js source.","docstring_tokens":["Returns","true","if","the","given","_PathSource","is","the","Closure","base",".","js","source","."],"function":"def _IsClosureBaseFile(js_source):\n \"\"\"Returns true if the given _PathSource is the Closure base.js source.\"\"\"\n return (os.path.basename(js_source.GetPath()) == 'base.js' and\n js_source.provides == set(['goog']))","function_tokens":["def","_IsClosureBaseFile","(","js_source",")",":","return","(","os",".","path",".","basename","(","js_source",".","GetPath","(",")",")","==","'base.js'","and","js_source",".","provides","==","set","(","[","'goog'","]",")",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/build\/closurebuilder.py#L159-L162"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/build\/closurebuilder.py","language":"python","identifier":"_PathSource.__init__","parameters":"(self, path)","argument_list":"","return_statement":"","docstring":"Initialize a source.\n\n Args:\n path: str, Path to a JavaScript file. The source string will be read\n from this file.","docstring_summary":"Initialize a source.","docstring_tokens":["Initialize","a","source","."],"function":"def __init__(self, path):\n \"\"\"Initialize a source.\n\n Args:\n path: str, Path to a JavaScript file. The source string will be read\n from this file.\n \"\"\"\n super(_PathSource, self).__init__(source.GetFileContents(path))\n\n self._path = path","function_tokens":["def","__init__","(","self",",","path",")",":","super","(","_PathSource",",","self",")",".","__init__","(","source",".","GetFileContents","(","path",")",")","self",".","_path","=","path"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/build\/closurebuilder.py#L168-L177"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/build\/closurebuilder.py","language":"python","identifier":"_PathSource.GetPath","parameters":"(self)","argument_list":"","return_statement":"return self._path","docstring":"Returns the path.","docstring_summary":"Returns the path.","docstring_tokens":["Returns","the","path","."],"function":"def GetPath(self):\n \"\"\"Returns the path.\"\"\"\n return self._path","function_tokens":["def","GetPath","(","self",")",":","return","self",".","_path"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/build\/closurebuilder.py#L182-L184"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/build\/depswriter.py","language":"python","identifier":"MakeDepsFile","parameters":"(source_map)","argument_list":"","return_statement":"return ''.join(lines)","docstring":"Make a generated deps file.\n\n Args:\n source_map: A dict map of the source path to source.Source object.\n\n Returns:\n str, A generated deps file source.","docstring_summary":"Make a generated deps file.","docstring_tokens":["Make","a","generated","deps","file","."],"function":"def MakeDepsFile(source_map):\n \"\"\"Make a generated deps file.\n\n Args:\n source_map: A dict map of the source path to source.Source object.\n\n Returns:\n str, A generated deps file source.\n \"\"\"\n\n # Write in path alphabetical order\n paths = sorted(source_map.keys())\n\n lines = []\n\n for path in paths:\n js_source = source_map[path]\n\n # We don't need to add entries that don't provide anything.\n if js_source.provides:\n lines.append(_GetDepsLine(path, js_source))\n\n return ''.join(lines)","function_tokens":["def","MakeDepsFile","(","source_map",")",":","# Write in path alphabetical order","paths","=","sorted","(","source_map",".","keys","(",")",")","lines","=","[","]","for","path","in","paths",":","js_source","=","source_map","[","path","]","# We don't need to add entries that don't provide anything.","if","js_source",".","provides",":","lines",".","append","(","_GetDepsLine","(","path",",","js_source",")",")","return","''",".","join","(","lines",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/build\/depswriter.py#L40-L62"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/build\/depswriter.py","language":"python","identifier":"_GetDepsLine","parameters":"(path, js_source)","argument_list":"","return_statement":"return 'goog.addDependency(\\'%s\\', %s, %s, %s);\\n' % (\n path, provides, requires, module)","docstring":"Get a deps.js file string for a source.","docstring_summary":"Get a deps.js file string for a source.","docstring_tokens":["Get","a","deps",".","js","file","string","for","a","source","."],"function":"def _GetDepsLine(path, js_source):\n \"\"\"Get a deps.js file string for a source.\"\"\"\n\n provides = sorted(js_source.provides)\n requires = sorted(js_source.requires)\n module = 'true' if js_source.is_goog_module else 'false'\n\n return 'goog.addDependency(\\'%s\\', %s, %s, %s);\\n' % (\n path, provides, requires, module)","function_tokens":["def","_GetDepsLine","(","path",",","js_source",")",":","provides","=","sorted","(","js_source",".","provides",")","requires","=","sorted","(","js_source",".","requires",")","module","=","'true'","if","js_source",".","is_goog_module","else","'false'","return","'goog.addDependency(\\'%s\\', %s, %s, %s);\\n'","%","(","path",",","provides",",","requires",",","module",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/build\/depswriter.py#L65-L73"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/build\/depswriter.py","language":"python","identifier":"_GetOptionsParser","parameters":"()","argument_list":"","return_statement":"return parser","docstring":"Get the options parser.","docstring_summary":"Get the options parser.","docstring_tokens":["Get","the","options","parser","."],"function":"def _GetOptionsParser():\n \"\"\"Get the options parser.\"\"\"\n\n parser = optparse.OptionParser(__doc__)\n\n parser.add_option('--output_file',\n dest='output_file',\n action='store',\n help=('If specified, write output to this path instead of '\n 'writing to standard output.'))\n parser.add_option('--root',\n dest='roots',\n default=[],\n action='append',\n help='A root directory to scan for JS source files. '\n 'Paths of JS files in generated deps file will be '\n 'relative to this path. This flag may be specified '\n 'multiple times.')\n parser.add_option('--root_with_prefix',\n dest='roots_with_prefix',\n default=[],\n action='append',\n help='A root directory to scan for JS source files, plus '\n 'a prefix (if either contains a space, surround with '\n 'quotes). Paths in generated deps file will be relative '\n 'to the root, but preceded by the prefix. This flag '\n 'may be specified multiple times.')\n parser.add_option('--path_with_depspath',\n dest='paths_with_depspath',\n default=[],\n action='append',\n help='A path to a source file and an alternate path to '\n 'the file in the generated deps file (if either contains '\n 'a space, surround with whitespace). This flag may be '\n 'specified multiple times.')\n return parser","function_tokens":["def","_GetOptionsParser","(",")",":","parser","=","optparse",".","OptionParser","(","__doc__",")","parser",".","add_option","(","'--output_file'",",","dest","=","'output_file'",",","action","=","'store'",",","help","=","(","'If specified, write output to this path instead of '","'writing to standard output.'",")",")","parser",".","add_option","(","'--root'",",","dest","=","'roots'",",","default","=","[","]",",","action","=","'append'",",","help","=","'A root directory to scan for JS source files. '","'Paths of JS files in generated deps file will be '","'relative to this path. This flag may be specified '","'multiple times.'",")","parser",".","add_option","(","'--root_with_prefix'",",","dest","=","'roots_with_prefix'",",","default","=","[","]",",","action","=","'append'",",","help","=","'A root directory to scan for JS source files, plus '","'a prefix (if either contains a space, surround with '","'quotes). Paths in generated deps file will be relative '","'to the root, but preceded by the prefix. This flag '","'may be specified multiple times.'",")","parser",".","add_option","(","'--path_with_depspath'",",","dest","=","'paths_with_depspath'",",","default","=","[","]",",","action","=","'append'",",","help","=","'A path to a source file and an alternate path to '","'the file in the generated deps file (if either contains '","'a space, surround with whitespace). This flag may be '","'specified multiple times.'",")","return","parser"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/build\/depswriter.py#L76-L111"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/build\/depswriter.py","language":"python","identifier":"_NormalizePathSeparators","parameters":"(path)","argument_list":"","return_statement":"return path.replace(os.sep, posixpath.sep)","docstring":"Replaces OS-specific path separators with POSIX-style slashes.\n\n Args:\n path: str, A file path.\n\n Returns:\n str, The path with any OS-specific path separators (such as backslash on\n Windows) replaced with URL-compatible forward slashes. A no-op on systems\n that use POSIX paths.","docstring_summary":"Replaces OS-specific path separators with POSIX-style slashes.","docstring_tokens":["Replaces","OS","-","specific","path","separators","with","POSIX","-","style","slashes","."],"function":"def _NormalizePathSeparators(path):\n \"\"\"Replaces OS-specific path separators with POSIX-style slashes.\n\n Args:\n path: str, A file path.\n\n Returns:\n str, The path with any OS-specific path separators (such as backslash on\n Windows) replaced with URL-compatible forward slashes. A no-op on systems\n that use POSIX paths.\n \"\"\"\n return path.replace(os.sep, posixpath.sep)","function_tokens":["def","_NormalizePathSeparators","(","path",")",":","return","path",".","replace","(","os",".","sep",",","posixpath",".","sep",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/build\/depswriter.py#L114-L125"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/build\/depswriter.py","language":"python","identifier":"_GetRelativePathToSourceDict","parameters":"(root, prefix='')","argument_list":"","return_statement":"return path_to_source","docstring":"Scans a top root directory for .js sources.\n\n Args:\n root: str, Root directory.\n prefix: str, Prefix for returned paths.\n\n Returns:\n dict, A map of relative paths (with prefix, if given), to source.Source\n objects.","docstring_summary":"Scans a top root directory for .js sources.","docstring_tokens":["Scans","a","top","root","directory","for",".","js","sources","."],"function":"def _GetRelativePathToSourceDict(root, prefix=''):\n \"\"\"Scans a top root directory for .js sources.\n\n Args:\n root: str, Root directory.\n prefix: str, Prefix for returned paths.\n\n Returns:\n dict, A map of relative paths (with prefix, if given), to source.Source\n objects.\n \"\"\"\n # Remember and restore the cwd when we're done. We work from the root so\n # that paths are relative from the root.\n start_wd = os.getcwd()\n os.chdir(root)\n\n path_to_source = {}\n for path in treescan.ScanTreeForJsFiles('.'):\n prefixed_path = _NormalizePathSeparators(os.path.join(prefix, path))\n path_to_source[prefixed_path] = source.Source(source.GetFileContents(path))\n\n os.chdir(start_wd)\n\n return path_to_source","function_tokens":["def","_GetRelativePathToSourceDict","(","root",",","prefix","=","''",")",":","# Remember and restore the cwd when we're done. We work from the root so","# that paths are relative from the root.","start_wd","=","os",".","getcwd","(",")","os",".","chdir","(","root",")","path_to_source","=","{","}","for","path","in","treescan",".","ScanTreeForJsFiles","(","'.'",")",":","prefixed_path","=","_NormalizePathSeparators","(","os",".","path",".","join","(","prefix",",","path",")",")","path_to_source","[","prefixed_path","]","=","source",".","Source","(","source",".","GetFileContents","(","path",")",")","os",".","chdir","(","start_wd",")","return","path_to_source"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/build\/depswriter.py#L128-L151"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/build\/depswriter.py","language":"python","identifier":"_GetPair","parameters":"(s)","argument_list":"","return_statement":"","docstring":"Return a string as a shell-parsed tuple. Two values expected.","docstring_summary":"Return a string as a shell-parsed tuple. Two values expected.","docstring_tokens":["Return","a","string","as","a","shell","-","parsed","tuple",".","Two","values","expected","."],"function":"def _GetPair(s):\n \"\"\"Return a string as a shell-parsed tuple. Two values expected.\"\"\"\n try:\n # shlex uses '\\' as an escape character, so they must be escaped.\n s = s.replace('\\\\', '\\\\\\\\')\n first, second = shlex.split(s)\n return (first, second)\n except:\n raise Exception('Unable to parse input line as a pair: %s' % s)","function_tokens":["def","_GetPair","(","s",")",":","try",":","# shlex uses '\\' as an escape character, so they must be escaped.","s","=","s",".","replace","(","'\\\\'",",","'\\\\\\\\'",")","first",",","second","=","shlex",".","split","(","s",")","return","(","first",",","second",")","except",":","raise","Exception","(","'Unable to parse input line as a pair: %s'","%","s",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/build\/depswriter.py#L154-L162"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/build\/depswriter.py","language":"python","identifier":"main","parameters":"()","argument_list":"","return_statement":"","docstring":"CLI frontend to MakeDepsFile.","docstring_summary":"CLI frontend to MakeDepsFile.","docstring_tokens":["CLI","frontend","to","MakeDepsFile","."],"function":"def main():\n \"\"\"CLI frontend to MakeDepsFile.\"\"\"\n logging.basicConfig(format=(sys.argv[0] + ': %(message)s'),\n level=logging.INFO)\n options, args = _GetOptionsParser().parse_args()\n\n path_to_source = {}\n\n # Roots without prefixes\n for root in options.roots:\n path_to_source.update(_GetRelativePathToSourceDict(root))\n\n # Roots with prefixes\n for root_and_prefix in options.roots_with_prefix:\n root, prefix = _GetPair(root_and_prefix)\n path_to_source.update(_GetRelativePathToSourceDict(root, prefix=prefix))\n\n # Source paths\n for path in args:\n path_to_source[path] = source.Source(source.GetFileContents(path))\n\n # Source paths with alternate deps paths\n for path_with_depspath in options.paths_with_depspath:\n srcpath, depspath = _GetPair(path_with_depspath)\n path_to_source[depspath] = source.Source(source.GetFileContents(srcpath))\n\n # Make our output pipe.\n if options.output_file:\n out = open(options.output_file, 'w')\n else:\n out = sys.stdout\n\n out.write('\/\/ This file was autogenerated by %s.\\n' % sys.argv[0])\n out.write('\/\/ Please do not edit.\\n')\n\n out.write(MakeDepsFile(path_to_source))","function_tokens":["def","main","(",")",":","logging",".","basicConfig","(","format","=","(","sys",".","argv","[","0","]","+","': %(message)s'",")",",","level","=","logging",".","INFO",")","options",",","args","=","_GetOptionsParser","(",")",".","parse_args","(",")","path_to_source","=","{","}","# Roots without prefixes","for","root","in","options",".","roots",":","path_to_source",".","update","(","_GetRelativePathToSourceDict","(","root",")",")","# Roots with prefixes","for","root_and_prefix","in","options",".","roots_with_prefix",":","root",",","prefix","=","_GetPair","(","root_and_prefix",")","path_to_source",".","update","(","_GetRelativePathToSourceDict","(","root",",","prefix","=","prefix",")",")","# Source paths","for","path","in","args",":","path_to_source","[","path","]","=","source",".","Source","(","source",".","GetFileContents","(","path",")",")","# Source paths with alternate deps paths","for","path_with_depspath","in","options",".","paths_with_depspath",":","srcpath",",","depspath","=","_GetPair","(","path_with_depspath",")","path_to_source","[","depspath","]","=","source",".","Source","(","source",".","GetFileContents","(","srcpath",")",")","# Make our output pipe.","if","options",".","output_file",":","out","=","open","(","options",".","output_file",",","'w'",")","else",":","out","=","sys",".","stdout","out",".","write","(","'\/\/ This file was autogenerated by %s.\\n'","%","sys",".","argv","[","0","]",")","out",".","write","(","'\/\/ Please do not edit.\\n'",")","out",".","write","(","MakeDepsFile","(","path_to_source",")",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/build\/depswriter.py#L165-L200"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/build\/treescan.py","language":"python","identifier":"ScanTreeForJsFiles","parameters":"(root)","argument_list":"","return_statement":"return ScanTree(root, path_filter=_JS_FILE_REGEX)","docstring":"Scans a directory tree for JavaScript files.\n\n Args:\n root: str, Path to a root directory.\n\n Returns:\n An iterable of paths to JS files, relative to cwd.","docstring_summary":"Scans a directory tree for JavaScript files.","docstring_tokens":["Scans","a","directory","tree","for","JavaScript","files","."],"function":"def ScanTreeForJsFiles(root):\n \"\"\"Scans a directory tree for JavaScript files.\n\n Args:\n root: str, Path to a root directory.\n\n Returns:\n An iterable of paths to JS files, relative to cwd.\n \"\"\"\n return ScanTree(root, path_filter=_JS_FILE_REGEX)","function_tokens":["def","ScanTreeForJsFiles","(","root",")",":","return","ScanTree","(","root",",","path_filter","=","_JS_FILE_REGEX",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/build\/treescan.py#L31-L40"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/build\/treescan.py","language":"python","identifier":"ScanTree","parameters":"(root, path_filter=None, ignore_hidden=True)","argument_list":"","return_statement":"","docstring":"Scans a directory tree for files.\n\n Args:\n root: str, Path to a root directory.\n path_filter: A regular expression filter. If set, only paths matching\n the path_filter are returned.\n ignore_hidden: If True, do not follow or return hidden directories or files\n (those starting with a '.' character).\n\n Yields:\n A string path to files, relative to cwd.","docstring_summary":"Scans a directory tree for files.","docstring_tokens":["Scans","a","directory","tree","for","files","."],"function":"def ScanTree(root, path_filter=None, ignore_hidden=True):\n \"\"\"Scans a directory tree for files.\n\n Args:\n root: str, Path to a root directory.\n path_filter: A regular expression filter. If set, only paths matching\n the path_filter are returned.\n ignore_hidden: If True, do not follow or return hidden directories or files\n (those starting with a '.' character).\n\n Yields:\n A string path to files, relative to cwd.\n \"\"\"\n\n def OnError(os_error):\n raise os_error\n\n for dirpath, dirnames, filenames in os.walk(root, onerror=OnError):\n # os.walk allows us to modify dirnames to prevent decent into particular\n # directories. Avoid hidden directories.\n for dirname in dirnames:\n if ignore_hidden and dirname.startswith('.'):\n dirnames.remove(dirname)\n\n for filename in filenames:\n\n # nothing that starts with '.'\n if ignore_hidden and filename.startswith('.'):\n continue\n\n fullpath = os.path.join(dirpath, filename)\n\n if path_filter and not path_filter.match(fullpath):\n continue\n\n yield os.path.normpath(fullpath)","function_tokens":["def","ScanTree","(","root",",","path_filter","=","None",",","ignore_hidden","=","True",")",":","def","OnError","(","os_error",")",":","raise","os_error","for","dirpath",",","dirnames",",","filenames","in","os",".","walk","(","root",",","onerror","=","OnError",")",":","# os.walk allows us to modify dirnames to prevent decent into particular","# directories. Avoid hidden directories.","for","dirname","in","dirnames",":","if","ignore_hidden","and","dirname",".","startswith","(","'.'",")",":","dirnames",".","remove","(","dirname",")","for","filename","in","filenames",":","# nothing that starts with '.'","if","ignore_hidden","and","filename",".","startswith","(","'.'",")",":","continue","fullpath","=","os",".","path",".","join","(","dirpath",",","filename",")","if","path_filter","and","not","path_filter",".","match","(","fullpath",")",":","continue","yield","os",".","path",".","normpath","(","fullpath",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/build\/treescan.py#L43-L78"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/build\/source.py","language":"python","identifier":"GetFileContents","parameters":"(path)","argument_list":"","return_statement":"","docstring":"Get a file's contents as a string.\n\n Args:\n path: str, Path to file.\n\n Returns:\n str, Contents of file.\n\n Raises:\n IOError: An error occurred opening or reading the file.","docstring_summary":"Get a file's contents as a string.","docstring_tokens":["Get","a","file","s","contents","as","a","string","."],"function":"def GetFileContents(path):\n \"\"\"Get a file's contents as a string.\n\n Args:\n path: str, Path to file.\n\n Returns:\n str, Contents of file.\n\n Raises:\n IOError: An error occurred opening or reading the file.\n\n \"\"\"\n fileobj = open(path)\n try:\n return fileobj.read()\n finally:\n fileobj.close()","function_tokens":["def","GetFileContents","(","path",")",":","fileobj","=","open","(","path",")","try",":","return","fileobj",".","read","(",")","finally",":","fileobj",".","close","(",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/build\/source.py#L110-L127"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/build\/source.py","language":"python","identifier":"Source.__init__","parameters":"(self, source)","argument_list":"","return_statement":"","docstring":"Initialize a source.\n\n Args:\n source: str, The JavaScript source.","docstring_summary":"Initialize a source.","docstring_tokens":["Initialize","a","source","."],"function":"def __init__(self, source):\n \"\"\"Initialize a source.\n\n Args:\n source: str, The JavaScript source.\n \"\"\"\n\n self.provides = set()\n self.requires = set()\n self.is_goog_module = False\n\n self._source = source\n self._ScanSource()","function_tokens":["def","__init__","(","self",",","source",")",":","self",".","provides","=","set","(",")","self",".","requires","=","set","(",")","self",".","is_goog_module","=","False","self",".","_source","=","source","self",".","_ScanSource","(",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/build\/source.py#L50-L62"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/build\/source.py","language":"python","identifier":"Source.GetSource","parameters":"(self)","argument_list":"","return_statement":"return self._source","docstring":"Get the source as a string.","docstring_summary":"Get the source as a string.","docstring_tokens":["Get","the","source","as","a","string","."],"function":"def GetSource(self):\n \"\"\"Get the source as a string.\"\"\"\n return self._source","function_tokens":["def","GetSource","(","self",")",":","return","self",".","_source"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/build\/source.py#L64-L66"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/build\/source.py","language":"python","identifier":"Source._HasProvideGoogFlag","parameters":"(cls, source)","argument_list":"","return_statement":"return False","docstring":"Determines whether the @provideGoog flag is in a comment.","docstring_summary":"Determines whether the","docstring_tokens":["Determines","whether","the"],"function":"def _HasProvideGoogFlag(cls, source):\n \"\"\"Determines whether the @provideGoog flag is in a comment.\"\"\"\n for comment_content in cls._COMMENT_REGEX.findall(source):\n if '@provideGoog' in comment_content:\n return True\n\n return False","function_tokens":["def","_HasProvideGoogFlag","(","cls",",","source",")",":","for","comment_content","in","cls",".","_COMMENT_REGEX",".","findall","(","source",")",":","if","'@provideGoog'","in","comment_content",":","return","True","return","False"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/build\/source.py#L73-L79"}
{"nwo":"EinsteinsWorkshop\/BlocksCAD","sha":"2787505a727c14d0cefdb851594a3841203a6f30","path":"closure-library\/closure\/bin\/build\/source.py","language":"python","identifier":"Source._ScanSource","parameters":"(self)","argument_list":"","return_statement":"","docstring":"Fill in provides and requires by scanning the source.","docstring_summary":"Fill in provides and requires by scanning the source.","docstring_tokens":["Fill","in","provides","and","requires","by","scanning","the","source","."],"function":"def _ScanSource(self):\n \"\"\"Fill in provides and requires by scanning the source.\"\"\"\n\n stripped_source = self._StripComments(self.GetSource())\n\n source_lines = stripped_source.splitlines()\n for line in source_lines:\n match = _PROVIDE_REGEX.match(line)\n if match:\n self.provides.add(match.group(1))\n match = _MODULE_REGEX.match(line)\n if match:\n self.provides.add(match.group(1))\n self.is_goog_module = True\n match = _REQUIRES_REGEX.match(line)\n if match:\n self.requires.add(match.group(1))\n\n # Closure's base file implicitly provides 'goog'.\n # This is indicated with the @provideGoog flag.\n if self._HasProvideGoogFlag(self.GetSource()):\n\n if len(self.provides) or len(self.requires):\n raise Exception(\n 'Base file should not provide or require namespaces.')\n\n self.provides.add('goog')","function_tokens":["def","_ScanSource","(","self",")",":","stripped_source","=","self",".","_StripComments","(","self",".","GetSource","(",")",")","source_lines","=","stripped_source",".","splitlines","(",")","for","line","in","source_lines",":","match","=","_PROVIDE_REGEX",".","match","(","line",")","if","match",":","self",".","provides",".","add","(","match",".","group","(","1",")",")","match","=","_MODULE_REGEX",".","match","(","line",")","if","match",":","self",".","provides",".","add","(","match",".","group","(","1",")",")","self",".","is_goog_module","=","True","match","=","_REQUIRES_REGEX",".","match","(","line",")","if","match",":","self",".","requires",".","add","(","match",".","group","(","1",")",")","# Closure's base file implicitly provides 'goog'.","# This is indicated with the @provideGoog flag.","if","self",".","_HasProvideGoogFlag","(","self",".","GetSource","(",")",")",":","if","len","(","self",".","provides",")","or","len","(","self",".","requires",")",":","raise","Exception","(","'Base file should not provide or require namespaces.'",")","self",".","provides",".","add","(","'goog'",")"],"url":"https:\/\/github.com\/EinsteinsWorkshop\/BlocksCAD\/blob\/2787505a727c14d0cefdb851594a3841203a6f30\/closure-library\/closure\/bin\/build\/source.py#L81-L107"}