-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
54768d7
commit 546b762
Showing
4 changed files
with
137 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package cli | ||
|
||
import ( | ||
"github.com/arelate/vangogh_local_data" | ||
"github.com/boggydigital/nod" | ||
"os" | ||
"strconv" | ||
"time" | ||
) | ||
|
||
// StaleDehydrations needs to be in cli to avoid import cycle | ||
func StaleDehydrations(fix bool) error { | ||
|
||
if err := staleDehydrationsImageType( | ||
vangogh_local_data.ImageProperty, | ||
vangogh_local_data.DehydratedImageModifiedProperty, fix); err != nil { | ||
return err | ||
} | ||
|
||
if err := staleDehydrationsImageType( | ||
vangogh_local_data.VerticalImageProperty, | ||
vangogh_local_data.DehydratedVerticalImageModifiedProperty, fix); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func staleDehydrationsImageType(imageProperty, dimProperty string, fix bool) error { | ||
|
||
sdia := nod.NewProgress("checking stale dehydrations for %s...", imageProperty) | ||
defer sdia.End() | ||
|
||
rxa, err := vangogh_local_data.ConnectReduxAssets(imageProperty, dimProperty) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
staleIds := make(map[string]bool) | ||
|
||
ids := rxa.Keys(imageProperty) | ||
sdia.TotalInt(len(ids)) | ||
|
||
for _, id := range ids { | ||
if imageId, ok := rxa.GetFirstVal(imageProperty, id); ok { | ||
imagePath, err := vangogh_local_data.AbsLocalImagePath(imageId) | ||
if err != nil { | ||
return sdia.EndWithError(err) | ||
} | ||
if stat, err := os.Stat(imagePath); err == nil { | ||
if dimStr, ok := rxa.GetFirstVal(dimProperty, id); ok { | ||
if dim, err := strconv.ParseInt(dimStr, 10, 64); err == nil { | ||
dimTime := time.Unix(dim, 0) | ||
imt := stat.ModTime() | ||
if imt.After(dimTime) { | ||
staleIds[id] = true | ||
} | ||
} | ||
} | ||
} | ||
} | ||
sdia.Increment() | ||
} | ||
|
||
if len(staleIds) == 0 { | ||
sdia.EndWithResult("all good") | ||
} else { | ||
sdia.EndWithResult("found %d stale dehydrations", len(staleIds)) | ||
if fix { | ||
imageType := vangogh_local_data.ImageTypeFromProperty(imageProperty) | ||
return Dehydrate(staleIds, []vangogh_local_data.ImageType{imageType}, false) | ||
} | ||
|
||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package cli | ||
|
||
import ( | ||
"github.com/arelate/vangogh_local_data" | ||
"github.com/boggydigital/nod" | ||
) | ||
|
||
func WishlistedOwned(fix bool) error { | ||
|
||
woa := nod.Begin("checking wishlisted owned products...") | ||
defer woa.End() | ||
|
||
rxa, err := vangogh_local_data.ConnectReduxAssets( | ||
vangogh_local_data.WishlistedProperty, | ||
vangogh_local_data.OwnedProperty) | ||
|
||
if err != nil { | ||
return woa.EndWithError(err) | ||
} | ||
|
||
woid := make([]string, 0) | ||
|
||
for _, id := range rxa.Keys(vangogh_local_data.WishlistedProperty) { | ||
// only check actually wishlisted products, not just any wishlisted state | ||
if rxa.HasVal(vangogh_local_data.WishlistedProperty, id, vangogh_local_data.FalseValue) { | ||
continue | ||
} | ||
if rxa.HasVal(vangogh_local_data.OwnedProperty, id, vangogh_local_data.TrueValue) { | ||
woid = append(woid, id) | ||
} | ||
} | ||
|
||
if len(woid) > 0 { | ||
woa.EndWithResult("found %d product(s)", len(woid)) | ||
|
||
if fix { | ||
rwoa := nod.Begin(" removing products from wishlist...") | ||
|
||
if err := Wishlist(nil, woid); err != nil { | ||
return rwoa.EndWithError(err) | ||
} | ||
|
||
rwoa.EndWithResult("done") | ||
} | ||
|
||
} else { | ||
woa.EndWithResult("all good") | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters