promote som misc work
This commit is contained in:
		
							
								
								
									
										14
									
								
								SuperScriptDecorator/.vscode/launch.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								SuperScriptDecorator/.vscode/launch.json
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,14 @@
 | 
			
		||||
{
 | 
			
		||||
    "version": "0.2.0",
 | 
			
		||||
    "configurations": [
 | 
			
		||||
        {
 | 
			
		||||
            "name": "SSDecorator",
 | 
			
		||||
            "type": "python",
 | 
			
		||||
            "request": "launch",
 | 
			
		||||
            "program": "SuperScriptDecorator.py",
 | 
			
		||||
            "console": "integratedTerminal",
 | 
			
		||||
            "args": ["-d", "-i", "../example.txt", "-o", "decorate.db"],
 | 
			
		||||
            "justMyCode": false
 | 
			
		||||
        }
 | 
			
		||||
    ]
 | 
			
		||||
}
 | 
			
		||||
@ -1,8 +1,58 @@
 | 
			
		||||
import locale
 | 
			
		||||
import locale, sys, os, shlex
 | 
			
		||||
 | 
			
		||||
# encoding list
 | 
			
		||||
# https://docs.python.org/3/library/codecs.html#standard-encodings
 | 
			
		||||
database_encoding = locale.getpreferredencoding()
 | 
			
		||||
export_db = "import.txt"
 | 
			
		||||
decorated_db = "decorate.db"
 | 
			
		||||
debug_mode = False
 | 
			
		||||
class InputEntry(object):
 | 
			
		||||
    def __init__(self, data: tuple[str]):
 | 
			
		||||
        if len(data) != 4:
 | 
			
		||||
            raise Exception(f"Input syntax error. Require 4 items but got {len(data)}")
 | 
			
		||||
        self.m_Name: str = data[0]
 | 
			
		||||
        self.m_VtFile: str = data[1]
 | 
			
		||||
        self.m_ExportDb: str = data[2]
 | 
			
		||||
        self.m_EnvDb: str = data[3]
 | 
			
		||||
 | 
			
		||||
class CustomConfig(object):
 | 
			
		||||
    def __init__(self):
 | 
			
		||||
        # encoding list
 | 
			
		||||
        # https://docs.python.org/3/library/codecs.html#standard-encodings
 | 
			
		||||
        self.m_DatabaseEncoding: str = locale.getpreferredencoding()
 | 
			
		||||
        self.m_DebugMode = False
 | 
			
		||||
 | 
			
		||||
        self.m_ImportTxt: str = None
 | 
			
		||||
        self.m_DecoratedDb: str = None
 | 
			
		||||
 | 
			
		||||
        self.m_InputEntries: list[InputEntry] = []
 | 
			
		||||
 | 
			
		||||
    def Regulate(self) -> bool:
 | 
			
		||||
        # check input and output
 | 
			
		||||
        if self.m_ImportTxt is None:
 | 
			
		||||
            print("No input. Decorator exit.")
 | 
			
		||||
            return False
 | 
			
		||||
        if not os.path.isfile(self.m_ImportTxt):
 | 
			
		||||
            print(f'No such input: "{self.m_ImportTxt}"')
 | 
			
		||||
            return False
 | 
			
		||||
 | 
			
		||||
        if self.m_DecoratedDb is None:
 | 
			
		||||
            print("No output. Decorator exit.")
 | 
			
		||||
            return False
 | 
			
		||||
        if os.path.isdir(self.m_DecoratedDb):
 | 
			
		||||
            print("Output must be a file.")
 | 
			
		||||
            return False
 | 
			
		||||
 | 
			
		||||
        # remove result database in debug mode
 | 
			
		||||
        if self.m_DebugMode and os.path.isfile(self.m_DecoratedDb):
 | 
			
		||||
            os.remove(self.m_DecoratedDb)
 | 
			
		||||
 | 
			
		||||
        # process input file
 | 
			
		||||
        try:
 | 
			
		||||
            with open(self.m_ImportTxt, 'r', encoding='utf-8') as f:
 | 
			
		||||
                while True:
 | 
			
		||||
                    ln = f.readline()
 | 
			
		||||
                    if ln == '': break
 | 
			
		||||
                    ln.strip()
 | 
			
		||||
                    if ln == '': continue
 | 
			
		||||
 | 
			
		||||
                    self.m_InputEntries.append(InputEntry(shlex.split(ln)))
 | 
			
		||||
        except Exception as ex:
 | 
			
		||||
            print("Errro when processing input file.")
 | 
			
		||||
            print(ex)
 | 
			
		||||
 | 
			
		||||
        return True
 | 
			
		||||
 | 
			
		||||
@ -1,29 +1,51 @@
 | 
			
		||||
import sys
 | 
			
		||||
 | 
			
		||||
value_All = 0
 | 
			
		||||
value_Now = 0
 | 
			
		||||
progressbar_span = 2
 | 
			
		||||
progressbar_count = int(100/progressbar_span)
 | 
			
		||||
class Prograssbar(object):
 | 
			
		||||
    def __init__(self, filecount: int):
 | 
			
		||||
        if (filecount < 0): raise Exception("Progressbar can not hold minus length!")
 | 
			
		||||
 | 
			
		||||
def initProgressbar(all):
 | 
			
		||||
    global value_Now, value_All
 | 
			
		||||
    value_All = all
 | 
			
		||||
    value_Now = 0
 | 
			
		||||
        self.__FileCount: int = filecount
 | 
			
		||||
        self.__FileNow: int = 0
 | 
			
		||||
        self.__ContentCount: int = 0
 | 
			
		||||
        self.__ContentNow: int = 0
 | 
			
		||||
 | 
			
		||||
    sys.stdout.write('[{}] 0%'.format(progressbar_count * '='))
 | 
			
		||||
    sys.stdout.flush()
 | 
			
		||||
        self.__PbarFullChar: int = 50
 | 
			
		||||
        self.__PercentPerFile: float = 1 / self.__FileCount
 | 
			
		||||
        self.__CurFileName: str = None
 | 
			
		||||
 | 
			
		||||
def stepProgressbar():
 | 
			
		||||
    global value_Now, value_All
 | 
			
		||||
    value_Now += 1
 | 
			
		||||
    if (value_Now > value_All):
 | 
			
		||||
        value_Now = value_All
 | 
			
		||||
        self.__Render()
 | 
			
		||||
 | 
			
		||||
    percentage = int(value_Now / value_All * 100)
 | 
			
		||||
    percentage_bar = int(value_Now / value_All * progressbar_count)
 | 
			
		||||
    sys.stdout.write('\r[{}{}] {}%'.format(percentage_bar * '#',(progressbar_count - percentage_bar) * '=', percentage))
 | 
			
		||||
    sys.stdout.flush()
 | 
			
		||||
    def StepFile(self, newfile: str, content_len: int):
 | 
			
		||||
        if self.__CurFileName is not None:
 | 
			
		||||
            # not first call, INC FileNow
 | 
			
		||||
            # if first call, do not INC it
 | 
			
		||||
            self.__FileNow += 1
 | 
			
		||||
        # apply others
 | 
			
		||||
        self.__CurFileName = newfile
 | 
			
		||||
        self.__ContentNow = 0
 | 
			
		||||
        self.__ContentCount = content_len
 | 
			
		||||
 | 
			
		||||
def finProgressbar():
 | 
			
		||||
    sys.stdout.write('\r[{}] 100%\n'.format(progressbar_count * '#'))
 | 
			
		||||
    sys.stdout.flush()
 | 
			
		||||
        self.__Render()
 | 
			
		||||
 | 
			
		||||
    def StepContent(self):
 | 
			
		||||
        self.__ContentNow += 1
 | 
			
		||||
 | 
			
		||||
        self.__Render()
 | 
			
		||||
 | 
			
		||||
    def Finish(self):
 | 
			
		||||
        sys.stdout.write('\n')
 | 
			
		||||
        sys.stdout.flush()
 | 
			
		||||
 | 
			
		||||
    def __Render(self):
 | 
			
		||||
        percentage_content: float = 0 if self.__ContentCount == 0 else (self.__ContentNow / self.__ContentCount)
 | 
			
		||||
        percentage_full: float = (percentage_content + self.__FileNow) * self.__PercentPerFile
 | 
			
		||||
 | 
			
		||||
        percentage_bar = int(percentage_full * self.__PbarFullChar)
 | 
			
		||||
 | 
			
		||||
        sys.stdout.write('\r[{}{}] {:.2f}% - {}'.format(
 | 
			
		||||
            percentage_bar * '#',
 | 
			
		||||
            (self.__PbarFullChar - percentage_bar) * '=', 
 | 
			
		||||
            percentage_full * 100,
 | 
			
		||||
            self.__CurFileName
 | 
			
		||||
        ))
 | 
			
		||||
        sys.stdout.flush()
 | 
			
		||||
 | 
			
		||||
@ -1,53 +1,51 @@
 | 
			
		||||
import CustomConfig
 | 
			
		||||
import DecoratorCore
 | 
			
		||||
import os
 | 
			
		||||
import sys
 | 
			
		||||
import getopt
 | 
			
		||||
import logging
 | 
			
		||||
import CustomConfig, DecoratorCore, Progressbar
 | 
			
		||||
import os, sys, getopt, logging, time
 | 
			
		||||
 | 
			
		||||
# print banner
 | 
			
		||||
print('Super Script Decorator')
 | 
			
		||||
print('Homepage: https://github.com/yyc12345/SuperScriptMaterializer')
 | 
			
		||||
print('Report bug: https://github.com/yyc12345/SuperScriptMaterializer/issues')
 | 
			
		||||
print('')
 | 
			
		||||
 | 
			
		||||
# try get args
 | 
			
		||||
try:
 | 
			
		||||
    opts, args = getopt.getopt(sys.argv[1:], "hi:o:e:c:fd")
 | 
			
		||||
except getopt.GetoptError:
 | 
			
		||||
    print('Wrong arguments!')
 | 
			
		||||
    print('python SuperScriptViewer.py -i <import.txt> -o <decorated.db> -c <codec_name> -d')
 | 
			
		||||
    sys.exit(1)
 | 
			
		||||
 | 
			
		||||
# analyze args
 | 
			
		||||
cfg: CustomConfig.CustomConfig = CustomConfig.CustomConfig()
 | 
			
		||||
for opt, arg in opts:
 | 
			
		||||
    if opt == '-h':
 | 
			
		||||
        print('python SuperScriptViewer.py -i <import.txt> -o <decorated.db> -c <codec_name> -d')
 | 
			
		||||
        sys.exit(0)
 | 
			
		||||
    elif opt == '-i':
 | 
			
		||||
        CustomConfig.export_db = arg
 | 
			
		||||
        cfg.m_ImportTxt = arg
 | 
			
		||||
    elif opt == '-o':
 | 
			
		||||
        CustomConfig.decorated_db = arg
 | 
			
		||||
        cfg.m_DecoratedDb = arg
 | 
			
		||||
    elif opt == '-c':
 | 
			
		||||
        CustomConfig.database_encoding = arg
 | 
			
		||||
        cfg.m_DatabaseEncoding = arg
 | 
			
		||||
    elif opt == '-d':
 | 
			
		||||
        CustomConfig.debug_mode = True
 | 
			
		||||
        cfg.m_DebugMode = True
 | 
			
		||||
 | 
			
		||||
print('Super Script Decorator')
 | 
			
		||||
print('Homepage: https://github.com/yyc12345/SuperScriptMaterializer')
 | 
			
		||||
print('Report bug: https://github.com/yyc12345/SuperScriptMaterializer/issues')
 | 
			
		||||
print('')
 | 
			
		||||
 | 
			
		||||
# process input and output
 | 
			
		||||
if not os.path.isfile(CustomConfig.export_db):
 | 
			
		||||
    print('No import.txt. Fail to generate. Exit app.')
 | 
			
		||||
# regulate data
 | 
			
		||||
if not cfg.Regulate():
 | 
			
		||||
    # failed. exit program
 | 
			
		||||
    sys.exit(1)
 | 
			
		||||
 | 
			
		||||
# real db generator func
 | 
			
		||||
def dc_wrapper():
 | 
			
		||||
    pass
 | 
			
		||||
 | 
			
		||||
