-
Notifications
You must be signed in to change notification settings - Fork 44
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
Solving many bugs when using artisan #28
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ def run(self, *args, **kwargs): | |
self.args = [self.php_path, os.path.join(self.PROJECT_PATH, 'artisan'), 'generate:%s' % self.command] | ||
|
||
if os.path.isfile("%s" % os.path.join(self.PROJECT_PATH, 'artisan')): | ||
if self.command in ['model', 'seed', 'test', 'view', 'migration', 'resource']: | ||
if self.command in ['model', 'seed', 'test', 'view', 'migration', 'resource', 'scaffold']: | ||
# call function to do the work | ||
self.window.show_input_panel(self.fill_in, '', self.call_artisan, None, None) | ||
else: | ||
|
@@ -48,23 +48,23 @@ def call_artisan(self, value=''): | |
if os.name != 'posix': | ||
self.args = subprocess.list2cmdline(self.args) | ||
try: | ||
proc = subprocess.Popen(self.args, cwd=self.PROJECT_PATH, shell=False, stdout=subprocess.PIPE) | ||
proc = subprocess.Popen(self.args, cwd=self.PROJECT_PATH, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | ||
self.proc_status(proc) | ||
except IOError: | ||
sublime.status_message('IOError - command aborted') | ||
|
||
def proc_status(self, proc): | ||
if proc.poll() is None: | ||
sublime.set_timeout(lambda: self.proc_status(proc), 200) | ||
output = '' | ||
while proc.poll() is None: | ||
output += proc.communicate()[0] | ||
|
||
match = re.search(r'app/\w+/.*[.]php', output) | ||
if match: | ||
if not self.command == 'resource' and not self.command == 'scaffold': | ||
self.window.open_file('%s/%s' % (self.PROJECT_PATH, match.group(0))) | ||
sublime.status_message("%s generated successfully!" % self.command) | ||
else: | ||
output = proc.communicate()[0].decode('utf-8') | ||
match = re.search(r'/app/\w+/.*[.]php', output) | ||
if match: | ||
if not self.command == 'resource': | ||
self.window.open_file('%s%s' % (self.PROJECT_PATH, match.group(0))) | ||
sublime.status_message("%s generated successfully!" % self.command) | ||
else: | ||
sublime.status_message("Oh snap! generate:%s failed - %s" % (self.command, output)) | ||
sublime.status_message("Oh snap! generate:%s failed - %s" % (self.command, output)) | ||
|
||
class ArtisanCommand(sublime_plugin.WindowCommand): | ||
def __init__(self, *args, **kwargs): | ||
|
@@ -79,13 +79,13 @@ def run(self, *args, **kwargs): | |
def call_artisan(self, command): | ||
try: | ||
self.PROJECT_PATH = self.window.folders()[0] | ||
self.args = '%s %s %s' % (self.php_path, os.path.join(self.PROJECT_PATH, 'artisan'), command) | ||
self.args = [self.php_path, os.path.join(self.PROJECT_PATH, 'artisan')] + command.split(' ') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Popen arguments should be passed in as list rather than string:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had it as a list before but ran into some issues with the slashes iirc. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this specifically on Mac/Linux? I’ve been using this for several days now on Windows, and haven’t had any issues so far. That being said, I have just “php” as php path in the settings, using the environment variable (maybe that should be recommended for everyone using Windows?). I’m not entirely sure if it’ll still work if I type out the full path. Will try that later today. |
||
if os.name == 'posix': | ||
self.args = shlex.split(str(self.args)) | ||
|
||
if command: | ||
try: | ||
proc = subprocess.Popen(self.args, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
proc = subprocess.Popen(self.args, cwd=self.PROJECT_PATH, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | ||
self.proc_status(proc, command) | ||
except IOError: | ||
sublime.status_message('IOError - command aborted') | ||
|
@@ -95,21 +95,16 @@ def call_artisan(self, command): | |
sublime.status_message('Please open a Laravel Project') | ||
|
||
def proc_status(self, proc, command): | ||
if proc.poll() is None: | ||
sublime.set_timeout(lambda: self.proc_status(proc, command), 200) | ||
else: | ||
result = [x.decode('utf-8') for x in proc.communicate()] | ||
panel_name = 'artisan_output' | ||
panel = self.window.get_output_panel(panel_name) | ||
if not result[1]: | ||
if command == 'routes': | ||
panel.run_command('artisan_output', {'insert': result[0]}) | ||
self.window.run_command('show_panel', {'panel': 'output.' + panel_name}) | ||
sublime.status_message('artisan %s executed successfully' % command) | ||
else: | ||
panel.run_command('artisan_output', {'insert': result[1]}) | ||
self.window.run_command('show_panel', {'panel': 'output.' + panel_name}) | ||
sublime.status_message('artisan %s failed' % command) | ||
output = '' | ||
while proc.poll() is None: | ||
output += proc.communicate()[0] | ||
|
||
panel_name = 'artisan_output' | ||
panel = self.window.get_output_panel(panel_name) | ||
|
||
panel.run_command('artisan_output', {'insert': output}) | ||
self.window.run_command('show_panel', {'panel': 'output.' + panel_name}) | ||
sublime.status_message('executed artisan %s' % command) | ||
|
||
class ArtisanOutputCommand(sublime_plugin.TextCommand): | ||
def run(self, edit, insert): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was causing a deadlock if there was a sufficient amount of console output. See also http://docs.python.org/2/library/subprocess.html#subprocess.Popen.wait