Example #1
0
def editFiles(targetDir):
	files = []
	for f in aceutils.get_files(targetDir):
		basename = os.path.basename(f)
		ext = os.path.splitext(basename)[1]
		if ext == '.java':
			if 'Recorder' in basename:
				aceutils.rm(f)
			else:
				files.append(f)

	for file in files:
		ls = []
		with open(file, mode='r', encoding='utf-8-sig') as f:
			for l in f.readlines():
				if 'TakeScreenShot' in l:
					continue
				if 'CaptureScreen' in l:
					continue

				else:
					ls.append(l)

		with open(file, mode='w',  encoding='utf-8') as f:
			f.writelines(ls)
Example #2
0
def getCppFiles(path, base):
    files = aceutils.get_files(path)
    files = [base + p[len(path):] for p in files]
    files = [p.replace('\\', '/') for p in files]
    files = [
        p for p in files if os.path.splitext(p)[1] in {'.c', '.cpp', '.cxx'}
    ]
    return files
Example #3
0
def make_webpage():

    exclude_ext = [".txt", ".psd", ".BAK", ".pptx"]
    aceutils.cdToScript()
    aceutils.cd("../")

    aceutils.copytree("./Document", "./Doc/", True)
    aceutils.cd("./Doc")

    img_dir = "img/"
    ss_dir = "img/ss/"

    files = aceutils.get_files(".")

    for file in files:
        if os.path.splitext(file)[1] in exclude_ext:
            aceutils.rm(file)
            continue

        if os.path.splitext(file)[1] != ".md":
            continue

        ls = []

        # 読み込み
        with open(file, mode="r", encoding="utf-8-sig") as f:
            ls = f.readlines()

        # includeの実装
        relPath = ""
        ls = makeMarkdownUtils.include_basic_sample_web(ls, relPath, ss_dir, "all")
        ls = makeMarkdownUtils.include_application_sample_web(ls, relPath, ss_dir, "all")

        # リンクを修正
        ls = [s.replace(".md", ".html") for s in ls]

        ls = [s.replace("\r\n", "\n") for s in ls]

        # 出力
        with open(file, mode="wb") as f:
            for l in ls:
                f.write(l.encode("utf-8"))

    aceutils.mkdir(img_dir)
    aceutils.mkdir(ss_dir)

    # SSのコピー
    for ssfile in makeMarkdownUtils.included_ss_paths:
        aceutils.copy(ssfile, ss_dir)

    aceutils.cd("../")
Example #4
0
def make_webpage():

    exclude_ext = [".txt", ".psd", ".BAK", ".pptx"]
    aceutils.cdToScript()
    aceutils.cd('../')
    
    aceutils.copytree('./Document', './Doc/', True)
    aceutils.cd('./Doc')

    img_dir = 'img/'
    ss_dir = 'img/ss/'

    files = aceutils.get_files('.')
    
    for file in files:
        if os.path.splitext(file)[1] in exclude_ext:
            aceutils.rm(file)
            continue

        if os.path.splitext(file)[1] != ".md":
            continue

        ls = []

        # 読み込み
        with open(file, mode='r', encoding='utf-8-sig') as f:
            ls = f.readlines()
    
        #includeの実装
        relPath = ''
        ls = makeMarkdownUtils.include_basic_sample_web(ls,relPath,ss_dir,'all')
        ls = makeMarkdownUtils.include_application_sample_web(ls,relPath,ss_dir,'all')
    
        # リンクを修正
        ls = [s.replace('.md', '.html') for s in ls]

        ls = [s.replace('\r\n', '\n') for s in ls]

        # 出力
        with open(file, mode='wb') as f:
            for l in ls:
                f.write(l.encode('utf-8'))

    aceutils.mkdir(img_dir)
    aceutils.mkdir(ss_dir)
  
    # SSのコピー
    for ssfile in makeMarkdownUtils.included_ss_paths:
        aceutils.copy(ssfile,ss_dir)

    aceutils.cd('../')
Example #5
0
def editCSFiles(targetDir):
    files = []
    for f in aceutils.get_files(targetDir):
        basename = os.path.basename(f)
        ext = os.path.splitext(basename)[1]
        if ext == '.cs':
            files.append(f)

    for file in files:
        ls = []
        with open(file, mode='r', encoding='utf-8-sig') as f:
            for l in f.readlines():
                if 'Recorder.TakeScreenShot' in l:
                    continue
                if 'Recorder.CaptureScreen' in l:
                    continue

                else:
                    ls.append(l)

        with open(file, mode='w',  encoding='utf-8') as f:
            f.writelines(ls)
Example #6
0
def editCSFiles(targetDir):
    files = []
    for f in aceutils.get_files(targetDir):
        basename = os.path.basename(f)
        ext = os.path.splitext(basename)[1]
        if ext == ".cs":
            files.append(f)

    for file in files:
        ls = []
        with open(file, mode="r", encoding="utf-8-sig") as f:
            for l in f.readlines():
                if "Recorder.TakeScreenShot" in l:
                    continue
                if "Recorder.CaptureScreen" in l:
                    continue

                else:
                    ls.append(l)

        with open(file, mode="w", encoding="utf-8") as f:
            f.writelines(ls)
Example #7
0
	def editFiles(targetDir):
		files = []
		for f in aceutils.get_files(targetDir):
			basename = os.path.basename(f)
			ext = os.path.splitext(basename)[1]
			
			if ext == '.java':
				if r'Sample' in basename or 'Program' in basename:
					aceutils.rm(f)
				else:
					files.append(f)

		for file in files:
			ls = []
			with open(file, mode='r', encoding='utf-8-sig') as f:
				for l in f.readlines():
					l = l.replace(r'public void Run()','public static void main(String args[])')
					l = l.replace(r'implements ISample','')
					ls.append(l)
	
			with open(file, mode='w', encoding='utf-8-sig') as f:
				f.writelines(ls)
Example #8
0
    def editFiles(targetDir):
        files = []
        for f in aceutils.get_files(targetDir):
            basename = os.path.basename(f)
            ext = os.path.splitext(basename)[1]

            if ext == '.java':
                if r'Sample' in basename or 'Program' in basename:
                    aceutils.rm(f)
                else:
                    files.append(f)

        for file in files:
            ls = []
            with open(file, mode='r', encoding='utf-8-sig') as f:
                for l in f.readlines():
                    l = l.replace(r'public void Run()',
                                  'public static void main(String args[])')
                    l = l.replace(r'implements ISample', '')
                    ls.append(l)

            with open(file, mode='w', encoding='utf-8-sig') as f:
                f.writelines(ls)
Example #9
0
def getCppFiles(path,base):
	files = aceutils.get_files(path)
	files = [ base + p[len(path):] for p in files]
	files = [ p.replace('\\','/') for p in files]
	files = [ p for p in files if os.path.splitext(p)[1] in {'.c','.cpp','.cxx'}]
	return files
Example #10
0
def include_sample(ls,
                   relCodePath,
                   pattern,
                   sampleDir,
                   ssDir,
                   sampleDirPrefix,
                   mode=''):
    """
    ls コードの内容
    relCodePath コードファイルへのルートからの相対パス
    ssDir SSの保存ディレクトリ
	sampleDirPrefix サンプルdirへのリンクの前に追加される文字列
    mode 表示モード(cpp,cs,java)
    """

    #includeの実装
    ls_included = []
    includePattern = r'\* ' + pattern + ' (.+)'
    includer = re.compile(includePattern)

    for s in ls:
        m = includer.search(s.replace('\r', '').replace('\n', ''))
        if m != None:
            sampleNames = m.group(1).split('+')
            sampleName = sampleNames[0]
            searchedTargetDir = sampleDir

            files = []
            for f in aceutils.get_files(searchedTargetDir):
                basename = os.path.basename(f)
                name = os.path.splitext(basename)[0]
                if name in sampleNames:
                    files.append(f)

            ss_files = []
            for f in aceutils.get_files(sample_ss_dir):
                basename = os.path.basename(f)
                name = os.path.splitext(basename)[0]
                if name in sampleNames:
                    ss_files.append(f)

            # コードの検索
            def getFiles(ext):
                files_ = [f for f in files if os.path.splitext(f)[1] == ext]
                if len(files_) > 0:
                    return files_
                return None

            cpp_targetPath = getFiles('.cpp')
            cs_targetPath = getFiles('.cs')
            java_targetPath = getFiles('.java')

            # SSの表示
            if len(ss_files) > 0:
                ss_file = ss_files[0]
                rel_ss_file = os.path.relpath(
                    ssDir + os.path.basename(ss_file),
                    start=os.path.dirname(relCodePath))
                rel_ss_file = rel_ss_file.replace('\\', '/')
                ls_included.append('![SS](' + sampleDirPrefix + rel_ss_file +
                                   ')\n\n')
                included_ss_paths.append(ss_files[0])
                #print(relCodePath + ' : ' + ssDir+os.path.basename(ss_file) + ' : ' + rel_ss_file)

            def includeFile(targetPaths):
                if targetPaths == None:
                    print('include not found : ' + sampleName)
                    return

                ext = os.path.splitext(targetPaths[0])[1]

                if ext == '.cpp':
                    ls_included.append(r'<h3 class="cpp">C++</h3>' + '\n')
                    ls_included.append('```cpp\n')
                elif ext == '.cs':
                    ls_included.append(r'<h3 class="csharp">C#</h3>' + '\n')
                    ls_included.append('```cs\n')
                elif ext == '.java':
                    ls_included.append(r'<h3 class="java">Java</h3>' + '\n')
                    ls_included.append('```java\n')
                else:
                    ls_included.append('```\n')

                for targetPath in targetPaths:
                    print('include : ' + targetPath)

                    # コードの編集
                    with open(targetPath, mode='r', encoding='utf-8-sig') as f:
                        for fl in f.readlines():
                            if ext == '.cpp':
                                fl = fl.replace(r'void ' + sampleName + '()',
                                                r'int main()')
                                fl = fl.replace(r'return;', r'return 0;')

                            if ext == '.cs':
                                fl = fl.replace(
                                    r'public void Run()',
                                    '[System.STAThread]\r\n\tstatic void Main(string[] args)'
                                )
                                fl = fl.replace(r' : ISample', '')
                                if 'Recorder.TakeScreenShot' in fl:
                                    continue
                                if 'Recorder.CaptureScreen' in fl:
                                    continue

                            if ext == '.java':
                                fl = fl.replace(
                                    r'public void Run()',
                                    'public static void main(String args[])')
                                fl = fl.replace(r'implements ISample', '')
                                if 'Recorder.TakeScreenShot' in fl:
                                    continue
                                if 'Recorder.CaptureScreen' in fl:
                                    continue

                            ls_included.append(fl)

                ls_included.append('\n```\n')

            if mode == 'all':
                includeFile(cpp_targetPath)
                includeFile(cs_targetPath)
                includeFile(java_targetPath)
            if mode == 'cs':
                includeFile(cs_targetPath)
            elif mode == 'cpp':
                includeFile(cpp_targetPath)
            elif mode == 'java':
                includeFile(java_targetPath)
        else:
            ls_included.append(s)

    return ls_included
Example #11
0
def make_document_html(mode):
  exclude_ext = [".txt", ".psd", ".BAK", ".pptx"]

  template="""<!DOCTYPE html>
  <html>
  <head>
  <meta charset="UTF-8">
  <STYLE type="text/css">
  <!--
  @charset "utf-8";
  body
  {
  	line-height: 1.5em;
  }

  *::selection
  {
  	background-color: rgba(255, 210, 130, 0.5);
  /*	background-color: rgba(160, 220, 150, 0.5);*/
  }

  h1, h2, h3, h4
  {
  	font-family: "Meiryo UI";
  	display: block;
  }

  h1, h2, h3
  {
  	padding: 0.2em 0.3em;
  }

  h1
  {
  	font-size: 2em;
  	background-color: #ddeeee;
  	border-bottom: 1px solid #999999;
  	line-height: 1.2em;
  }
  h2
  {
  	font-size: 1.5em;
  	background-color: #eef3f3;
  	border-bottom: 1px solid #999999;
  	line-height: 1.2em;
  }
  h3{
  	font-size: 1.3em;
  	background-color: #eeeeee;
  }
  h4
  {
  	font-size: 1.1em;
  	margin-top: 0.3em;
  	margin-bottom: 0em;
  }

  p
  {
  	margin-bottom: 0.9em;
  }
  p code {
    border: 1px solid #ccc;
    border-radius: 3px;
    background-color: #f9f9f9;
    padding: 1px 5px;
    display: inline-block;
  }
  pre
  {
    margin-top: 0.1em;
    margin-left: 1em;
    border: 1px solid #ccc;
    background-color: #f9f9f9;
    padding: 3px 5px;
    display: block;
    font: 1em "Consolas";
  }

  pre code
  {
    font: 0.9em "Consolas";
  }

  code
  {
    color: #52595d;
    font: 0.95em "Consolas";
    margin: 0em 0.3em;
  }

  hr
  {
  	border: 0;
  	border-bottom: 2px dashed #acc;
  	background-color: #fff;
  }

  ul
  {
  	list-style-type: none;
  }

  li
  {
  	border-left: 2px solid #cdd;
  	margin-bottom: 2px;
  	padding-left: 0.5em;
  }

  em
  {
  	display: none;
  }

  table
  {
  	border-collapse: collapse;
  }

  td, th
  {
  	border: 1px solid #8bb;
  	padding: 2px 5px;
  	vertical-align: middle;
  }
  -->
  </STYLE>
  <title>$title$</title>
  </head>
  <body>
  $body$
  </body>
  </html>
  """

  aceutils.cdToScript()
  aceutils.cd('../')
  aceutils.copytree('./Document', './DocumentHtml', True)
  aceutils.cd('./DocumentHtml')

  img_dir = 'img/'
  ss_dir = 'img/ss/'

  files = aceutils.get_files('.')

  with open('template.html', mode='w',  encoding='utf-8') as f:
    f.write(template)

  for file in files:
    if os.path.splitext(file)[1] in exclude_ext:
      aceutils.rm(file)
      continue

    if os.path.splitext(file)[1] != ".md":
      continue

    ls = []

    # 読み込み
    with open(file, mode='r',  encoding='utf-8') as f:
      ls = f.readlines()
    
    #includeの実装
    relPath = file
    ls = makeMarkdownUtils.include_basic_sample(ls,relPath,ss_dir,mode)
    ls = makeMarkdownUtils.include_application_sample(ls,relPath,ss_dir,mode)

    # リンクを修正
    ls = [s.replace('.md', '.html') for s in ls]
    
    # 出力
    with open(file, mode='w',  encoding='utf-8') as f:
      f.writelines(ls)

    # pandocによる出力
    aceutils.call('pandoc -f markdown_github -t html5 -s --template=template.html -o {0}.html {0}.md'.format(os.path.splitext(file)[0]))
    aceutils.rm(file)

  aceutils.mkdir(img_dir)
  aceutils.mkdir(ss_dir)
  
  # SSのコピー
  for ssfile in makeMarkdownUtils.included_ss_paths:
    aceutils.copy(ssfile,ss_dir)

  aceutils.rm('template.html')
  aceutils.cd('../')
Example #12
0
def include_sample(ls,relCodePath,pattern,sampleDir,ssDir,sampleDirPrefix,mode=''):
    """
    ls コードの内容
    relCodePath コードファイルへのルートからの相対パス
    ssDir SSの保存ディレクトリ
	sampleDirPrefix サンプルdirへのリンクの前に追加される文字列
    mode 表示モード(cpp,cs)
    """

    #includeの実装
    ls_included = []
    includePattern = r'\* ' + pattern + ' (.+)'
    includer = re.compile(includePattern)
    
    for s in ls:
        m = includer.search(s.replace('\r','').replace('\n',''))
        if m != None:
            sampleName = m.group(1)
            searchedTargetDir = sampleDir
            
            files = []
            for f in aceutils.get_files(searchedTargetDir):
                basename = os.path.basename(f)
                name = os.path.splitext(basename)[0]
                if name == sampleName:
                    files.append(f)
      
            ss_files = []
            for f in aceutils.get_files(sample_ss_dir):
                basename = os.path.basename(f)
                name = os.path.splitext(basename)[0]
                if name == sampleName:
                    ss_files.append(f)
      
            # コードの検索
            def getFile(ext):
                files_ = [f for f in files if os.path.splitext(f)[1]==ext]
                if len(files_) > 0:
                    return files_[0]
                return None

            cpp_targetPath = getFile('.cpp')
            cs_targetPath = getFile('.cs')

            # SSの表示
            if len(ss_files) > 0:
                ss_file = ss_files[0]
                rel_ss_file = os.path.relpath(ssDir+os.path.basename(ss_file), start=os.path.dirname(relCodePath))
                rel_ss_file = rel_ss_file.replace('\\','/')
                ls_included.append('![SS](' + sampleDirPrefix + rel_ss_file + ')\n\n')
                included_ss_paths.append(ss_files[0])
                #print(relCodePath + ' : ' + ssDir+os.path.basename(ss_file) + ' : ' + rel_ss_file)

            def includeFile(targetPath):
                if targetPath==None:
                    print('include not found : ' + sampleName )
                    return

                print('include : ' + targetPath)

                ext = os.path.splitext(targetPath)[1]
            
                if ext=='.cpp':
                    ls_included.append(r'<h3 class="cpp">C++</h3>'+'\n')
                    ls_included.append('```cpp\n')
                elif ext=='.cs':
                    ls_included.append(r'<h3 class="csharp">C#</h3>'+'\n')
                    ls_included.append('```cs\n')
                else:
                    ls_included.append('```\n')

                with open(targetPath, mode='r', encoding='utf-8-sig') as f:
                    for fl in f.readlines():
                        if ext=='.cpp':
                            fl = fl.replace(r'void ' + sampleName + '()',r'int main()')
                            fl = fl.replace(r'return;',r'return 0;')

                        if ext=='.cs':
                            fl = fl.replace(r'public void Run()','[System.STAThread]\r\n\tstatic void Main(string[] args)')
                            fl = fl.replace(r' : ISample','')
                            if 'Recorder.TakeScreenShot' in fl:
                                continue
                            if 'Recorder.CaptureScreen' in fl:
                                continue

                        ls_included.append(fl)
                
                ls_included.append('\n```\n')

            if mode == 'all':
                includeFile(cpp_targetPath)
                includeFile(cs_targetPath)
            if mode == 'cs':
                includeFile(cs_targetPath)
            elif mode == 'cpp':
                includeFile(cpp_targetPath)

        else:
            ls_included.append(s)

    return ls_included