As I was looking at a few issues, I coded this little feature which is something I kind of always wanted.
I like to see the modules grouped per package, very much like the admin module's page. By doing so, it's easier to find what module of each package is enabled.
I was thinking in doing this by default, but as the screen receives more information, for 80 columns the display is not very nice, so I added this feature by request of a --package command line argument.
| Comment | File | Size | Author |
|---|---|---|---|
| #37 | 654682-pm-list-package-8x.patch | 7.32 KB | hanoii |
| #33 | 654682-pm-list-package-7x.patch | 6.7 KB | hanoii |
| #29 | 654682-pm-list-package-6x.patch | 6.5 KB | hanoii |
| #28 | 654682-pm-list-package-5x.patch | 6.53 KB | hanoii |
| #27 | 654682-pm-list-package-4x.patch | 5.87 KB | hanoii |
Comments
Comment #1
hanoiiComment #2
hanoiiAttached is an updated patch.
The previous one had a bug (usort instead of uasort) and was including another fix of another issue.
Comment #3
moshe weitzman commentedI think this would look more readable if we printed the package title on its own line every time it changes to a new package. it would be *** Core - optional *** and so on. The problem is that the package column steals width from other info. My idea is worse for grep tho. Hmmm.
Also, this does not work on D7 but I think the problem is not with this code but with our D7 project handling in general.
Comment #4
hanoiiYeah, I agree about the width stealing problem, that's why I added it as an optional commandline argument, so if you have a wider console screen, you could use it.
Comment #5
jonhattanhanoii: at #678574-13: Add "pm-" namespace to all of the pm commands moshe suggests to remove module description to make room for project type alongside package name (that is not applicable for others than modules afaik).
Related issues:
* #679020: Extend `pm-list` to list modules, themes and profiles and filter by project status (enabled|disabled|uninstalled...)
* #677894: untangle pm_module_manage() a bit
Comment #6
hanoiiYeah, this issue aim not only to display the project type but to group (sort) by package name first and then project name. And yes it's probably referenced to just modules. If description is gone, this can be a default display and not an optional argument. I'll keep an eye on that issue and see if this patch needs updating.
Comment #7
moshe weitzman commentedSeems like this is still desireable.
Comment #8
jonhattanWithout description in the table now there's room for a new column "Package". This option is suitable for grep. For themes this column can show the base theme or none.
also --package to filter the list.
Comment #9
hanoiiSo, what do you say, package to be there by default, or by a command line? or the command line to filter, is that something already implemented somewhere else (a --filter command).
Want me to provide a patch for this or somebody else working at it?
Comment #10
moshe weitzman commentedThere by default. Perhaps truncate after 20 chars? not sure ... As jonhattan suggests, we should add a --package option which filters similar to --status
Comment #11
hanoiiOk, here's the patch following the latest changes on drush, a few notes on this patch:
- Sorting of the projects happens by default, I guess this can be removed, although it gives a more coherent output. (Sort criteria: project type, project package, project name).
- I haven't truncated anything, it doesn't look that bad, but let me know if that's needed when reviewing, and also, if there's a drush way of doing it.
- --package supports multiple values as #725686: enhancements for --type, -status and --package, multiple values and case insensitive filters. The package column is displayed in two situations, if none or more than one filter was given. Now that I think of it, it may not be that useful, let me know otherwise. If you like this approach, however, the --status filter patch of the previous issue would probably need some similar logic as this one. Shall I remove the package column altogether when one or more packages were used as filters?
Comment #12
greg.1.anderson commentedThis works well, and I wouldn't be opposed to it being committed as-is. Some minor optional suggestions.
My opinions.
Comment #13
moshe weitzman commentedYes, this sounds like very good feedback
Comment #14
hanoiiOne question before I get to look at the feedback.
1. The "Other" should be only something handled on the display of the status or you'd prefer this to be part of the actual $project object when loading it?
2. Not sure as I never checked this out for D7, but isn't there profiles listed as well? (I think I heard it somewhere). If so, do they have packages? Or would those be displayed as Profile?
3. Probably not needed any more. right.
Comment #15
greg.1.anderson commentedYou should put "Other" into $project so that it sorts in the same order it does on the "modules" page (with the "other" section in alphabetical order per 'other').
Comment #16
hanoiiI don't need to really put it in the $project object, that's really changing some deeper API, if preferred, I look it up. But I can work out the sorting and the display of Other withing the pm list and the sorting function.
Comment #17
greg.1.anderson commentedThat sounds okay.
Comment #18
jonhattan* Drupal set "Other" for the package name in the theme layer (see theme_system_modules()). It also sort by package name in this function. I don't like to set it in drush up in the api call (drush_get_modules() or drush_get_projects()) because it introduces some overhead not needed by other commands relying in drush_get_modules() or drush_get_projects().
* I've seen an inconsistency in drush_pm_info_module() as it sets the package to "none" instead of Other. It was introduced by #679832: pm-info: show info for one or more projects.. Please hannoi fix this in your patchs for this issue.
* Removing the project type and using Package column for this seems not necessary to me. I proposed in #8 to use the package column in themes to show the base theme. This is of interest to obtain all themes based on zen or fusion and do something with them when a new version of the base theme is available. I think this is the best way for drush to provide this info.
* Profiles. Probably I told this in some of the closed issues related to pm-list or pm-info. Nothing was done. Lets do it in a new issue.
Comment #19
hanoiiWell, I tried to cover most things requested on this issue, including the inconsistency reported by jonhattan on #18.
One some small different things I did:
- For themes, if a base theme is declared, that's used for the package column, if not, Base is displayed (rather than Other).
I also update the help a little bit, so you may want to review that.
Comment #20
hanoiiSorry, some small further changes I missed in the previous patch:
- The use of 'Base' was not used the same way on the sorting and the display, now it is.
- Use of dt() around 'Base' and 'Other'
Comment #21
hanoiiComment #22
moshe weitzman commentedI get
Comment #23
hanoiiAre you using the latest patch (3x). What version of php? I don't get that warning and I am certainly not modifying the array in the function. I really don't get that warning.
EDIT: Even more, I don't find any useful mention of that warning on google at all, which is rather strange.
Comment #24
moshe weitzman commentedThat error is with Drupal 7 using latest version of the patch.
On D6, I am seeing many repeats of : WD php: Undefined index: package in [error]
/Users/mw/contributions/modules/drush/commands/pm/pm.drush.inc on line 50.
Using php 5.2.11
Comment #25
hanoiiReally strange. D7 I haven't really tested, I will though. But definitely on D6 and without any errors or warnings. I guess that one might be one way I am using to define a variable name which may not be working. Strange it worked on my side though, php 5.2.12 here. Will try to rework that bit at least for D6 and check that error on D7.
Comment #26
jonhattanI have not tested it yet but reviewing the code I see:
* the usage of variable variables ($$) is a unnecessary obfuscation. You can use instead
foreach (array($a, $b) as $item). I also think a duplication of code in this case is not too bad.* This piece of code in drush_pm_list() seems a duplicate:
* I think you can also use empty() instead of isset() || == ''.
* It would be great if the fix for drush_pm_info() also sets the base theme as package name for themes.
So I propose to create a new function
drush_pm_get_projects()that basicly calls to drush_get_projects() and then set's the package name. pm-list and pm-info will use it. This can also be done up in drush_get_projects() but I said in #18 this is not convenient as other code calling drush_get_projects() don't need it and is a unnecesary overhead. Perhaps it is not a remarkable overhead we can live with.Note you can also use strcasecmp() for a case insensitive comparison.
Comment #27
hanoiiOK, I followed most johanttan suggestions, with the following comments/changes:
- I created the drush_pm_get_projects() functions as he proposed. IMHO, I also like this approach rather than modifying drush_get_projects() not that much because of the overhead, but drush_get_projects() seems more as a wrapper function to low-level environment-specific functions, and I guess that specific logic for pm-commands should be within the pm plugin/module, whatever this is called within drush :). I do have a question about this, I am using this function on pm-list and pm-info only, but drush_get_projects() is called in a few other places within the pm module, what should be do there?
- I slightly changed the way the $type filter worked before, by resembling exactly the way status filter works. Before it was calling
drush_get_' . $type . 's', but with the new function explained above, I'd rather don't do this, and just filter types in the foreach {} just as we do with any other filter, with only single call to drush_pm_get_projects().- Sort function is a lot simpler now, so I hope moshe will find no errors.
- Tested on D5, D6 and D7
I haven't done anything around this yet. Again, IMHO, base theme is base theme. Although we are using the package column to build a coherent display of themes and modules, package is not a familiar term within themes, so I rather stick with Base theme (and that's being displayed on the info already). Maybe just for semantic sake, we could call the Package column on the display Package/Base theme, but I don't think that's even necessary.
Comment #28
hanoiiI take a few things back from my previous post, I have reconsidered a few things by looking a bit further into D7.
There is a package entry now on the info files for themes on D7 (Core themes are packaged as Core). So from that point of view, I think using the base theme for the package column on the sm command is not appropriate. I rather stick to package for all version of drupal, and use 'Other' for those themes with no packages.
With this, the idea of filtering by all themes based on one base theme (zen for example) is not there any more, but if that's a feature you'd like to have, I rather code it as another filter (--basetheme) rather than using a --package filter for mixed purposes, even more when on D7 you have both things on themes (package and base theme).
So here's this new more standard approach, adding Other to both module and themes as package if there's none. I now did add the Package info to the pm-info of themes and also fixed an error in the display of the Base theme there.
Comment #29
hanoiiUps, my bad, removed on this patch.
Powered by Dreditor.
Comment #30
greg.1.anderson commentedI haven't reviewed the patch, but I thought I would say that I agree that base theme should be a separate concept from packages. I don't think that base theme is too important myself, and for my part would be satisfied if that were handled as a separate issue.
Comment #31
hanoiiComment #32
jonhattanI agree with removing base theme from this issue, mainly after hanoii has found that in D7 themes can be grouped in packages.
hanoii:
* $data['Package'] can be refactored up to drush_info_project(), enclosed by
if (($info->type == 'module')||($major_version >= 7)) {}* pm-enable/disable functions don't need drush_pm_get_projects() as they do nothing with packages.
Comment #33
hanoiidone, although not needed to enclosed it by that if condition, because package is there (added by drupal_pm_get_projects() for everything if there's none defined).
While I am here, and probably for another issue, but if you all want I don't mind adding it to this patch, I think having the output of the pm-info command alphabetically sorted is a better looking approach, although the title should probably go first.
Comment #34
greg.1.anderson commentedChanges to pm-info output should be discussed in a separate issue (but I for one do not think that alphabetized output is appropriate there).
Comment #35
moshe weitzman commentedAlmost there.
typo
we can do return drupal_set_error all on 2 line. i know thats existing code, but needs fixing.
this is debug code? please remove.
space between pm- and commands
Powered by Dreditor.
Comment #36
hanoiiyou mean removing drush_log(dt('Aborting')) and doing return set error, you surely meant 1 line, didn't you?
Yes, that was there already, I just moved it, but I'll remove it.
Comment #37
hanoiiDone with all your requests and fixed one slipped through bug in which the type column was being output regardless of the presence of --type .
Comment #38
hanoiiComment #39
moshe weitzman commentedCommitted. many thanks for your persistence, hanoii.
I think it would be nice to add a strtolower() so that --status=Enabled and --package=core would work as expected.
Comment #40
hanoiiI am glad to help :)
Follow up patch on #725686: enhancements for --type, -status and --package, multiple values and case insensitive filters