junhuanchen / mpfshell-lite

👾 The lightweight version of the mpfshell is for pure CUI drivers.
https://github.com/wendlers/mpfshell
MIT License
35 stars 8 forks source link

Error upload files to ESP32 board on Windows systems #1

Open AlexStz opened 5 years ago

AlexStz commented 5 years ago

In file mpfexp.py -> def put(src) -> (src='probeled.py') Raise exception: string 284: self.exec_("f = open('%s', 'wb')" % self._fqn(dst)) self._fqn(dst) ='/flash\probeled.py' !!!

Need add to all os.path.join -> .replace("\\","/") Example:

def _fqn(self, name):
        return os.path.join(self.dir, name)

to:

def _fqn(self, name):
        return os.path.join(self.dir, name).replace("\\","/")
AlexStz commented 5 years ago

Or port "fix: Fix posix-style paths from Windows (wendlers#72)" from junhuanchen/mpfshell (change os.path.join to posixpath.join)

junhuanchen commented 5 years ago

🆗 thanks !!!! I know. XD

junhuanchen commented 5 years ago

According to the https://github.com/wendlers/mpfshell/commit/18993e022c79b39da8babdace03cba14e7d5de3e to fix.

But I'm not sure if it will affect other systems.

Your suggestion?

junhuanchen commented 5 years ago

check this.

图片

AlexStz commented 5 years ago

on Windows 7+ everything is OK. (I don't know how to WinXP or Vista) on Linux - also everything is OK. (posix system:) on Mac - I don’t check, none...

пн, 20 мая 2019 г. в 08:21, Juwan notifications@github.com:

According to the wendlers/mpfshell@18993e0 https://github.com/wendlers/mpfshell/commit/18993e022c79b39da8babdace03cba14e7d5de3e to fix.

But I'm not sure if it will affect other systems.

Your suggestion?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/junhuanchen/mpfshell-lite/issues/1?email_source=notifications&email_token=AILA4O3FIE2ZSEE2SBMW5DDPWI7PDA5CNFSM4HNVRSQ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODVXZU5Y#issuecomment-493853303, or mute the thread https://github.com/notifications/unsubscribe-auth/AILA4O2SJFUQ74HVAQS6WOTPWI7PDANCNFSM4HNVRSQQ .

AlexStz commented 5 years ago

if use "posixpath" all paths with "/" - none "\" or "\" !

пн, 20 мая 2019 г. в 09:22, Juwan notifications@github.com:

check this.

[image: 图片] https://user-images.githubusercontent.com/32978053/58003280-0c272d80-7b13-11e9-87cc-0cc78c96ee72.png

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/junhuanchen/mpfshell-lite/issues/1?email_source=notifications&email_token=AILA4O52UDBGW3MBUH662PDPWJGTDA5CNFSM4HNVRSQ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODVX5F5Y#issuecomment-493867767, or mute the thread https://github.com/notifications/unsubscribe-auth/AILA4O6VIRJT5OIIGSUCVE3PWJGTDANCNFSM4HNVRSQQ .

AlexStz commented 5 years ago

this in function "__parse_file_names()" and next -> "Class Tokenizer" ( variable "valid_fnchars")... I need to think. "re.Scanner" -> "tokens". I know this badly. I will dig the Internet.

пн, 20 мая 2019 г. в 09:36, Alex St stz.alex@gmail.com:

if use "posixpath" all paths with "/" - none "\" or "\" !

пн, 20 мая 2019 г. в 09:22, Juwan notifications@github.com:

check this.

[image: 图片] https://user-images.githubusercontent.com/32978053/58003280-0c272d80-7b13-11e9-87cc-0cc78c96ee72.png

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/junhuanchen/mpfshell-lite/issues/1?email_source=notifications&email_token=AILA4O52UDBGW3MBUH662PDPWJGTDA5CNFSM4HNVRSQ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODVX5F5Y#issuecomment-493867767, or mute the thread https://github.com/notifications/unsubscribe-auth/AILA4O6VIRJT5OIIGSUCVE3PWJGTDANCNFSM4HNVRSQQ .

junhuanchen commented 5 years ago

If this is the Windows path will go wrong.

图片

At this time need '\' to '/' , as .replace("\\","/"), The lcd function is also required.

I'll check later

AlexStz commented 5 years ago

Now all "args" all commands (lcd, cd, gt, rm, put...) need "posix" path (c:/User/Juwan). This is in function "parse_file_names()" and next -> "Class Tokenizer". All commands use "on local" or "on remote"(board) system. On remote (board) need ONLY posix paths. Need duplicate "parse_file_names()" for local system commands (lcd, rf, runfile...) (in Class Tokenizer-> validfnchars = "A-Za-z0-9%#~@/\$!*.+-\:\\" -> here added "\\"). Or completely replace function "__parse_file_names()" with your own.

AlexStz commented 5 years ago

Corrected valid_fnchars = "A-Za-z0-9_%#~@/\$!\*\.\+\-\:\\\\" -> here added "\\\\"

AlexStz commented 5 years ago

2019-05-20_111439 Errors none. (lines starting tokens: and rest: - for debugging)

junhuanchen commented 5 years ago

But I think a few questions.

windows is C:\

linux is /root

mac unknown.

Whether we need to judge a function or a regular expression by the system.

if os == win validfnchars = "A-Za-z0-9%#~@/\$!*.+-\:\\" elif os == linux validfnchars = "A-Za-z0-9%#~@/\$!*.+-\:"

Like this code.

Today 520 (is I love you) so I'll update it the day after tomorrow XD (521 to wo ai ni in Chinese)

AlexStz commented 5 years ago

I think that there is no need to divide into different "local" operating systems. And the remote is always "linux" (board). If there is no such path, now give error. valid_fnchars = "A-Za-z0-9_%#~@/\$!\*\.\+\-\:\\\\" - All valid characters in the path are listed here. Аf an unspecified character appears in the string (path from "args") -> "__parse_file_names(args)" give error "Invalid filename given: %s" ->since "tokenizer.tokenize(args)" was able to split the string by the missing in "valid_fnchars" character and return to "rest" the second part of the line. 2019-05-20_114930

I think that need only split parse_file_names on "local" and "remote" commands. Or need write another "check" function to test real paths depending on OS (replace "parse_file_names") with many-many code... :)

p.s. Chinese valentines day... :)

AlexStz commented 5 years ago

If you still want to implement a real path check of the local system, read to start: is_path_exists_or_creatable(). And python pathlib.

Beyond sanity. Beyond pain. You will find Python portability concerns. (Cecil Curry Copyrighted)

:)

junhuanchen commented 5 years ago

Maybe this is the best way. about is_path_exists_or_creatable() and python pathlib.

After that, we need to add some test cases to check the various paths, and I'll update unit_test for that.

junhuanchen commented 5 years ago

I think any system path should be converted back to Linux, as you say