# generate db
 | 
			
		||||
if CustomConfig.debug_mode:
 | 
			
		||||
    DecoratorCore.run()
 | 
			
		||||
# if in debug mode, run directly
 | 
			
		||||
# otherwise, run with a try wrapper.
 | 
			
		||||
if cfg.m_DebugMode:
 | 
			
		||||
    DecoratorCore.run(cfg)
 | 
			
		||||
else:
 | 
			
		||||
    try:
 | 
			
		||||
        DecoratorCore.run()
 | 
			
		||||
    except Exception, ex:
 | 
			
		||||
        DecoratorCore.run(cfg)
 | 
			
		||||
    except Exception as ex:
 | 
			
		||||
        print("!!! An error occurs. Please report follwoing error output and reproduce file to developer. !!!")
 | 
			
		||||
        logging.exception(ex)
 | 
			
		||||
        sys.exit(1)
 | 
			
		||||
 | 
			
		||||
print('Decorated database generating done.')
 | 
			
		||||
        
 | 
			
		||||
print('Decorated database generation done.')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,50 +0,0 @@
 | 
			
		||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
 | 
			
		||||
  <PropertyGroup>
 | 
			
		||||
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
 | 
			
		||||
    <SchemaVersion>2.0</SchemaVersion>
 | 
			
		||||
    <ProjectGuid>6d751bf5-87d6-4123-94b3-34721938cf04</ProjectGuid>
 | 
			
		||||
    <ProjectHome>.</ProjectHome>
 | 
			
		||||
    <StartupFile>SuperScriptDecorator.py</StartupFile>
 | 
			
		||||
    <SearchPath>
 | 
			
		||||
    </SearchPath>
 | 
			
		||||
    <WorkingDirectory>.</WorkingDirectory>
 | 
			
		||||
    <OutputPath>.</OutputPath>
 | 
			
		||||
    <Name>SuperScriptDecorator</Name>
 | 
			
		||||
    <RootNamespace>SuperScriptDecorator</RootNamespace>
 | 
			
		||||
    <LaunchProvider>Standard Python launcher</LaunchProvider>
 | 
			
		||||
    <CommandLineArguments>-f -d</CommandLineArguments>
 | 
			
		||||
    <EnableNativeCodeDebugging>False</EnableNativeCodeDebugging>
 | 
			
		||||
  </PropertyGroup>
 | 
			
		||||
  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
 | 
			
		||||
    <DebugSymbols>true</DebugSymbols>
 | 
			
		||||
    <EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
 | 
			
		||||
  </PropertyGroup>
 | 
			
		||||
  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
 | 
			
		||||
    <DebugSymbols>true</DebugSymbols>
 | 
			
		||||
    <EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
 | 
			
		||||
  </PropertyGroup>
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <Compile Include="CustomConfig.py">
 | 
			
		||||
      <SubType>Code</SubType>
 | 
			
		||||
    </Compile>
 | 
			
		||||
    <Compile Include="DecoratorConstValue.py">
 | 
			
		||||
      <SubType>Code</SubType>
 | 
			
		||||
    </Compile>
 | 
			
		||||
    <Compile Include="DecoratorCore.py">
 | 
			
		||||
      <SubType>Code</SubType>
 | 
			
		||||
    </Compile>
 | 
			
		||||
    <Compile Include="Progressbar.py">
 | 
			
		||||
      <SubType>Code</SubType>
 | 
			
		||||
    </Compile>
 | 
			
		||||
    <Compile Include="SuperScriptDecorator.py" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets" />
 | 
			
		||||
  <!-- Uncomment the CoreCompile target to enable the Build command in
 | 
			
		||||
       Visual Studio and specify your pre- and post-build commands in
 | 
			
		||||
       the BeforeBuild and AfterBuild targets below. -->
 | 
			
		||||
  <!--<Target Name="CoreCompile" />-->
 | 
			
		||||
  <Target Name="BeforeBuild">
 | 
			
		||||
  </Target>
 | 
			
		||||
  <Target Name="AfterBuild">
 | 
			
		||||
  </Target>
 | 
			
		||||
</Project>
 | 
			
		||||
		Reference in New Issue
	
	Block a user