Jump to content




Downloading files off GitHub (and how to use a repo)


17 replies to this topic

#1 mrdawgza

  • Members
  • 110 posts
  • LocationSouth Africa

Posted 16 December 2013 - 03:29 PM

This tutorial will show you how to make a github repository and download the files into your computer.
it's my first tutorial so...

Step One
You shall be needing a GitHub repository - head to www.github.com and create an account.
Then you should create a new repository.
The name can be anything, Tungsten OS or such anything!
And the description is optional.
You don't need the .gitignore and license features yet since you haven't really made Tungsten OS proper yet. It is still under development.

Step Two
With a GitHub repository located at www.github.com/youname/theRepositoryName you can continue on here.
Now I have a nifty little program called (not mine) SourceTree which you can get here.

Setting up SourceTree
Spoiler

The Installer

Note: You need the HTTP API enabled for this to work!
How to enable the HTTP API
Spoiler


Now, the file we shall be downloading is called 'startup', located at www.github.com/myName/repo/startup .
If you try to download that into ComputerCraft it'll show you all of the HTML details, which is useless - so we need the raw file which is found at
https://raw.github.com/me/repo/startup .
That is what we shall download.

So now to get, read and save 'startup' off GitHub, we shall use the code:
local download = http.get("https://raw.github.com/myName/repo/startup") --This will make 'download' hold the contents of the file.
local handle = download.readAll() --Reads everything in download
download.close() --remember to close download!

local file = fs.open("startup","w") --opens the file 'startup' with the permissions to write.
file.write(handle) --writes all the stuff in handle to the file 'startup'.
file.close() --remember to close download!
That is basically it!

Now putting that code in for each file is a mission, so you can put it into a local function: (in the installer)
This code will make sure it downloaded it, else if it didn't the installer will return false with an error message.
local function get(repoFile,saveTo)
local download = http.get("https://raw.github.com/myName/repo/repoFile") --This will make 'download' hold the contents of the file.
if download then --checks if download returned true or false
   local handle = download.readAll() --Reads everything in download
   download.close() --remember to close the download!
   local file = fs.open(saveTo,"w") --opens the file defined in 'saveTo' with the permissions to write.
   file.write(handle) --writes all the stuff in handle to the file defined in 'saveTo'
   file.close() --remember to close the file!
  else --if returned false
   print("Unable to download the file "..repoFile)
   print("Make sure you have the HTTP API enabled or")
   print("an internet connection!")
  end --end the if
end --close the function
Now call this function with:
get("startup","startup") --remember the quotation marks! (" ")

That is basically it for an advanced installer of GitHub. That is exactly what the pastebin get program does, it just doesn't run with a function and has the URL www.pastebin.com/raw?i= (or whatever)
and saves the raw.

If you need any questions just ask me. ALSO if the code I posted errors just tell me - I posted it without testing...

Edited by mrdawgza, 07 July 2014 - 10:19 AM.


#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 16 December 2013 - 05:05 PM

Why SourceTree and not git itself, or the git bash for Windows? Git is a pretty powerful tool, and you'd be better off knowing how to use it directly than tying yourself down to some GUI app.

#3 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 16 December 2013 - 06:22 PM

I can definitely confirm what Lyqyd is saying... I started out with with the GUI app, and was apprehensive to switch to command line, but NeverCast managed to convince me and I love him for it. Its much more powerful, and you end up just having much better control over your repos.

#4 distantcam

  • Members
  • 139 posts
  • LocationChunk 0

Posted 16 December 2013 - 06:48 PM

I'd also mention GitHub for Mac and Windows.

And as far as using the command line goes on Windows, installing SourceTree or GitHub for Windows is the easiest way to get the Git command line installed. Both provide access when you need to step outside the GUI.

#5 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 16 December 2013 - 06:57 PM

View Postdistantcam, on 16 December 2013 - 06:48 PM, said:

I'd also mention GitHub for Mac and Windows.
SourceTree is better than the GitHub GUI.

