Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

errors just running the script on windows on python 3.7 #17

Closed
tunip3 opened this issue Oct 21, 2018 · 9 comments
Closed

errors just running the script on windows on python 3.7 #17

tunip3 opened this issue Oct 21, 2018 · 9 comments

Comments

@tunip3
Copy link

tunip3 commented Oct 21, 2018

Traceback (most recent call last):
File "u4pak.py", line 1683, in
main(sys.argv[1:])
File "u4pak.py", line 1570, in main
if args.command == 'list':
AttributeError: 'Namespace' object has no attribute 'command'

@align4
Copy link

align4 commented Aug 5, 2019

same, + the following when trying to list

Traceback (most recent call last):
  File "u4pak.py", line 1720, in <module>
    main(sys.argv[1:])
  File "u4pak.py", line 1609, in main
    pak = read_index(stream,args.check_integrity)
  File "u4pak.py", line 792, in read_index
    mount_point = read_path(stream)
  File "u4pak.py", line 538, in read_path
    return stream.read(path_len).rstrip(b'\0').decode('utf-8').replace('/',os.path.sep)
OverflowError: cannot fit 'int' into an index-sized integer

@panzi
Copy link
Owner

panzi commented Aug 5, 2019

I somehow missed the first report: I cannot reproduce that on Linux with Python 3.7.3.
For the second: That is strange. Maybe the file is damaged or in some (sub-)format I don't know about or I have a bug that somehow only gets triggered by your file. Please rewrite the read_path() function on line 536 like this and tell me what the new output is:

def read_path(stream):
	path_len, = st_unpack('<I',stream.read(4))
	print(path_len)
	print(stream.read(8).rstrip(b'\0').decode('utf-8'))
	stream.seek(-8, 1)
	return stream.read(path_len).rstrip(b'\0').decode('utf-8').replace('/',os.path.sep)

@rulesless
Copy link

I somehow missed the first report: I cannot reproduce that on Linux with Python 3.7.3.
For the second: That is strange. Maybe the file is damaged or in some (sub-)format I don't know about or I have a bug that somehow only gets triggered by your file. Please rewrite the read_path() function on line 536 like this and tell me what the new output is:

def read_path(stream):
	path_len, = st_unpack('<I',stream.read(4))
	print(path_len)
	print(stream.read(8).rstrip(b'\0').decode('utf-8'))
	stream.seek(-8, 1)
	return stream.read(path_len).rstrip(b'\0').decode('utf-8').replace('/',os.path.sep)

Before was
Traceback (most recent call last): File u4pak.py, line 1743, in <module> main(sys.argv[1:]) File u4pak.py, line 1618, in main if args.command == 'list': AttributeError: 'Namespace' object has no attribute 'command'

And now
Traceback (most recent call last): File u4pak.py, line 1743, in <module> main(sys.argv[1:]) File u4pak.py, line 1618, in main if args.command == 'list': AttributeError: 'Namespace' object has no attribute 'command'

@panzi
Copy link
Owner

panzi commented Apr 29, 2020

Wait, how do you call the program?

@panzi
Copy link
Owner

panzi commented Apr 29, 2020

I just figured out that you get that error message if you don't pass any arguments to u4pak.py. I fixed it so that it will print the help message in that case.

@rulesless
Copy link

rulesless commented Apr 29, 2020

I just figured out that you get that error message if you don't pass any arguments to u4pak.py. I fixed it so that it will print the help message in that case.

Thanks
`
C:\MOD>u4pak.py pack file.pak folder
usage: u4pak.py [-h] command ...

unpack, list and mount Unreal Engine 4 .pak archives

positional arguments:
command
unpack (x)
unpack archive
pack (c) pack archive
list (l) list archive contens
info (i) print archive summary info
test (t) test archive integrity
mount (m)
fuse mount archive

optional arguments:
-h, --help show this help message and exit
`

@panzi
Copy link
Owner

panzi commented Apr 29, 2020

It prints that help message for you when you try to pack a folder? Weird, it doesn't for me. Sorry, I don't have Windows, so I can't reproduce that problem. :(

panzi@panzi tmp$ mkdir folder
panzi@panzi tmp$ echo foo > folder/foo.txt
panzi@panzi tmp$ echo bar > folder/bar.txt
panzi@panzi tmp$ ~/src/python/u4pak/u4pak.py pack file.pak folder
panzi@panzi tmp$ ~/src/python/u4pak/u4pak.py list file.pak
folder/bar.txt
folder/foo.txt

@Nova77x
Copy link

Nova77x commented Sep 5, 2020

It seems to be a weird bug with argument parsing. This only happens when you omit "python", and just run the script directly. The arguments are read, but the first argument doesn't get parsed properly, even though it's in argv.

u4pak.py pack test.pak test

args:

Namespace(archive='test.pak', archive_version=3, check_integrity=False, command=Non
e, encoding='UTF-8', files=['test'], mount_point='..\..\..\', print0=Fa
lse, progress=False, verbose=False, zlib=False)

argv:

['pack', 'test.pak', 'test']

python u4pak.py pack test.pak test

args:

Namespace(archive='test.pak', archive_version=3, check_integrity=False, command='pa
ck', encoding='UTF-8', files=['test'], mount_point='..\..\..\', print0=
False, progress=False, verbose=False, zlib=False)

argv:

['pack', 'test.pak', 'test']

Go to the line "if args.command is None:", and just above it add "args.command = argv[0]". That fixes it.

@panzi
Copy link
Owner

panzi commented May 14, 2021

Btw. I've also written a new tool now that doesn't require Python, but instead I provide a compiled Windows binary. It is faster, but has slightly different command line arguments and a feature for Windows users that don't want to use a terminal. That means you can write a text file that contains what you otherwise would write as the command line arguments, change the extension from .txt to .u4pak and drop that file onto u4pak.exe (or you can also associate the .u4pak extension with u4pak.exe so that a double-click will automatically open it with that). This should also keep the window open after it is done (until you press ENTER). Though I haven't tested it under Windows since I'm on Linux.

@panzi panzi closed this as completed May 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants