revolunet / sublimetext-google-apps-scripts

SublimeText 2 plugin to edit your Google Apps Scripts
30 stars 10 forks source link

Plugin does not work #7

Open Buravchik opened 10 years ago

Buravchik commented 10 years ago

Log from fresh startup:

startup, version: 2221 windows x32 channel: stable executable: /C/Program Files/Sublime Text 2/sublime_text.exe working dir: /C/Windows/system32 packages path: /C/Users/User/AppData/Roaming/Sublime Text 2/Packages settings path: /C/Users/User/AppData/Roaming/Sublime Text 2/Settings source packages: 49 installed packages: 48, running PackageSetup Py_GetProgramName(): sublime_text.exe Py_GetExecPrefix(): C:\Program Files\Sublime Text 2 Py_GetProgramFullPath(): C:\Program Files\Sublime Text 2\sublime_text.exe Py_GetPath(): C:\Program Files\Sublime Text 2\python26.zip;C:\Program Files\Sublime Text 2\DLLs;C:\Program Files\Sublime Text 2\lib;C:\Program Files\Sublime Text 2\lib\plat-win;C:\Program Files\Sublime Text 2\lib\lib-tk;C:\Program Files\Sublime Text 2 Py_GetPythonHome(): C:\Program Files\Sublime Text 2 PackageSetup returned: -1 catalogue loaded found 4 files for base name Default.sublime-keymap found 1 files for base name Default.sublime-mousemap found 2 files for base name Main.sublime-menu Reloading plugin C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\CSS\css_completions.py Reloading plugin C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Default\comment.py Reloading plugin C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Default\copy_path.py Reloading plugin C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Default\delete_word.py Reloading plugin C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Default\detect_indentation.py Reloading plugin C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Default\duplicate_line.py Reloading plugin C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Default\echo.py Reloading plugin C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Default\exec.py Reloading plugin C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Default\fold.py Reloading plugin C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Default\font.py Reloading plugin C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Default\goto_line.py Reloading plugin C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Default\indentation.py Reloading plugin C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Default\kill_ring.py Reloading plugin C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Default\mark.py Reloading plugin C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Default\new_templates.py Reloading plugin C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Default\open_file_settings.py Reloading plugin C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Default\open_in_browser.py Reloading plugin C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Default\paragraph.py Reloading plugin C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Default\save_on_focus_lost.py Reloading plugin C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Default\scroll.py Reloading plugin C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Default\set_unsaved_view_name.py Reloading plugin C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Default\side_bar.py Reloading plugin C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Default\sort.py Reloading plugin C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Default\swap_line.py Reloading plugin C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Default\switch_file.py Reloading plugin C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Default\transform.py Reloading plugin C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Default\transpose.py Reloading plugin C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Default\trim_trailing_white_space.py Reloading plugin C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Diff\diff.py Reloading plugin C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\HTML\encode_html_entities.py Reloading plugin C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\HTML\html_completions.py Reloading plugin C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Package Control\Package Control.py plugin init time: 1.32996 loading bindings loading pointer bindings found 1 files for base name Default.sublime-theme theme loaded app ready pre session restore time: 3.02609 wrote startup cache, added files: 6 orphaned files: 0 total files: 96 cache hits: 90 startup time: 3.24853 (package setup was run) loaded 837 snippets reloading /C/Users/User/AppData/Roaming/Sublime Text 2/Packages/User/Package Control.sublime-settings Package Control: No updated packages ignored packages updated to: [Vintage, Google Apps Scripts] found 1 files for base name Default.sublime-theme reloading /C/Users/User/AppData/Roaming/Sublime Text 2/Packages/User/Preferences.sublime-settings found 1 files for base name Default.sublime-theme theme loaded theme loaded ignored packages updated to: [Vintage] found 1 files for base name Default.sublime-theme reloading /C/Users/User/AppData/Roaming/Sublime Text 2/Packages/User/Package Control.sublime-settings reloading /C/Users/User/AppData/Roaming/Sublime Text 2/Packages/User/Preferences.sublime-settings found 1 files for base name Default.sublime-theme Reloading plugin C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Google Apps Scripts\GoogleAppsScripts.py Traceback (most recent call last): File ".\sublime_plugin.py", line 62, in reload_plugin File ".\GoogleAppsScripts.py", line 17, in import ScriptsBrowser File ".\ScriptsBrowser.py", line 19, in import GoogleOAuth2 File "C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Google Apps Scripts\lib\GoogleOAuth2.py", line 4, in import httplib2 File "C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Google Apps Scripts\lib\httplib2init.py", line 95, in from iri2uri import iri2uri File "C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Google Apps Scripts\lib\httplib2\iri2uri.py", line 100 self.assertEqual("http://xn--o3h.com/%E2%98%84", iri2uri(u"http://\N{COMET}.com/\N{COMET}")) SyntaxError: (unicode error) \N escapes not supported (can't load unicodedata module) Reloading plugin C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Google Apps Scripts\ScriptsBrowser.py Traceback (most recent call last): File ".\sublime_plugin.py", line 62, in reload_plugin File ".\ScriptsBrowser.py", line 19, in import GoogleOAuth2 File "C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Google Apps Scripts\lib\GoogleOAuth2.py", line 4, in import httplib2 File "C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Google Apps Scripts\lib\httplib2init.py", line 95, in from iri2uri import iri2uri File "C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Google Apps Scripts\lib\httplib2\iri2uri.py", line 100 self.assertEqual("http://xn--o3h.com/%E2%98%84", iri2uri(u"http://\N{COMET}.com/\N{COMET}")) SyntaxError: (unicode error) \N escapes not supported (can't load unicodedata module) Reloading plugin C:\Users\User\AppData\Roaming\Sublime Text 2\Packages\Google Apps Scripts\SublimeHelper.py found 3 files for base name Main.sublime-menu theme loaded theme loaded

revolunet commented 10 years ago

very strange traceback. what the hell is "http://xn--o3h.com/%E2%98%84" ?? I dont have any windows to test sorry

Buravchik commented 10 years ago

it comes from line 100 of \lib\httplib2\iri2uri.py Looks like https://github.com/ipython/ipython/issues/1063 http://www.sublimetext.com/forum/viewtopic.php?f=3&t=3462

richy58729 commented 10 years ago

I don't know if you have found the solution in the meantime, but there is a work-around I'd like to share:

revolunet commented 10 years ago

thanks a lot @richy58729 for the feedback i will backport this fix into the code.

about your WindowsError can you tell about the related line number please ? i guess this is about the credentials.json file. or if you have the full traceback it can help.

richy58729 commented 10 years ago

Hi Julien,

Here's the traceback:


Traceback (most recent call last): File ".\GoogleAppsScripts.py", line 126, in callback File ".\GoogleAppsScripts.py", line 142, in file_selected File ".\SublimeHelper.py", line 24, in write WindowsError: [Error 32] The process cannot access the file because it

is being used by another process

----- Original Message ----- Subject: Re: [sublimetext-google-apps-scripts] Plugin does not work (#7) Date: Fri, 16 May 2014 03:31:40 -0700 From: Julien Bouquillon notifications@github.com

thanks a lot @richy58729 for the feedback i will backport this fix into the code.

about your WindowsError can you tell about the related line number please ? i guess this is about the credentials.json file. or if you have the full traceback it can help.


Reply to this email directly or view it on GitHub: https://github.com/revolunet/sublimetext-google-apps-scripts/issues/7#issuecomment-43317935

revolunet commented 10 years ago

thanks !

richy58729 commented 10 years ago

Oh, I have checked and the credentials.json file exists and seems to be filled with the correct data. Browsing Google Drive works just fine, only when trying to open a script file, does it generate that error. As to what's causing it and how to fix it, I have no clue so far. But, as you don't have Windows, I guess I'm on my own. Ah well...

revolunet commented 10 years ago

Ok, looks like this code is the root cause : https://github.com/revolunet/sublimetext-google-apps-scripts/blob/master/SublimeHelper.py#L20-L25

i try to rename a file which is not closed yet. different behaviour on Mac/Win.

will try to fix it this weekend

richy58729 commented 10 years ago

You are awesome!

Although I'm not really fluent in Python, I will try to give it a go also, with you being on Mac OS and thus not really able to reproduce the bug and how to fix it (with certainty, that is). Thanks for pointing me in the right direction as I didn't think about a file on the local file system being the culprit (which, come to think of it, of course makes much more sense, as it is a Windows error and thus likely to be confined to the local file system)..

If I'm successful to squash the bug, I'll post it here.

Thanks again in advance.

revolunet commented 10 years ago

maybe just closing the file before renaming it could help. or use another method from the "tempfile" module

may the force be with you :)

richy58729 commented 10 years ago

I don't really have a clue what I'm doing as I don't have any experience coding in Python, but I have a half-baked "solution" now: as long as a file with the same name isn't already open (i.e. Code.js, looks like Code.gs is automatically renamed to Code.js by your plugin, I guess so Sublime Text will use JavaScript syntax highlighting), this will work:

path2 = os.path.join(os.path.dirname(path), name)
if os.path.exists(path2):
     os.unlink(path2)
os.close(handle)
os.rename(path, path2)

If I already have a Code.js open from Google Drive into Sublime Text and try to open another Code.js, it will just silently fail... So as long I only open one file at a time (as the standard file name is Code.gs a.k.a. Code.js in Google Drive, a second file will probably have the same name as the first file), it's working OK.

At least now I can use Sublime Text as editor instead of the Google Apps Script editor, so for now, I can live with it, but I hope you can figure out a better solution than me in the long run...

revolunet commented 10 years ago

i just issued an untested little patch to force close the tempfile before renaming it. would be cool if you could test this patch and tell me if it fix the issue : 60e492c63ef2b9ec2d237cb26d566614f6dafafa

richy58729 commented 10 years ago

Sorry for not getting back to you sooner, but because another plugin I really liked wasn't working in Sublime Text 2, I decided to switch to Sublime Text 3, where your plugin doesn't work anyway, so I had to reinstall Sublime Text 2 just to test out your plugin...

It works fine, but:

Traceback (most recent call last):
  File ".\GoogleAppsScripts.py", line 126, in callback
  File ".\GoogleAppsScripts.py", line 142, in file_selected
  File ".\SublimeHelper.py", line 25, in write
WindowsError: [Error 183] Cannot create a file when that file already exists

So it does work as long as you don't open a second file with the same name. They all get saved in the same TEMP folder and thus only one file with that name can exist there. Maybe making a sub-folder within the TEMP folder will squash that bug?

richy58729 commented 10 years ago

Oh, just another thing: as your plugin doesn't delete the temp file in the TEMP folder for Code.gs/Code.js, trying to open it after starting Sublime Text 2 anew (without having that file open in the workspace), that error will occur also, so in order to open any Code.gs/Code.js file from Google Apps Script some time in the future, you have to manually delete the file Code.js from the TEMP folder first. Would be nice if your plugin would handle that automatically (which is IMHO another reason to make a sub-folder in the TEMP folder first).

diegoguimaraes commented 10 years ago

I can't get this plugin working either. After I installed it from package control, I got nothing related to the plugin in the Command Palette. Using a manual installation didn't work too. It just add the menu in package settings, Preferences-> Package settings->Google Apps Script. I tried from Ubuntu 14.04 and Window 7. Am I doing something wrong to use it? Do I need to set something up before? Thanks!

revolunet commented 10 years ago

@diegoguimaraes you're using sublime text version 2 right ?

could you please open view-> console in ST2 and you should see something related to the plugin (errors).

You can copy/paster the whole debug in ST2 then search for "Google" to find the revelant part and paste it here. Will be helpful to improve it.

thanks

diegoguimaraes commented 10 years ago

@revolunet yes, I'm using sublime 2. Here's the console debug output, the parts related to the apps script plugin:

Reloading plugin /home/diego/.config/sublime-text-2/Packages/Google Apps Scripts/GoogleAppsScripts.py Traceback (most recent call last): File "./sublime_plugin.py", line 62, in reload_plugin File "./GoogleAppsScripts.py", line 17, in import ScriptsBrowser File "./ScriptsBrowser.py", line 18, in import requests File "/home/diego/.config/sublime-text-2/Packages/Google Apps Scripts/lib/requests/init.py", line 58, in from . import utils File "/home/diego/.config/sublime-text-2/Packages/Google Apps Scripts/lib/requests/utils.py", line 15, in import io File ".\io.py", line 63, in ImportError: No module named _fileio Reloading plugin /home/diego/.config/sublime-text-2/Packages/Google Apps Scripts/ScriptsBrowser.py Traceback (most recent call last): File "./sublime_plugin.py", line 62, in reload_plugin File "./ScriptsBrowser.py", line 18, in import requests File "/home/diego/.config/sublime-text-2/Packages/Google Apps Scripts/lib/requests/init.py", line 58, in from . import utils File "/home/diego/.config/sublime-text-2/Packages/Google Apps Scripts/lib/requests/utils.py", line 15, in import io File ".\io.py", line 63, in ImportError: No module named _fileio Reloading plugin /home/diego/.config/sublime-text-2/Packages/Google Apps Scripts/SublimeHelper.py

Thanks!