#6 mrdawgza

  • Members
  • 110 posts
  • LocationSouth Africa

Posted 17 December 2013 - 08:11 AM

View PostLyqyd, on 16 December 2013 - 05:05 PM, said:

Why SourceTree and not git itself, or the git bash for Windows? Git is a pretty powerful tool, and you'd be better off knowing how to use it directly than tying yourself down to some GUI app.

I sorta made this tutorial for someone new to GitHub and Git - So using a GUI would make it easier for them to understand.

#7 oeed

    Oversimplifier

  • Members
  • 2,095 posts
  • LocationAuckland, New Zealand

Posted 17 December 2013 - 04:55 PM

View PostOptimusSnorr, on 17 December 2013 - 08:11 AM, said:

View PostLyqyd, on 16 December 2013 - 05:05 PM, said:

Why SourceTree and not git itself, or the git bash for Windows? Git is a pretty powerful tool, and you'd be better off knowing how to use it directly than tying yourself down to some GUI app.

I sorta made this tutorial for someone new to GitHub and Git - So using a GUI would make it easier for them to understand.

I completely agree. Someone starting off with GitHub won't want to spend ages learning how to use the command line, they may decide to use it later on, but initially for the tasks they're doing it's probably not worth learning until they have a basic grasp on the idea. You have to learn to walk before you can run.

#8 awsmazinggenius

  • Members
  • 930 posts
  • LocationCanada

Posted 17 December 2013 - 08:39 PM

View Postoeed, on 17 December 2013 - 04:55 PM, said:

View PostOptimusSnorr, on 17 December 2013 - 08:11 AM, said:

View PostLyqyd, on 16 December 2013 - 05:05 PM, said:

Why SourceTree and not git itself, or the git bash for Windows? Git is a pretty powerful tool, and you'd be better off knowing how to use it directly than tying yourself down to some GUI app.

I sorta made this tutorial for someone new to GitHub and Git - So using a GUI would make it easier for them to understand.

I completely agree. Someone starting off with GitHub won't want to spend ages learning how to use the command line, they may decide to use it later on, but initially for the tasks they're doing it's probably not worth learning until they have a basic grasp on the idea. You have to learn to walk before you can run.
Agreed. I always used the GitHub web editor (copy-pasting from my editor) until the first time I needed to get a .png into a repo. Then I switched to the command line. Also, for getting files from GitHub into CC, I have always used raw.github.com . I'm not entirely sure that's the best way, though.

#9 Lemur

  • Members
  • 15 posts
  • Location*.*

Posted 22 December 2013 - 11:45 PM

If you intend to get into the Software world at all, learning Git is a requirement for most places. It would be advantageous to learn it, and honestly the command line will be a lot faster for you on that one.

As one of the most nightmarish things is undoing whatever bork in a repo you just made, this is bookmark worthy: http://sethrobertson...ixUm/fixup.html

In terms of API it would be worthwhile to note that effectively all you're doing is grabbing the raw (text) version of the file from Github. As to how to get all the files in there from a repo, I'd have to think about it. That would definitely be a beneficial feature, some form of functioning Git API Facade in Lua.

http://developer.git...repos/contents/

This looks promising as to a source for getting everything. If there's some form of JSON parser in Lua we could make it automatically fetch everything in a directory and effectively download everything you need in one go. Considering the API is HTTP Rest based, you just need to shoot it a get request to get the data you need to get the rest of the library.

Anyone up for trying to make a Git Facade for pulling down a whole repo? My Lua skills are less than par at this point, so I'm not sure what types of features it'd have for this. I'll do a bit of research and see what I can find out on it.

I suppose the question I'd need answered is can we parse JSON in CC? I'd rather not make a custom JSON parser unless absolutely necessary.

#10 awsmazinggenius

  • Members
  • 930 posts
  • LocationCanada

Posted 23 December 2013 - 09:20 AM

View PostLemur, on 22 December 2013 - 11:45 PM, said:

