Skip to content

Commit 5d1a49e

Browse files
committedMay 2, 2018
Added FileFormatConverter script
1 parent 2650603 commit 5d1a49e

File tree

4 files changed

+103
-0
lines changed

4 files changed

+103
-0
lines changed
 
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
from argparse import ArgumentParser, FileType, Action
3+
import sys
4+
import codecs
5+
import os
6+
7+
# example use: FileFormatConverter.py --srcfile=radkfile --srcformat=euc-jp --dstfile=radkfile.txt --dstformat=utf8
8+
9+
def parse_cmdline():
10+
parser = ArgumentParser()
11+
parser.add_argument("--srcfile", help="path to the file to convert", required=True)
12+
parser.add_argument("--srcformat", help="format of the source file", required=True)
13+
parser.add_argument("--dstfile", help="path to the converted file", required=True)
14+
parser.add_argument("--dstformat", help="format of the destination file", required=True)
15+
return parser.parse_args()
16+
17+
18+
def main():
19+
args = parse_cmdline()
20+
linecounter = 0
21+
22+
print("Conversion from file '%s' (%s) to file '%s' (%s)" % (args.srcfile, args.srcformat, args.dstfile, args.dstformat))
23+
24+
srcfile = codecs.open(args.srcfile, 'r', args.srcformat)
25+
dstfile = codecs.open(args.dstfile, 'w', args.dstformat)
26+
27+
for line in srcfile:
28+
dstfile.write(line)
29+
linecounter += 1
30+
31+
print("Converted %s lines" % linecounter)
32+
33+
srcfile.close()
34+
dstfile.close()
35+
36+
if __name__ == '__main__':
37+
main()
38+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
2+
<PropertyGroup>
3+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
4+
<SchemaVersion>2.0</SchemaVersion>
5+
<ProjectGuid>381456ed-a5dd-4bee-90cc-8a0d6be1a02a</ProjectGuid>
6+
<ProjectHome>.</ProjectHome>
7+
<StartupFile>FileFormatConverter.py</StartupFile>
8+
<SearchPath>
9+
</SearchPath>
10+
<WorkingDirectory>.</WorkingDirectory>
11+
<OutputPath>.</OutputPath>
12+
<Name>FileFormatConverter</Name>
13+
<RootNamespace>FileFormatConverter</RootNamespace>
14+
<LaunchProvider>Standard Python launcher</LaunchProvider>
15+
<CommandLineArguments>--srcfile=radkfile --srcformat=euc-jp --dstfile=radkfile.txt --dstformat=utf8</CommandLineArguments>
16+
<EnableNativeCodeDebugging>False</EnableNativeCodeDebugging>
17+
</PropertyGroup>
18+
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
19+
<DebugSymbols>true</DebugSymbols>
20+
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
21+
</PropertyGroup>
22+
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
23+
<DebugSymbols>true</DebugSymbols>
24+
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
25+
</PropertyGroup>
26+
<ItemGroup>
27+
<Compile Include="FileFormatConverter.py" />
28+
</ItemGroup>
29+
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets" />
30+
<!-- Uncomment the CoreCompile target to enable the Build command in
31+
Visual Studio and specify your pre- and post-build commands in
32+
the BeforeBuild and AfterBuild targets below. -->
33+
<!--<Target Name="CoreCompile" />-->
34+
<Target Name="BeforeBuild">
35+
</Target>
36+
<Target Name="AfterBuild">
37+
</Target>
38+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.27428.2043
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "FileFormatConverter", "FileFormatConverter.pyproj", "{381456ED-A5DD-4BEE-90CC-8A0D6BE1A02A}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{381456ED-A5DD-4BEE-90CC-8A0D6BE1A02A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{381456ED-A5DD-4BEE-90CC-8A0D6BE1A02A}.Release|Any CPU.ActiveCfg = Release|Any CPU
16+
EndGlobalSection
17+
GlobalSection(SolutionProperties) = preSolution
18+
HideSolutionNode = FALSE
19+
EndGlobalSection
20+
GlobalSection(ExtensibilityGlobals) = postSolution
21+
SolutionGuid = {1A02B8FA-ACD7-4DF8-B1AC-F2BC550103E8}
22+
EndGlobalSection
23+
EndGlobal

‎README.md

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ Python utility scripts by [FalsinSoft](http://falsinsoft.blogspot.com)
33

44
A little collection of simple scripts developed for various purposes
55

6+
FileFormatConverter
7+
---------
8+
Very basic script able to convert a file from a specific codec format to another (for example 'euc-jp' to 'utf8')
9+
610
KradfileToSQLite
711
---------
812
Convert the [KRADFILE](http://www.edrdg.org/krad/kradinf.html) to sqlite database

0 commit comments

Comments
 (0)
Please sign in to comment.