Models for the scancode project app

June 12, 2017 · 4 mins read
Categories: GSoC-2017 |

code: https://github.com/nexB/scancode-server/commit/5b2ee1bfbff478dcd720b0797e30838b53fcddae

Hello there!

So this is my first post in which I am going to be talking about Google Summer of Code-2017. Yes, it’s true I have selected for GSoC-2017. My project is to create a RESTful API for an organisation called AboutCode. In this post and some coming posts, I will try to write the things that I learn in the way of making the project. I am trying to write all the things to retain as many things as possible.

It has been the second week since the things started and we are still on the models part. It is difficult for the people who don’t know Django. But anyone who has worked on an MVC(Model-View-Controller) framework will be easily able to understand what I am trying to say.

In this post, I am going to share what thought made me write these models in particular. I have tried to achieve as higher normalisation as I could have done.

It is bad strictly start writing the code without discussing the situation. This helps to understand the situation well.

First of all, I should be telling a little about what the software does. The main software grabs the code and gives the output regarding the things like licences, copyrights, packages and other details of the code given as command line argument.

Here I will be sharing a single file output JSON generated by the software.

 `"scancode notice": "Some notice and a disclaimer",` `"scancode_version": "version_of_scancode_used", ` `"files_count": 1, ` `"files": [` `  {` `    "path": "/home/ranvir/Doc...", ` `    "scan_errors": ["errors_if_any",], ` `    "licences":[{}], ` `    "copyrights":[{}], ` `    "packages": [{}]` `  }` `]`
Now our work is to create a website that can take URL/local code as an input and show the result in graphical form. Pretty easy right?

So starting from the first task i.e. to create the models( if you are not familiar with MVC and still reading this - it is the task of creating the database in the normalised form). Before that, we did a lot of basic stuff that was related to creating the installation documentation. Setting virtual environments and much more. But the first big task under the hood was to create the models.

I had assigned the time of 2 weeks for this. So somehow we are running late for the task but I hope that we will manage somehow.

Firstly we were making the user table the base of every model and try to grab it into every other table in the database. But then our mentor said that in the website we are going to allow the anonymous scanning. This allowed me to add the concept of guests and users. In this way, we can keep everything almost similar and make least changes.

The next few bulleted points will create one table each.

  • The first table checks whether it is a URL scan or the code is being scanned from the local. This will help us differentiate between the two as the two need to store different things. We need to store URL for the scan from URL and path or directory name for the local scan. This is the most basic table and it associates a scan ID to each and every scan.

  • The next table will take care of the status of the person who applies the command. It can either be a authenticated user or it can be a guest. I have attached the scan ID with the user type.

  • The next table will store the URL for the scan applied by passing an URL.

  • Another table will store the path from local where the code is passed to the system.

  • One more table will store more attributes of the code like code base size, number of files

  • The result table will store the most basic results of the scan like scan errors, file name, file path and an Id for each file.

All the above-discussed tables will have a scan ID as foreign key except the first table which is having it as a primary key.

  • Next three tables will have file ID as a foreign key. The tables are licences, copyrights and packages.
We will definitely need few more models like the user Information model and some other which I am not able to think for now.

The other models can be made as the requirements changes.

Please share your Feedback:

Did you enjoy reading or think it can be improved? Don’t forget to leave your thoughts in the comments section below! If you liked this article, please share it with your friends, and read a few more!

We don't share your details with others