I suppose the question I'd need answered is can we parse JSON in CC? I'd rather not make a custom JSON parser unless absolutely necessary.
I just downloaded JSON4Lua from LuaForge - I am translating it into CC Lua. If you'd like, I can PM you when done. (I don't plan on a release of it specifically (though it is MIT, I could if I wanted), but it's really useful to have in awsmazingOS.

Edited by awsmazinggenius, 23 December 2013 - 09:21 AM.


#11 Lemur

  • Members
  • 15 posts
  • Location*.*

Posted 24 December 2013 - 12:21 AM

Is there a definitive guide on the differences? I come from Ruby but I could easily pick up Lua in any capacity for things like this. Ping me out and around if you have any projects on getting something like this done.

Why not just OS is on Github?

#12 distantcam

  • Members
  • 139 posts
  • LocationChunk 0

Posted 24 December 2013 - 01:34 AM

This JSON parser from ElvishJerricco worked well for me.

http://www.computerc...-computercraft/

#13 SpencerBeige

  • Members
  • 263 posts

Posted 24 June 2014 - 03:24 AM

thanks! this is great because now, i can make better installation files, this is great!
by the way, it says that my access is denied, how do i make it so i can access a website with https?

Edited by slow-coder, 24 June 2014 - 04:05 AM.


#14 skwerlman

  • Members
  • 163 posts
  • LocationPennsylvania

Posted 25 June 2014 - 02:52 AM

View Postslow-coder, on 24 June 2014 - 03:24 AM, said:

by the way, it says that my access is denied, how do i make it so i can access a website with https?
In the computercraft config, there's a whitelist for the http api. If you set it to '*' (without quotes) it will allow access to all sites.

#15 mrdawgza

  • Members
  • 110 posts
  • LocationSouth Africa

Posted 25 June 2014 - 11:16 AM

View Postslow-coder, on 24 June 2014 - 03:24 AM, said:

thanks! this is great because now, i can make better installation files, this is great!
by the way, it says that my access is denied, how do i make it so i can access a website with https?

The answer;

View Postskwerlman, on 25 June 2014 - 02:52 AM, said:

View Postslow-coder, on 24 June 2014 - 03:24 AM, said:

by the way, it says that my access is denied, how do i make it so i can access a website with https?
In the computercraft config, there's a whitelist for the http api. If you set it to '*' (without quotes) it will allow access to all sites.

however if you are playing on a server and cannot access the Computercraft config file simply ask the server manager/owner if he could change it for you.
In modpacks (like direwolf20) I think it is enabled on default.

Edited by Mr.DawG_ZA - OptimusSnorr, 25 June 2014 - 11:16 AM.


#16 Agoldfish

  • Members
  • 451 posts
  • LocationSome Fish Bowl in Ohio.

Posted 28 June 2014 - 11:58 PM

Now time to teach how to download branches. :P

#17 skwerlman

  • Members
  • 163 posts
  • LocationPennsylvania

Posted 29 June 2014 - 06:01 PM

View PostAgoldfish, on 28 June 2014 - 11:58 PM, said:

Now time to teach how to download branches. :P
Or from release tags. (This'd be really useful actually, now that I think about it...)
Or from specific commits.

#18 Agoldfish

  • Members
  • 451 posts
  • LocationSome Fish Bowl in Ohio.

Posted 29 June 2014 - 06:09 PM

View Postskwerlman, on 29 June 2014 - 06:01 PM, said:

View PostAgoldfish, on 28 June 2014 - 11:58 PM, said:

Now time to teach how to download branches. :P
Or from release tags. (This'd be really useful actually, now that I think about it...)
Or from specific commits.

View Postskwerlman, on 29 June 2014 - 06:01 PM, said:

View PostAgoldfish, on 28 June 2014 - 11:58 PM, said:

Now time to teach how to download branches. :P
Or from release tags. (This'd be really useful actually, now that I think about it...)
Or from specific commits.
Yeah, I'll have to look into that. :P





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users