Ejemplo n.º 1
0
 def __init__(self, mid, path):
     """Creates a media file.
      mid is the media's unique ID number
      path is the media's path, in legacy sign stream format, with ':' as
      the path separator.
 """
     import macpath
     super(MediaFile, self).__init__()
     self.mid = mid
     self.path = path
     (dir, self.filename) = macpath.split(path)
def recursive(l):

    operator = split(l)
    rest = difLista(operator, l)

    if operator == '+':
        calcSumm(rest, recursive(l))
    elif operator == '-':
        calcSubs(rest, recursive(l))
    elif operator == '*':
        calcPlus(rest, recursive())
    elif operator == '/':
        calcDiv(rest, recursive(l))
    else:
        print("operator error")
Ejemplo n.º 3
0
def glob(pathname):
	if not has_magic(pathname): return [pathname]
	dirname, basename = macpath.split(pathname)
	if has_magic(dirname):
		if dirname[-1:] = ':': dirname = dirname[:-1]
		list = glob(dirname)
	else:
		list = [dirname]
	if not has_magic(basename):
		result = []
		for dirname in list:
			if basename or macpath.isdir(dirname):
				name = macpath.cat(dirname, basename)
				if macpath.exists(name):
					result.append(name)
	else:
		result = []
		for dirname in list:
			sublist = glob1(dirname, basename)
			for name in sublist:
				result.append(macpath.cat(dirname, name))
	return result
Ejemplo n.º 4
0
def glob(pathname):
       if not has_magic(pathname): return [pathname]
       dirname, basename = macpath.split(pathname)
       if has_magic(dirname):
               if dirname[-1:] = ':': dirname = dirname[:-1]
               list = glob(dirname)
       else:
               list = [dirname]
       if not has_magic(basename):
               result = []
               for dirname in list:
                       if basename or macpath.isdir(dirname):
                               name = macpath.cat(dirname, basename)
                               if macpath.exists(name):
                                       result.append(name)
       else:
               result = []
               for dirname in list:
                       sublist = glob1(dirname, basename)
                       for name in sublist:
                               result.append(macpath.cat(dirname, name))
       return result
Ejemplo n.º 5
0
'''
macpath 模块

macpath 模块( 参见 Example 13-2 )提供了 Macintosh 平台下的 os.path 功能. 
你也可以使用它在其他平台处理 Macintosh 路径.
'''
import macpath

file = 'my:little:pony'

print("isabs", "=>", macpath.isabs(file))
print("dirname", "=>", macpath.dirname(file))
print("basename", "=>", macpath.basename(file))
print("normpath", "=>", macpath.normpath(file))
print("split", "=>", macpath.split(file))
print("join", "=>", macpath.join(file, "zorba"))
'''
isabs => True
dirname => my:little
basename => pony
normpath => my:little:pony
split => ('my:little', 'pony')
join => my:little:pony:zorba
'''
Ejemplo n.º 6
0
def make_imDocument(_id_new, summaryid_new, listofwords_new):
    imDocument = Document(_id_new, summaryid_new, listofwords_new)
    return imDocument

    return 2


path = r'C:\inetpub\json.txt'

with open(path, 'r') as data_file:
    data = json.load(data_file)

    data = [doc for doc in data['hits']['hits']]
    for doc in data:
        #print("%s) %s" % (doc['_id'], doc['_source']['summaryid']))
        listofwordsTmp = split(doc['_source']['searchabletext'])
        listofwordsAll += listofwordsTmp
        d01 = make_imDocument(
            doc['_id'], doc['_source']['summaryid'],
            remove_html_tags(doc['_source']['searchabletext']))
        list_of_lists.append(d01)

        docslist.append(remove_html_tags(doc['_source']['searchabletext']))

vectorizer = TfidfVectorizer(stop_words='english')
X = vectorizer.fit_transform(docslist)

true_k = 3
j = 0
model = KMeans(n_clusters=true_k, init='k-means++', max_iter=10000, n_init=1)
model.fit(X)
Ejemplo n.º 7
0
"""
Ejemplo n.º 8
0
"""
Ejemplo n.º 9
0
'''
macpath 模块

macpath 模块( 参见 Example 13-2 )提供了 Macintosh 平台下的 os.path 功能. 
你也可以使用它在其他平台处理 Macintosh 路径.
'''
import macpath

file = 'my:little:pony'

print("isabs", "=>", macpath.isabs(file))
print("dirname", "=>", macpath.dirname(file))
print("basename", "=>", macpath.basename(file))
print("normpath", "=>", macpath.normpath(file))
print("split", "=>", macpath.split(file))
print("join", "=>", macpath.join(file, "zorba"))

'''
isabs => True
dirname => my:little
basename => pony
normpath => my:little:pony
split => ('my:little', 'pony')
join => my:little:pony:zorba
'''
Ejemplo n.º 10
0
def WriteProjectSettingsXML(mprj, templateName):
    """ Writes out the Applescript which writes the <SETTINGS> section of
    the CodeWarrior XML. This includes all the CW project preferences,
    source file list and link order.  This function is used to write
    out the settings for 'project.xml' and 'project_uber.xml' """

    template_filename = os.path.join(os.environ['BUILD_ROOT'],"bin","mac", templateName)
    template_text = open(template_filename,"r").read()
                 
    ## set access paths
    user_list = []
    if templateName == "project_uber.xml":  
        # uber can't have local paths eg. ':', ':pub:'
        # they must be like '::pndebug:', '::pndebug:pub:'
        module_path = os.getcwd()
        src_root_path = macpath.normpath(os.path.join(module_path,mprj.project.src_root_path))+":"

        
        for (path, recursive, origin) in mprj.user_paths:
            umake_lib.debug("USER_PATH: %s => (%s)" %
                            (repr(path),
                             repr(mprj.project.src_root_path)))

            path = macpath.normpath(macpath.join(module_path, path))
            if path[:len(src_root_path)] == src_root_path:
                path = "#SRC_ROOT_PATH#" + path[len(src_root_path):]

            umake_lib.debug("USER_PATH: => %s (%s)" %
                            (repr(path),
                             repr(src_root_path)))

            user_list.append(path)
    else:
        for (path, recursive, origin) in mprj.user_paths:
            path = macpath.normpath(path)
            user_list.append(path)

    ## Set CodeWarrior prefs
    empty_list = []
    template_text = SetAccessPathBlock(template_text,
                                       user_list,
                                       empty_list,
                                       empty_list,
                                       "#USER_SEARCH_PATHS#")

    system_list = []
    recursive_list = []
    origin_list = []
    for (path, recursive, origin) in mprj.system_paths:
        system_list.append(path)
        recursive_list.append(recursive)
        origin_list.append(origin)

    template_text = SetAccessPathBlock(template_text,
                                       system_list,
                                       recursive_list,
                                       origin_list,
                                       "#SYSTEM_SEARCH_PATHS#")

    ## add files
    file_list = string.join(mprj.source_list, ',')
    source_dir,output_dir = macpath.split(mprj.output_dir_path)
    
    target_type = ''
    if output_dir == "debug":
        target_type = "debug"

    template_text = SetFileListBlock(template_text,
                                     file_list,
                                     "#TEXT_FILE_LIST#",
                                     "Text",
                                     target_type)

    source_list = []
    for file_name in mprj.source_list:
        source_list.append(file_name)

    if len(mprj.library_list):
        library_list = string.join(mprj.library_list, ',')
        template_text = SetFileListBlock(template_text,
                                         library_list,
                                         "#LIB_FILE_LIST#",
                                         "Library",
                                         "")

        # add libs to source list since they need to be
        # included with groups, link order iterms
        for library in mprj.library_list:
            lib_path, lib_name = os.path.split(library)
            if lib_name not in mprj.source_list:
                source_list.append(lib_name)
    else:
        template_text=string.replace(template_text, "#LIB_FILE_LIST#", "")
        
    # link order
    file_list = string.join(source_list, ',')

    gLinkOrderBlockString="""
                <FILEREF>
                    <PATHTYPE>Name</PATHTYPE>
                    <PATH>#THE_VALUE#</PATH>
                    <PATHFORMAT>MacOS</PATHFORMAT>
                </FILEREF>
"""

    template_text = SetPreferenceBlock(template_text,
                                       file_list,
                                       gLinkOrderBlockString,
                                       "#LINK_ORDER_ITEMS#")
    
    ## add frameworks
    if len(mprj.project.sys_frameworks):
        framework_string_list = string.join(mprj.project.sys_frameworks, ',')
        template_text=SetFrameworkBlock(template_text,
                                        framework_string_list,
                                        "#FRAMEWORK_LIST#")
    else:
        template_text=string.replace(template_text, "#FRAMEWORK_LIST#", "")

    ## group order
    template_text=SetGroupBlock(template_text,
                                file_list,
                                "#GROUP_LIST_ITEMS#",
                                mprj.cwtarget_name)
    template_text = string.replace(template_text,
                                   "#GROUP_NAME#",
                                   mprj.cwtarget_name)

    ## CW project preferences
    template_text=SetPreferenceValue(template_text, "MWFrontEnd_C_prefixname", mprj.prefix_file)
    template_text=SetPreferenceValue(template_text, "MWRez_Language_prefixname", mprj.rprefix_file)
                
    ## set remaining preferences - theses are defined in macos-carbon-powerpc-cw6.cf
    for (panel, pref) in mprj.preferences.items():
        for (pref_key, pref_value) in pref.items():
            template_text = SetPreferenceValue(template_text,
                                               pref_key,
                                               pref_value)


    # set target dir to debug/release
    if templateName == "project_uber.xml":  
        module_path = mprj.project_file_path[:-1]
        module_path, module_name = os.path.split(module_path)
        module_path, module_name = os.path.split(module_path)
        template_text = string.replace(template_text,
                                       "#TARGET_DIR#",
                                       "#SRC_ROOT_PATH#%s:%s:" % (module_name,output_dir))
                                       
        template_text = string.replace(template_text,
                                       "#OUTPUT_FILE_NAME#",
                                       "%s:%s" % (output_dir,mprj.output_name))
    else:
        template_text = string.replace(template_text,
                                       "#TARGET_DIR#",
                                       ":%s:" % (output_dir))

    template_text = string.replace(template_text,
                                   "#TARGET_NAME#",
                                   mprj.cwtarget_name)

    return template_text