Skip to content

Commit

Permalink
Updated to v1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tanaikech committed Oct 27, 2018
1 parent 30ab370 commit c750803
Show file tree
Hide file tree
Showing 19 changed files with 1,010 additions and 148 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Features of "ggsrun" are as follows.
1. **[Downloads spreadsheet, document and presentation, while executes GAS, simultaneously.](help/README.md#DownloadFiles)**
1. **[Downloads files from Google Drive and Uploads files to Google Drive.](help/README.md#UploadFiles)** <sup><font color="Red">Updated! (v1.4.1)</font></sup>
1. **[Downloads standalone script and bound script.](help/README.md#DownloadFiles)** <sup><font color="Red">Updated! (v1.4.0)</font></sup>
1. **[Downloads all files and folders in a specific folder.](help/README.md#DownloadFilesFromFolder)** <sup><font color="Red">Updated! (v1.5.0)</font></sup>
1. **[Upload script files and create project as standalone script and container-bound script.](help/README.md#UploadFiles)** <sup><font color="Red">Updated! (v1.4.0)</font></sup>
1. **[Update project.](help/README.md#Update_Project)** <sup><font color="Red">Updated! (v1.4.0)</font></sup>
1. **[Retrieve revision files of Google Docs and retrieve versions of projects.](help/README.md#RevisionFile)** <sup><font color="Red">Updated! (v1.4.0)</font></sup>
Expand Down Expand Up @@ -99,6 +100,7 @@ Completed!
1. [Executes GAS with Values and Downloads File](help/README.md#ExecutesGASwithValuesandDownloadsFile)
1. [Executes Existing Functions on Project](help/README.md#ExecutesExistingFunctionsonProject)
1. [Download Files](help/README.md#DownloadFiles)
1. [Downloads all files and folders in a specific folder.](help/README.md#DownloadFilesFromFolder)
1. [Upload Files](help/README.md#UploadFiles)
1. [Show File List](help/README.md#ShowFileList)
1. [Search Files](help/README.md#SearchFiles)
Expand Down
18 changes: 8 additions & 10 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,21 @@ Will you want to develop GAS on your local PC? Generally, when we develop GAS, w
4. Downloads spreadsheet, document and presentation, while executes GAS, simultaneously.
5. Upload files to Google Drive. When files are uploaded, also they can be converted by options.
5. Downloads files from Google Drive and Uploads files to Google Drive.
6. Creates, updates and backs up project of both standalone type and bound script type.
6. Downloads standalone script and bound script.
7. Creates Google Docs (Spreadsheet, Document, Slide and Form) and create bound script in the created Google Docs.
7. Downloads all files and folders in a specific folder.
8. Downloads files from Google Drive and Uploads files to Google Drive. Also container-bound scripts can be downloaded.
8. Upload script files and create project as standalone script and container-bound script.
9. Downloads revision files from Google Drive.
9. Update project.
10. Rearranges files in project of both standalone type and bound script type.
10. Retrieve revision files of Google Docs and retrieve versions of projects.
11. Modifies Manifests (appsscript.json) in project.
11. Rearranges scripts in project.
12. Remove files in the project of both standalone type and bound script type.
13. Retrieve revision file list and revision data.
12. Modifies Manifests in project.
You can see the release page https://github.com/tanaikech/ggsrun/releases
Expand Down
18 changes: 17 additions & 1 deletion ggsrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func main() {
app.Author = "Tanaike [ https://github.com/tanaikech/ggsrun ] "
app.Email = "[email protected]"
app.Usage = "Executes Google Apps Script (GAS) on Google and Feeds Back Results."
app.Version = "1.4.1"
app.Version = "1.5.0"
app.Commands = []cli.Command{
{
Name: "exe1",
Expand Down Expand Up @@ -163,10 +163,26 @@ func main() {
Name: "rawdata, r",
Usage: "Save a project with GAS scripts as raw data (JSON data).",
},
cli.BoolFlag{
Name: "zip, z",
Usage: "Create a zip file including all scripts of a GAS project. Please use this for downloading a GAS project.",
},
cli.StringFlag{
Name: "deletefile",
Usage: "Value is file ID. This can delete a file using a file ID on Google Drive.",
},
cli.BoolFlag{
Name: "overwrite, o",
Usage: "When filename of downloading file is existing in directory at local PC, overwrite it. At default, it is not overwritten.",
},
cli.BoolFlag{
Name: "skip, s",
Usage: "When filename of downloading file is existing in directory at local PC, skip it. At default, it is not overwritten.",
},
cli.BoolFlag{
Name: "showfilelist, l",
Usage: "When files from a folder are retrieved, file list is returned using this option. When this is used, files are not downloaded.",
},
cli.BoolFlag{
Name: "jsonparser, j",
Usage: "Display results by JSON parser",
Expand Down
106 changes: 105 additions & 1 deletion help/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ggsrun
- Executes GAS with Values and Downloads File
- Executes Existing Functions on Project
- Download Files
- Download All Files and Folders in Specific Folder
- Upload Files
- Show File List
- Search Files
Expand Down Expand Up @@ -69,6 +70,8 @@ Features of "ggsrun" are as follows.

1. **[Downloads standalone script and bound script.](#DownloadFiles)**

1. **[Downloads all files and folders in a specific folder.](#DownloadFilesFromFolder)**

1. **[Upload script files and create project as standalone script and container-bound script.](#UploadFiles)**

1. **[Update project.](#Update_Project)**
Expand Down Expand Up @@ -890,7 +893,8 @@ $ ggsrun d -f filename -e pdf

You can convert only from Google Docs Files (spreadsheet, slide, documentation and so on). For example, you cannot convert image files and text data.

When you download project files which are standalone script and container-bound script, you can use the option of ``--raw``. You can download raw files of project by this.
- When you download project files which are standalone script and container-bound script, you can use the option of ``--raw``. You can download raw files of project by this.
- When you download a project file, when you use the option ``--zip`` or ``-zip``, you can download the prject as a zip file. This zip file has all scripts in the project. This option was added at v1.5.0.

~~~bash
$ ggsrun d -i fileId -r
Expand All @@ -912,6 +916,106 @@ You can also delete files using file ID.
$ ggsrun d --deletefile [fileId]
~~~

<a name="DownloadFilesFromFolder"></a>
### 6-1. Download All Files and Folders in Specific Folder
From version 1.5.0, ggsrun got to be able to download all files and folders in the specific folder in Google Drive. The same folder structure of Google Drive is created to the local PC.

**Run :**

~~~bash
$ ggsrun d -f foldername
~~~

or

~~~bash
$ ggsrun d -i folderid
~~~

- When the option ``--jsonparser`` or ``-j `` is used like ``$ ggsrun d -f foldername -j``, you can see the progress of download. Other options are the same with those of download.
- When the option ``--showfilelist`` or ``-l`` is used, only the file list and folder structure can be retrieved as JSON object. In this case, no files and folders are downloaded.
- When the option ``--overwrite`` or ``-o`` is used, when the duplicated files in the downloaded folder on the local PC are found, the downloaded files are overwritten.
- When the option ``--skip`` or ``-s`` is used, when the duplicated files in the downloaded folder on the local PC are found, the downloaded files are skipped and not saved. This can be used to know whether the files with new filename were created in the folder of Google Drive.
- About the folder, you can download from not only the folders in your Google Drive, but also the shared folders in other Google Drive. When you want to download the files from the shared folder, please use the folder ID of the shared folder.
- When the files and folders are downloaded, the folder structure in Google Drive is also created to the working directory on the local PC.
- When the project of the standalone script script type is downloaded, it is created as a zip file. In the zip file, all scripts are included.

#### Sample:
![](images/downloadFolder_sample.png)
As a sample, it supposes that it downloads the files from the above structure. The command is as follows.

~~~bash
$ ggsrun d -f sampleFolder1 -j
~~~

By this command, all files with the folder structure ot the above figure are created in the working directory on local PC. When the command is run, the following result is returned. When ``-j`` is not used, only JSON object is returned.

~~~bash
$ ggsrun d -f sampleFolder1 -j
Files are downloaded from a folder 'sampleFolder1'.
Getting values to download.
Download files from a folder 'sampleFolder1'.
There are 10 files and 6 folders in the folder.
Starting download.
Now downloading 'Spreadsheet1.xlsx' (bytes)... 3595
Now downloading 'Spreadsheet2.xlsx' (bytes)... 3595
Now downloading 'Spreadsheet4.xlsx' (bytes)... 3595
Now downloading 'Spreadsheet3.xlsx' (bytes)... 3595
Now downloading 'Document1.docx' (bytes)... 6097
Now downloading 'image1.jpg' (bytes)... 958546 / 958546
Now downloading 'Slides1.pptx' (bytes)... 31733
Now downloading 'Spreadsheet5.xlsx' (bytes)... 3595
Project file 'StandaloneProject1.gs' is downloaded.
Now downloading 'Text1.txt' (bytes)... 50000000 / 50000000
{
"id": "### folderId ###",
"name": "sampleFolder1",
"mimeType": "application/vnd.google-apps.folder",
"parents": [
"### parent folderId ###"
],
"webViewLink": "https://drive.google.com/drive/folders/###",
"createdTime": "2000-01-01T00:00:00.000Z",
"modifiedTime": "2000-01-01T00:00:00.000Z",
"lastModifyingUser": {
"displayName": "Tanaike",
"emailAddress": "mailaddress"
},
"owners": [
{
"displayName": "Tanaike",
"permissionId": "###",
"emailAddress": "mailaddress"
}
],
"message": [
"Files were downloaded from folder 'sampleFolder1'.",
"File was downloaded as 'Spreadsheet1.xlsx'. Size was 3595 bytes.",
"File was downloaded as 'Spreadsheet2.xlsx'. Size was 3595 bytes.",
"File was downloaded as 'Spreadsheet4.xlsx'. Size was 3595 bytes.",
"File was downloaded as 'Spreadsheet3.xlsx'. Size was 3595 bytes.",
"File was downloaded as 'Document1.docx'. Size was 6097 bytes.",
"File was downloaded as 'image1.jpg'. Size was 958546 bytes.",
"File was downloaded as 'Slides1.pptx'. Size was 31733 bytes.",
"File was downloaded as 'Spreadsheet5.xlsx'. Size was 3595 bytes.",
"StandaloneProject1.gs has 4 scripts.",
"4 scripts in the project were saved as 'StandaloneProject1.gs.zip'.",
"File was downloaded as 'Text1.txt'. Size was 50000000 bytes.",
"There were 10 files and 6 folders in the folder."
],
"TotalElapsedTime": 12.345
}
~~~


> **IMPORTANT :**
> As a limitation, the project ID of the container-bound script still cannot be retrieved using the file ID of Google Docs by Drive API and Apps Script API. By this situation, only the projects of the container-bound script type cannot be downloaded. When the container-bound script can be retrieved from file ID of Google Docs, the backup of folder will be completely done.
> I have already reported about this situation at [https://issuetracker.google.com/issues/111149037](https://issuetracker.google.com/issues/111149037).


<a name="UploadFiles"></a>
## 7. Upload Files
ggsrun can upload local files to Google Drive. The files also include GAS projects and scripts.
Expand Down
13 changes: 12 additions & 1 deletion help/UpdateHistory.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ggsrun
- If the environment variable (**``GGSRUN_CFG_PATH``**) is set, ggsrun.cfg is read using it.
- If it is not set, ggsrun.cfg is read from the current working directory. This is as has been the way until now.
- This is the response for some requests.
- This incofmation was added to [here](help/README.md#environmentvariable).
- This information was added to [here](help/README.md#environmentvariable).

* v1.2.2 (July 12, 2017)

Expand Down Expand Up @@ -110,6 +110,17 @@ ggsrun
- ``$ ggsrun u -f filename -chunk 10``
- This means that a file with filename is uploaded by each chunk of 10 MB.

* v1.5.0 (October 27, 2018)
1. [From this version, ggsrun got to be able to download all files and folders in the specific folder in Google Drive.](README.md#DownloadFilesFromFolder) When all files are downloaded from a folder, the same folder structure of Google Drive is created to the local PC.
- ``$ ggsrun d -f folderName or folderId``
- When the project file is downloaded, it is downloaded as a zip file. All scripts in the project is put in the zip file.
- Also when you download a single project, you can use an option ``--zip`` or ``-z``. By this, the downloaded project is saved as a zip file.
- This new function can be also used for the shared folders. When you want to download the files from the shared folder, please use the folder ID of the shared folder.
1. The file list with the folder tree in the specific folder got to be able to be retrieved.
1. When the files are downloaded, the progression got to be able to be seen. When you want to see the progression, please use ``-j`` when you download files and folders.
1. Files with large size got to be able to be used. In order to download files with large size (several gigabytes), files are saved by chunks.
1. Some modifications.


**You can read "How to install" at [here](https://github.com/tanaikech/ggsrun/blob/master/README.md#How_to_Install).**

Expand Down
Binary file added help/images/downloadFolder_sample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion init.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@ func (a *AuthContainer) chkInitFile(file string) ([]byte, error) {
return body, err
}
}
return nil, fmt.Errorf("Error: %s was not found.\n", file)
return nil, fmt.Errorf("error: %s was not found", file)
}
12 changes: 8 additions & 4 deletions materials.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,12 @@ func (a *AuthContainer) defDownloadContainer(c *cli.Context) *utl.FileInf {
BoundScriptName: c.String("boundscriptname"),
WantExt: c.String("extension"),
WantName: c.String("filename"),
Progress: c.Bool("jsonparser"),
OverWrite: c.Bool("overwrite"),
RawProject: c.Bool("rawdata"),
ShowFileInf: c.Bool("showfilelist"),
Skip: c.Bool("skip"),
Zip: c.Bool("zip"),
}
return p
}
Expand All @@ -380,16 +386,14 @@ func (a *AuthContainer) defUploadContainer(c *cli.Context) *utl.FileInf {
ChunkSize: func(chnk int64) int64 {
if chnk < 1 {
return 1048576
} else {
return chnk * 1048576
}
return chnk * 1048576
}(c.Int64("chunksize")),
UpFilename: func(filenames string) []string {
if filenames != "" {
return regexp.MustCompile(`\s*,\s*`).Split(filenames, -1)
} else {
return nil
}
return nil
}(c.String("filename")),
ParentID: c.String("parentid"),
ProjectType: func(ptype string) string {
Expand Down
15 changes: 8 additions & 7 deletions oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ func (a *AuthContainer) getAtoken() *AuthContainer {
}
body, err := r.FetchAPI()
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v. ", err)
fmt.Fprintf(os.Stderr, "Error: %v. %s\n", err, body)
fmt.Println("Hint: If you use old ggsrun.cfg, please remove it and run 'ggsrun auth'. Then try again.")
os.Exit(1)
}
json.Unmarshal(body, &a.Atoken)
Expand Down Expand Up @@ -138,7 +139,7 @@ func (a *AuthContainer) chkRedirectURI() bool {
func (a *AuthContainer) getCode() (string, error) {
p := a.InitVal.Port
if !a.chkRedirectURI() {
return "", fmt.Errorf("Go manual mode.")
return "", fmt.Errorf("Go manual mode")
}
fmt.Printf("\n### This is a automatic input mode.\n### Please follow opened browser, login Google and click authentication.\n### It will move to a manual mode if you wait for 30 seconds under this situation.\n")
a.Cs.Cid.Redirecturis = append(a.Cs.Cid.Redirecturis, "http://localhost:"+strconv.Itoa(p)+"/")
Expand All @@ -164,7 +165,7 @@ func (a *AuthContainer) getCode() (string, error) {
code := r.URL.Query().Get("code")
if len(code) == 0 {
fmt.Fprintf(w, `<html><head><title>ggsrun status</title></head><body><p>Erorr.</p></body></html>`)
s.Response <- authCode{Err: fmt.Errorf("Not found code.")}
s.Response <- authCode{Err: fmt.Errorf("Not found code")}
return
}
fmt.Fprintf(w, `<html><head><title>ggsrun status</title></head><body><p>The authentication was done. Please close this page.</p></body></html>`)
Expand Down Expand Up @@ -195,19 +196,19 @@ func (a *AuthContainer) getCode() (string, error) {
case "windows":
cmd = exec.Command("cmd", "/c", "start", strings.Replace(codeurl, "&", `^&`, -1))
default:
return "", fmt.Errorf("Go manual mode.")
return "", fmt.Errorf("Go manual mode")
}
if err := cmd.Start(); err != nil {
return "", fmt.Errorf("Go manual mode.")
return "", fmt.Errorf("Go manual mode")
}
var result authCode
select {
case result = <-s.Response:
case <-time.After(time.Duration(30) * time.Second): // After 30 s, move to manual mode.
return "", fmt.Errorf("Go manual mode.")
return "", fmt.Errorf("Go manual mode")
}
if result.Err != nil {
return "", fmt.Errorf("Go manual mode.")
return "", fmt.Errorf("Go manual mode")
}
return result.Code, nil
}
Expand Down
11 changes: 5 additions & 6 deletions projectupdater.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ func (e *ExecutionContainer) projectUpdateControl(c *cli.Context) *utl.FileInf {
ProjectMaker().
projectUpdate2().
dispUpdateProjectContainer()
} else {
return e.defUpdateProjectContainer(c).
projectBackup(c).
filesInProjectRemover().
projectUpdate2().
dispUpdateProjectContainer()
}
return e.defUpdateProjectContainer(c).
projectBackup(c).
filesInProjectRemover().
projectUpdate2().
dispUpdateProjectContainer()
}
if c.Bool("rearrange") {
e.defUpdateProjectContainer(c).
Expand Down
19 changes: 7 additions & 12 deletions scriptrearrange.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ func (e *ExecutionContainer) rearrangeByTerminal() *ExecutionContainer {
s.Stop()
fmt.Printf("\n")
return e
} else {
e.Msg = append(e.Msg, "Scripts of project were NOT rearranged.")
return e
}
e.Msg = append(e.Msg, "Scripts of project were NOT rearranged.")
return e
}

// rearrange : Rearranging scripts in a project using a configuration file.
Expand Down Expand Up @@ -84,22 +83,18 @@ func (e *ExecutionContainer) rearrangeByFile(data []string) *ExecutionContainer
if cn == len(e.Project.Files) {
e.rearrange(baseProject, changedIndx)
return e
} else {
e.Msg = append(e.Msg, "Error: Script names of inputted file are different for script names in project.")
return e
}
} else {
e.Msg = append(e.Msg, "Error: Order of inputted file are the same to the order in project.")
e.Msg = append(e.Msg, "Error: Script names of inputted file are different for script names in project.")
return e
}
} else {
e.Msg = append(e.Msg, "Error: Number of script names of inputted file are different for number of scripts in project.")
e.Msg = append(e.Msg, "Error: Order of inputted file are the same to the order in project.")
return e
}
} else {
e.Msg = append(e.Msg, "Error: There are duplicated names in script names of inputted file.")
e.Msg = append(e.Msg, "Error: Number of script names of inputted file are different for number of scripts in project.")
return e
}
e.Msg = append(e.Msg, "Error: There are duplicated names in script names of inputted file.")
return e
}

// rearrange : Main method for rearranging scripts.
Expand Down
Loading

0 comments on commit c750803

Please sign in to comment.