Merge branch 'main' of gitea.opawilly.goip.de:steffen/scripts
This commit is contained in:
commit
9a713a07cb
5 files changed
+343
-1
No files matched your search
+1
-1
@@ -133,4 +133,4 @@ $lin =~ s/\),$/\);/;
|
||||
|
||||
write_file('cx.sql', $lin);
|
||||
|
||||
1;
|
||||
1;
|
||||
@@ -0,0 +1,101 @@
|
||||
#!/perl -w
|
||||
use warnings;
|
||||
use File::Slurp qw(:std);
|
||||
use File::stat;
|
||||
use File::Path qw(make_path);
|
||||
# use IO::Socket::SSL;
|
||||
use LWP::UserAgent;
|
||||
use Data::Printer;
|
||||
use Crypt::SSLeay;
|
||||
use Net::SSL;
|
||||
#use Win32::File::VersionInfo;
|
||||
use POSIX qw(strftime);
|
||||
|
||||
$ENV{PERL_NET_HTTPS_SSL_SOCKET_CLASS} = "Net::SSL";
|
||||
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
|
||||
$| = 1;
|
||||
|
||||
my $bib = {
|
||||
'autofill' => 'AutoFill',
|
||||
'buttons' => 'Buttons',
|
||||
'select' => 'Select',
|
||||
'staterestore' => 'StateRestore',
|
||||
'scroller' => 'Scroller',
|
||||
'searchbuilder' => 'SearchBuilder',
|
||||
'searchpanes' => 'SearchPanes',
|
||||
'rowreorder' => 'RowReorder',
|
||||
'responsive' => 'Responsive',
|
||||
'rowgroup' => 'RowGroup',
|
||||
'colreorder' => 'ColReorder',
|
||||
'fixedcolumns' => 'FixedColumns',
|
||||
'keytable' => 'KeyTable',
|
||||
'fixedheader' => 'FixedHeader',
|
||||
'datetime' => 'Datetime',
|
||||
};
|
||||
|
||||
my @dateien;
|
||||
|
||||
my $downloadfolder = 'D:\\wsldata\\htlib\\jquery-datatables';
|
||||
|
||||
my $ua = LWP::UserAgent->new(timeout => 10);
|
||||
$ua->agent('Mozilla/5.0');
|
||||
$ua->show_progress( 1 );
|
||||
|
||||
my $response = $ua->get( 'https://cdn.datatables.net/');
|
||||
my @releases = $response->as_string =~ /href="(.*)">Release notes/g;
|
||||
|
||||
for my $rel ( @releases ) {
|
||||
my $folder = $rel =~ s/\/\/cdn.datatables.net\///r;
|
||||
my @urlsplit = split('/', $folder);
|
||||
|
||||
$folder = $folder =~ s/\//\\\\/gr;
|
||||
|
||||
if ( $urlsplit[0] !~ /^\d*\.\d*\.\d*$/ ) {
|
||||
if ( $bib->{$urlsplit[0]} ) {
|
||||
$folder = $folder =~ s/$urlsplit[0]/$bib->{$urlsplit[0]}/r;
|
||||
}
|
||||
|
||||
$folder = 'extensions\\'. $folder;
|
||||
}
|
||||
if ( !-e $downloadfolder.'\\'. $folder) {
|
||||
my $response = $ua->get( 'https://cdn.datatables.net/'. $rel);
|
||||
my @files = $response->as_string =~ /<a href="(.*)">\/\//g;
|
||||
for my $f ( @files ) {
|
||||
if ( $f !~ /mjs$|json$/ ) {
|
||||
push @dateien, $f;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$folder = $folder =~ s/\\\\$//rg;
|
||||
$folder = $folder =~ s/\\\\/\\/rg;
|
||||
print "$folder -> aktuell\n";
|
||||
}
|
||||
}
|
||||
|
||||
for my $da ( @dateien ) {
|
||||
next if $da !~ /cdn\.datatables\.net/ or $da =~ /mjs$/ ;
|
||||
my $folder = $da =~ s/\/\/cdn.datatables.net\///r;
|
||||
my @urlsplit = split('/', $folder);
|
||||
my $file = $urlsplit[-1];
|
||||
|
||||
$folder = $folder =~ s/$file//r;
|
||||
$folder = $folder =~ s/\//\\\\/gr;
|
||||
|
||||
if ( $urlsplit[0] !~ /^\d*\.\d*\.\d*$/ ) {
|
||||
if ( $bib->{$urlsplit[0]} ) {
|
||||
$folder = $folder =~ s/$urlsplit[0]/$bib->{$urlsplit[0]}/r;
|
||||
}
|
||||
|
||||
$folder = 'extensions\\'. $folder;
|
||||
}
|
||||
#
|
||||
if ( !-e $downloadfolder.'\\'. $folder.$file) {
|
||||
make_path( $downloadfolder.'\\'. $folder );
|
||||
my $response = $ua->get( 'https:'. $da, ':content_file' => $downloadfolder.'\\'. $folder.$file);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
system("pause");
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,124 @@
|
||||
#!/perl -w
|
||||
use warnings;
|
||||
use File::Slurp qw(:std);
|
||||
use File::stat;
|
||||
use File::Path;
|
||||
use Archive::Zip; # imports
|
||||
# use IO::Socket::SSL;
|
||||
use LWP::UserAgent;
|
||||
use Data::Printer;
|
||||
use Crypt::SSLeay;
|
||||
use Net::SSL;
|
||||
use Mojo::UserAgent;
|
||||
use JSON;
|
||||
|
||||
$ENV{PERL_NET_HTTPS_SSL_SOCKET_CLASS} = "Net::SSL";
|
||||
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
|
||||
|
||||
my $delzip = 0;
|
||||
my @folders = (
|
||||
'D:\\vsc\\vs-codium\\',
|
||||
'D:\\vsc\\vs-codium-local\\'
|
||||
);
|
||||
|
||||
for my $f ( @folders ) {
|
||||
mkdir $f unless -d $f;
|
||||
}
|
||||
|
||||
my $ua = Mojo::UserAgent->new();
|
||||
$ua->max_redirects(5);
|
||||
my $res = $ua->insecure(1)->get('https://github.com/VSCodium/vscodium/releases')->result->body;
|
||||
# write_file('test.html', $res);
|
||||
|
||||
# my $res = read_file('test.html');
|
||||
my $downloadfolder = 'D:\\Downloads\\';
|
||||
my $filename = 'vscodium.zip';
|
||||
|
||||
my @url = $res =~ /"(https:\/\/.*win32-x64.*zip?)"/g;
|
||||
print "downloade VS-Codium Version: $url[0]\n";
|
||||
|
||||
if ( -e $downloadfolder.$filename ) {
|
||||
print "entferne $downloadfolder$filename\n";
|
||||
unlink("$downloadfolder.$filename");
|
||||
}
|
||||
|
||||
my $tx = $ua->insecure(1)->get( $url[0] );
|
||||
$tx->res->content->asset->move_to( $downloadfolder.$filename);
|
||||
|
||||
# löschen aller Cached Dateien und Unterordner
|
||||
my @cacheddir = qw(Cache GPUCache CachedData CachedData-x64);
|
||||
|
||||
|
||||
if ( -e $downloadfolder.$filename ) {
|
||||
for my $fold ( @folders ) {
|
||||
opendir (my $dh, $fold);
|
||||
print "$fold --> ";
|
||||
my @fol = readdir $dh;
|
||||
|
||||
my $test = 1;
|
||||
if ( -e $fold.'VSCodium.exe' ) {
|
||||
$test = unlink($fold.'VSCodium.exe');
|
||||
}
|
||||
|
||||
if ( $test == 1 ) {
|
||||
for my $d ( @fol ) {
|
||||
if ( $d =~ /^\.|^\.\./ ) {
|
||||
next;
|
||||
}
|
||||
|
||||
if ( -d "$fold$d" ) {
|
||||
if ( $d ne 'data' ) {
|
||||
rmtree("$fold$d");
|
||||
} else {
|
||||
# Cache löschen
|
||||
print "leere";
|
||||
for my $cdir ( @cacheddir ) {
|
||||
print " $cdir";
|
||||
rmtree( "$fold$d\\user-data\\$cdir", {keep_root => 1} );
|
||||
}
|
||||
}
|
||||
} else{
|
||||
unlink("$fold$d");
|
||||
}
|
||||
}
|
||||
print "--> geloescht, Userdaten behalten\n";
|
||||
$delzip++;
|
||||
}
|
||||
}
|
||||
|
||||
my $obj = Archive::Zip->new(); # new instance
|
||||
my $status = $obj->read("$downloadfolder$filename"); # read file contents
|
||||
|
||||
if ($status != 0) {
|
||||
die('Error in file!');
|
||||
} else {
|
||||
if ( scalar @folders == $delzip ) {
|
||||
for my $f ( @folders ) {
|
||||
print "entpacke neue Version in $f\n";
|
||||
$obj->extractTree(undef, $f); # extract files
|
||||
}
|
||||
unlink("$downloadfolder$filename");
|
||||
print "zip datei von VSCode gelöscht\n";
|
||||
} else {
|
||||
print "zip nicht gelöscht da nicht alle Ordner verarbeitet wurden\n";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
print "keine neue Version gefunden\n";
|
||||
}
|
||||
|
||||
for my $fold ( @folders ) {
|
||||
my $prodjson = $fold.'\\resources\\app\\product.json';
|
||||
# "serviceUrl": "https://marketplace.visualstudio.com/_apis/public/gallery",
|
||||
# "itemUrl": "https://marketplace.visualstudio.com/items",
|
||||
if ( -e $prodjson ) {
|
||||
my $pro = decode_json(read_file($prodjson));
|
||||
$pro->{extensionsGallery}->{serviceUrl} = "https://marketplace.visualstudio.com/_apis/public/gallery";
|
||||
$pro->{extensionsGallery}->{itemUrl} = "https://marketplace.visualstudio.com/items";
|
||||
write_file($prodjson, to_json($pro, { pretty => 1}) );
|
||||
}
|
||||
}
|
||||
|
||||
system("pause");
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,117 @@
|
||||
import os, sys
|
||||
import re
|
||||
import json
|
||||
import shutil
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from zipfile import ZipFile
|
||||
import urllib3
|
||||
|
||||
urllib3.disable_warnings()
|
||||
|
||||
folders = [
|
||||
r'D:\\vsc\\vs-codium\\',
|
||||
r'D:\\vsc\\vs-codium-local\\'
|
||||
]
|
||||
|
||||
download_folder = r'D:\\Downloads\\'
|
||||
filename = 'vscodium.zip'
|
||||
|
||||
# Ordner anlegen, falls nicht vorhanden
|
||||
for f in folders:
|
||||
os.makedirs(f, exist_ok=True)
|
||||
|
||||
# Aktuelle Download-URL ermitteln
|
||||
res = requests.get('https://github.com/VSCodium/vscodium-insiders/tags')
|
||||
soup = BeautifulSoup(res.text, 'html.parser')
|
||||
|
||||
# with open("updatevscodium.html", "w", encoding="utf-8") as f:
|
||||
# f.write( soup.prettify() )
|
||||
|
||||
urls = re.findall(r'/VSCodium/vscodium-insiders/releases/tag/(.*)-insider', soup.prettify())
|
||||
|
||||
if not urls:
|
||||
print("Keine neue Version gefunden.")
|
||||
exit()
|
||||
|
||||
# Aktuelle Download-URL ermitteln
|
||||
print(f"https://github.com/VSCodium/vscodium-insiders/releases/download/{urls[0]}-insider/VSCodium-win32-x64-{urls[0]}-insider.zip")
|
||||
|
||||
|
||||
zip_path = os.path.join(download_folder, filename)
|
||||
|
||||
if os.path.exists(zip_path):
|
||||
print(f"Entferne {zip_path}")
|
||||
os.remove(zip_path)
|
||||
|
||||
# Datei herunterladen
|
||||
r = requests.get(f"https://github.com/VSCodium/vscodium-insiders/releases/download/{urls[0]}-insider/VSCodium-win32-x64-{urls[0]}-insider.zip", stream=True, verify=False)
|
||||
with open(zip_path, 'wb') as f:
|
||||
for chunk in r.iter_content(chunk_size=8192):
|
||||
f.write(chunk)
|
||||
|
||||
# Cachedaten löschen
|
||||
cache_dirs = ['Cache', 'GPUCache', 'CachedData', 'CachedData-x64']
|
||||
|
||||
delete_count = 0
|
||||
if os.path.exists(zip_path):
|
||||
si = os.path.getsize(zip_path)
|
||||
|
||||
if si < 20:
|
||||
print("Zip ist zu klein")
|
||||
sys.exit(1)
|
||||
|
||||
print(si)
|
||||
|
||||
for f in folders:
|
||||
print(f"{f} --> ")
|
||||
|
||||
if os.path.exists(os.path.join(f, 'VSCodium.exe')):
|
||||
os.remove(os.path.join(f, 'VSCodium.exe'))
|
||||
|
||||
for item in os.listdir(f):
|
||||
path = os.path.join(f, item)
|
||||
|
||||
if os.path.isdir(path):
|
||||
if item != 'data':
|
||||
shutil.rmtree(path)
|
||||
else:
|
||||
print("Leere", end=' ')
|
||||
for cache in cache_dirs:
|
||||
cache_path = os.path.join(path, 'user-data', cache)
|
||||
print(cache, end=' ')
|
||||
if os.path.exists(cache_path):
|
||||
shutil.rmtree(cache_path, ignore_errors=True)
|
||||
else:
|
||||
os.remove(path)
|
||||
|
||||
print("--> gelöscht, Userdaten behalten")
|
||||
delete_count += 1
|
||||
|
||||
# Entpacken
|
||||
if delete_count == len(folders):
|
||||
for f in folders:
|
||||
print(f"Entpacke neue Version in {f}")
|
||||
with ZipFile(zip_path, 'r') as zip_ref:
|
||||
zip_ref.extractall(f)
|
||||
os.remove(zip_path)
|
||||
print("ZIP Datei von VSCodium gelöscht")
|
||||
else:
|
||||
print("ZIP nicht gelöscht, da nicht alle Ordner verarbeitet wurden")
|
||||
|
||||
# product.json anpassen
|
||||
for f in folders:
|
||||
prod_json = os.path.join(f, 'resources', 'app', 'product.json')
|
||||
if os.path.exists(prod_json):
|
||||
with open(prod_json, 'r', encoding='utf-8') as pj:
|
||||
data = json.load(pj)
|
||||
|
||||
data['extensionsGallery'] = {
|
||||
'serviceUrl': 'https://marketplace.visualstudio.com/_apis/public/gallery',
|
||||
'itemUrl': 'https://marketplace.visualstudio.com/items'
|
||||
}
|
||||
|
||||
with open(prod_json, 'w', encoding='utf-8') as pj:
|
||||
json.dump(data, pj, indent=4)
|
||||
|
||||
input("Fertig. Beliebige Taste drücken...")
|
||||
Reference in new issue
Block a user