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

Added basic importing function for exported lists! #2105

Closed
wants to merge 10 commits into from
Closed

Added basic importing function for exported lists! #2105

wants to merge 10 commits into from

Conversation

yigitemres
Copy link
Contributor

@yigitemres yigitemres commented Mar 8, 2018

Added basic importing function for exported lists! #1863
Feel free to fix any mistakes!
PS: I'm very new to ps1 scripting. Any suggestion can take time! 😄

{
if($line -ne "") #Checks empty line!
{
$appslist += $line.Split()[0] + " "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we have duplicate packages on the list or dependency of some package and the package itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate packages are also going to into list but, because of the nature scoop install they are not installed. But you are right, duplicates are trying to install by this script. I will look into it. Thx for your comments! 🥂



$filePaths = $args
importApps(createAppsList($filepaths))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should report %ERRORLEVEL% with result of the operation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add this too. Thx again! 👍

@rasa
Copy link
Member

rasa commented Mar 9, 2018

Can import ignore lines that start with a # or ; char?

@yigitemres
Copy link
Contributor Author

yigitemres commented Mar 9, 2018

@rasa Nope currently, but thx to you it will. 🥂
Edit: It's done!

┌[⚡ yigit] [10:46]
└[~\Desktop]> cat .\kdiff3.txt
#kdiff3
kdiff3

#
;

;kdiff3# #123
┌[⚡ yigit] [10:46]
└[~\Desktop]> cat .\unzip.txt
  unzip
 #unzip
unzip
#unzip
;;unzip
#;unzip
;#unzip
 unzip
┌[⚡ yigit] [10:46]
└[~\Desktop]> scoop import .\kdiff3.txt .\unzip.txt
kdiff3
unzip

@rasa
Copy link
Member

rasa commented Mar 9, 2018

Since scoop export says it Exports (an importable) list of installed apps, scoop import should be able to consume its output, and act accordingly. To that end, we may want to consider that scoop import should:

  1. Install globally, if *global* is found.
  2. Install the 32bit version, if {32bit} is found.
  3. Add the appropriate bucket, if [bucket] is found. For non-standard buckets, this should fail (until we add the bucket location to the export file).
  4. Install “url” apps, if a [url] app is found.
  5. Consider supporting the alternate bucket convention bucket/appname.
  6. Consider supporting pinning of specific versions, using appname@version.
  7. Consider maybe adding flags to quit on the first failure, or ignore all failures and plow on.
  8. Gracefully ignore apps that are already installed.
  9. Consider adding switches to either report/fail, or uninstall/reinstall, if the installed app is not the same as the one listed in the import file (different bucket/url, architecture, or globalness ).

Have I captured everything? @r15ch13?

@yigitemres
Copy link
Contributor Author

@rasa Thx for suggestions. 1 and 2 is done! As I said earlier, I'm pretty new to PS scripting but I try my best. 🥂

@r15ch13
Copy link
Member

r15ch13 commented Mar 9, 2018

@rasa sounds about right.
6. export has to be modified so it will output this info
7. "plowing" through might be difficult because of the bad error handling 😢
8. scoop install does this already

@yigitemres I don't want to be rude, but this https://blog.codinghorror.com/flattening-arrow-code/ might be a good read for you. 😃

@yigitemres
Copy link
Contributor Author

yigitemres commented Mar 9, 2018

@r15ch13 It could be worse. It could be spaghetti with switch cases and arrow code! 🤣 My first ever C++ homework is resulted with spaghetti code and I had to rewrite it just day before the deadline!

I just write this sake of QoL. It will be possibly deleted or changed (if it is ever merged!) in time. I maybe calling these ifs as function (or found clever way to check string for multiple case with ease) in order to become a little more easy to read.

Any fix or suggestions are welcomed as always!
(BTW, If someone had already create import function, please create pull request. I will be happily delete this. All I want to achieve is that eliminating issues and contributing this wonderful project.)

@yigitemres
Copy link
Contributor Author

@rasa * for wildcards. We are both wrong. 😆 It should be *{32bit}*. (When apps name like "dasapp32bit", it was passed as --arch 32bit)

Thx for warning. 🥂

@rasa rasa mentioned this pull request Mar 12, 2018
try {
scoop install $Matches.url $globalArgs.TrimEnd(" ") $archArgs.TrimEnd(" ")
}
catch {
Copy link
Contributor Author

@yigitemres yigitemres Mar 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot figure out how to catch if $Matches.url not exist or not reachable? If anybody have suggestions, I'm very happy to hear it!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could check status code of the url HEAD

PS > Invoke-WebRequest -Uri 'community.spiceworks.com' -Method 'HEAD' | select StatusCode

StatusCode
----------
       200

@ScoopInstaller ScoopInstaller deleted a comment Oct 1, 2018
@nitrocode
Copy link
Contributor

nitrocode commented Oct 14, 2018

Will there be a Scoopfile similar to Brewfile where it will contain both command line installs and installs from its extras and other buckets?

I'm in favor of the # prefix instead of the old ; way. # seems to be more consistent with powershell and other languages where as the ; reminds me of ini files.

also if that's true, will the exported file also auto-add whatever buckets are required? nvm just saw #3 on the list in @rasa's post.

Thanks for all the hard work on this.

else {
return $false
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe above can be reduced to this.

function checkFileExt ($file) {
    return ([IO.Path]::GetExtension($file) -eq ".txt")
}

The above simplification can be applied to functions below and would make the code more concise and thus make it more readable.

@scadu
Copy link

scadu commented Feb 2, 2019

What's the status of this merge request? I see that @yigitemres removed his repository.

I started playing with scoop export trying to install package from array when item not installed.
The only property available from scoop export seems to be Length which is not very useful, but most probably I'm missing something.

import would be really useful for provisioning. I might take a look if no one is interested in introducing this feature. Please note that I haven't touched PowerShell before except my deploy script.

@yigitemres
Copy link
Contributor Author

yigitemres commented Feb 3, 2019

What's the status of this merge request? I see that @yigitemres removed his repository.

"I will be Bach" Arnold, probably...

I will fork again and work on it. If anyone comes with cleaner version (which you should 😃) I will be happy. My main aim to try to implement this feature because of two reasons. First one is QoL change and the second one is that learning PS.

Thanks for all ideas, suggestions and warnings. I hope that we will see this feature in the near future. 🥂

@yigitemres
Copy link
Contributor Author

yigitemres commented Apr 13, 2020

NecroBump?!

Hi guys, It's been a long time. I remember that we have unfinished business with this unimplemented feature. I will be very happy if you can help me. I'm gonna try to add all(?) previously mentioned features (I have some objections about some of them) with clean code. If you have suggestions, please comment. 🥂 For a testing purposes I need something. Can somebody export of their scoop list and paste it here if;

  • The person installed app from json file.
  • The person installed app from manifest url.

I'm using WSLGentoo as a scoop replacement. Because of this, I need these exports for testing purposes. Installing scoop apps with many different conditions is a real burden for me for now. 😢

I hope that this will finished really soon with your helps.

Have a nice day! 🤗

@yigitemres
Copy link
Contributor Author

Final NecroBump!

@scadu If you accept I have a mission for you. (Mission Impossible intensifies 😁)

I think that no one interest with import function and I'm fully migrated from this package manager to another. If anyone have better solution please pr.

Have a nice day! 🥂

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

Successfully merging this pull request may close these issues.

6 participants