Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
Poulpe
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
octobus
Poulpe
Commits
a5a4311d
Commit
a5a4311d
authored
3 years ago
by
Simon Sapin
Browse files
Options
Downloads
Patches
Plain Diff
Find and create a `tmp` directory in the source repo
parent
60d53e09
No related branches found
No related tags found
1 merge request
!1
Initial implementation
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.hgignore
+1
-0
1 addition, 0 deletions
.hgignore
src/main.rs
+56
-19
56 additions, 19 deletions
src/main.rs
with
57 additions
and
19 deletions
.hgignore
+
1
−
0
View file @
a5a4311d
^target/
^tmp/
This diff is collapsed.
Click to expand it.
src/main.rs
+
56
−
19
View file @
a5a4311d
use
dialoguer
::
console
::
style
;
use
dialoguer
::
Confirm
;
use
std
::
path
::
PathBuf
;
use
structopt
::
StructOpt
;
#[derive(StructOpt)]
...
...
@@ -7,5 +8,9 @@
NewDataset
{
directory
:
String
},
}
struct
Megafine
{
tmp_dir
:
PathBuf
,
}
type
Result
<
T
>
=
std
::
result
::
Result
<
T
,
Box
<
dyn
std
::
error
::
Error
>>
;
...
...
@@ -10,10 +15,21 @@
type
Result
<
T
>
=
std
::
result
::
Result
<
T
,
Box
<
dyn
std
::
error
::
Error
>>
;
fn
new_dataset
(
directory
:
String
)
->
Result
<
()
>
{
println!
(
"Creating a dataset from directory {}"
,
style
(
&
directory
)
.bold
()
);
if
!
std
::
fs
::
metadata
(
&
directory
)
?
.is_dir
()
{
Err
(
"Not a directory"
)
?
impl
Megafine
{
fn
new_dataset
(
&
self
,
directory
:
String
)
->
Result
<
()
>
{
println!
(
"Creating a dataset from directory {}"
,
style
(
&
directory
)
.bold
()
);
if
!
std
::
fs
::
metadata
(
&
directory
)
?
.is_dir
()
{
Err
(
"Not a directory"
)
?
}
let
proceed
=
Confirm
::
new
()
.with_prompt
(
"Continue?"
)
.default
(
false
)
.interact
()
?
;
if
!
proceed
{
Err
(
""
)
?
}
// TODO
Ok
(())
}
...
...
@@ -19,8 +35,27 @@
}
let
proceed
=
Confirm
::
new
()
.with_prompt
(
"Continue?"
)
.default
(
false
)
.interact
()
?
;
if
!
proceed
{
Err
(
""
)
?
fn
new
()
->
Result
<
Self
>
{
let
exe
=
std
::
fs
::
canonicalize
(
std
::
env
::
current_exe
()
?
)
?
;
// TODO: use a `try` block when available
// https://github.com/rust-lang/rust/issues/31436
let
find_repo
=
||
{
let
parent_1
=
exe
.parent
()
?
;
let
parent_2
=
parent_1
.parent
()
?
;
let
parent_3
=
parent_2
.parent
()
?
;
let
name_1
=
parent_1
.file_name
()
?
;
let
name_2
=
parent_2
.file_name
()
?
;
(
name_2
==
"target"
&&
(
name_1
==
"debug"
||
name_1
==
"release"
))
.then
(||
parent_3
)
};
let
repo
=
find_repo
()
.ok_or_else
(||
{
format!
(
"Couldn’t find megafine repository, executable is '{}'
\
instead of the expected target/{{debug,target}}/megafine"
,
exe
.display
()
)
})
?
;
let
tmp_dir
=
repo
.join
(
"tmp"
);
std
::
fs
::
create_dir_all
(
&
tmp_dir
)
?
;
Ok
(
Self
{
tmp_dir
})
}
...
...
@@ -26,6 +61,11 @@
}
// TODO
Ok
(())
fn
main
()
->
Result
<
()
>
{
let
megafine
=
Megafine
::
new
()
?
;
match
Args
::
from_args
()
{
Args
::
NewDataset
{
directory
}
=>
megafine
.new_dataset
(
directory
),
}
}
}
fn
main
()
{
...
...
@@ -29,10 +69,7 @@
}
fn
main
()
{
let
result
=
match
Args
::
from_args
()
{
Args
::
NewDataset
{
directory
}
=>
new_dataset
(
directory
),
};
match
result
{
match
Megafine
::
main
()
{
Ok
(())
=>
{}
Err
(
error
)
=>
{
let
message
=
error
.to_string
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment