PowerShell to zip WordPress plugin - wordpress

I have a folder containing the code for a WordPress plugin, and the following script:
$folder = Join-Path $PSScriptRoot $pluginName
$destination = Join-Path $PSScriptRoot "bundles/$pluginName.zip"
Add-Type -AssemblyName "System.IO.Compression.FileSystem"
if (Test-Path $destination) {
Remove-Item $destination
}
[IO.Compression.ZipFile]::CreateFromDirectory(
$folder,
$destination,
[IO.Compression.CompressionLevel]::Optimal,
$true # include base directory
)
If I try to install the plugin by uploading the produced zip file to a local WordPress instance, I get the following errors:
Warning: copy(/var/www/html/wp-content/plugins/jwt-authentication-for-wp-rest-api/jwt-authentication-for-wp-rest-api\jwt-auth.php): failed to open stream: Invalid argument in /var/www/html/wp-admin/includes/class-wp-filesystem-direct.php on line 257
Warning: copy(/var/www/html/wp-content/plugins/jwt-authentication-for-wp-rest-api/jwt-authentication-for-wp-rest-api\jwt-auth.php): failed to open stream: Invalid argument in /var/www/html/wp-admin/includes/class-wp-filesystem-direct.php on line 257
Could not copy file. /var/www/html/wp-content/plugins/jwt-authentication-for-wp-rest-api/jwt-authentication-for-wp-rest-api\jwt-auth.php
Plugin install failed.
However, if I manually zip the plugin, by right-clicking the plugin folder in Windows Explorer and choosing "Send to..." -> "Compressed folder", the generated zip file installs fine.
I can't figure out why this happens, because if I unzip the folders and diff their contents, they are identical. (The zipped files are not, but I assume that's because of compression levels etc).
Do I have to set any specific flags when zipping to make this work? How do I script production of a zip file that works exactly like "Send to..." -> "Compressed folder"?

Related

How do I install custom fonts in shinyapps.io apps?

This question relates to an answer given by Yihui here:
https://groups.google.com/g/shinyapps-users/c/0czcsM4vziM/m/GNuyL3ClCgAJ
In the instruction, it says to:
dir.create('~/.fonts')
Download the fonts, e.g. via download.file(), to ~/.fonts
Run system('fc-cache -f ~/.fonts')
I've put this into my .app code (just after all my library() calls) before trying to deploy the app to shinapps.io.:
dir.create('~/.fonts')
download.file('https://github.com/**MY USERNAME**/fonts', '~/.fonts')
system('fc-cache -f ~/.fonts')
As you can see, I have put all the fonts the app requires into a public repo on my github account. This is the URL that the font .ttf files are from. However, i think i may have misunderstood the directions, as i get this error from shinyapps.io:
Error in value[[3L]](cond) : Error sourcing /srv/connect/apps/font/app.R
Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
Execution halted
The fonts I wish to use are derivations of the "Sarabun" and "Garamond" families.
Please can someone provide more detail to Yihui's solution? Any help would be greatly appreciated. If you also have another solution that would be good to hear. However, please note that 'font style packages' tend not to work with shinyapps.io as these look locally for the styles, which defeats the purpose of it! Additionally, I wish to use a specific .ttf file.
Cheers all,
Matt
The URL https://github.com/**MY USERNAME**/fonts points to a repository overview, not the folder itself, so maybe you are downloading just the HTML page on that URL.
You need to download the archive depending on your OS (ZIP on Windows, .TAR.GZ on Unix-alike).
download.file("https://github.com/**USERNAME**/fonts/archive/master.tar.gz", destfile = "fonts.tar.gz")
# or ZIP file on Windows
download.file("https://github.com/**USERNAME**/fonts/archive/master.zip", destfile = "fonts.zip")
Then you have to extract the archive:
untar("fonts.tar.gz", exdir = "~/.fonts/")
# or with ZIP file on Windows
unzip("fonts.zip", exdir = "~/.fonts/")
Then you can use that in your script:
system('fc-cache -f ~/.fonts')
I hope the way is clear as it may vary depending on your OS, fonts and subfolders etc... Something like that should work.

Uploading release asset to Github is corrupting file

I am trying to automate our Github release process, and as part of it I am uploading release artifacts to Github release. Artifact I am uploading is a tar.gz file. I am using following python3.7 code to upload the artifact:
with open(filepath, 'rb') as file:
response = self._request_session.post(endpoint,
params={'name': local_artifact.filename},
files={local_artifact.filename: file})
Response status code I am getting is 201, which is expected as per Github upload release asset api documentation.
However, when I am downloading artifacts from Github, I am neither able to validate sha256 of the file, nor I am able open the tarball. On running tar -zxvf test.tar.gz I am getting following error:
tar: Unrecognized archive format
tar: Error exit delayed from previous errors.
I have already tested the file on local which I am uploading and that is working fine.
Can anyone please help me in identifying the problem here?
Here is response text I get after uploading file:
{
"url":"https://api.github.com/repos/c2tarun/upload_test_repo/releases/assets/17244134",
"id":17244134,
"node_id":"MDEyOlJlbGVhc2VBc3NldDE3MjQ0MTM0",
"name":"test.tar.gz",
"label":"",
"uploader":{
"login":"c2tarun",
"id":1129670,
...truncating for readability.
"type":"User",
"site_admin":false
},
"content_type":"multipart/form-data; boundary=1a13638ee5f5f57d303508eea4e64211",
"state":"uploaded",
"size":11969682,
"download_count":0,
"created_at":"2020-01-09T23:49:54Z",
"updated_at":"2020-01-09T23:50:18Z",
"browser_download_url":"https://github.com/c2tarun/upload_test_repo/releases/download/untagged-1baa5c7dd7f5a8d506cc/test.tar.gz"
}
Interesting update: Uploading same file multiple times, gives me different sha on downloading.
More Update: I thought that may be I am providing wrong Content-Type header for tar.gz file, so I created a zip file and used Content-Type as application/zip. I am still seeing same issue. Here are my request headers for zip file:
{
'User-Agent':'python-requests/2.22.0',
'Accept-Encoding':'gzip, deflate',
'Accept':'*/*',
'Connection':'keep-alive',
'Content-Type':'application/zip',
'Content-Length':'332',
'Authorization':'Basic xxxxxxxxx'
}
Thanks
You should set the Content-Type is 'application/tar+gzip' or debug with
file --mime-type -b test.tar.gz
command.

Firebase error: symbolFileMappings:upsert: The uploaded file is not a valid Breakpad Symbol file

I am trying to upload a dSYM file to Firebase using this command:
./Pods/FirebaseCrash/batch-upload -i ./Info.plist -p ./GoogleService-Info.plist ./service-accounts/mtb.json 78*****C-5**4-3***-***C-00*********7
But each time I run this, I get back the following errors
./Pods/FirebaseCrash/upload-sym-util.bash:377: error: symbolFileMappings:upsert: The uploaded file is not a valid Breakpad Symbol file.
./Pods/FirebaseCrash/upload-sym-util.bash:378: note: symbolFileMappings:upsert: The metadata for the symbol file failed to update.
I have tried this link https://groups.google.com/forum/#!msg/firebase-talk/4829Sp1_uKY/IEC_T4-VBAAJ but haven't had any luck as it errors out to
usage: batch-upload [-hv] [-p google-service] [-i info] service-account-file {mach-o file|uuid}
Can someone help me on this one please?
Thanks
Apparently this bug relates to batch-upload script having problems with archives, so you would need to patch it manually.
Try the following:
Change extract_symbols_and_upload "$EXE" "$ARCH" "$BUNDLE" to
extract_symbols_and_upload "$EXE" "$ARCH" "$BUNDLE/$BNDL_PATH"
The dump_syms utility understands dSYM bundles but not archives,
curiously enough. This fix will go out with the next release.
Source

R error when using untar

I'm running a script with input parameters that are referenced in the code to automate the directory creation, download of file and untar of file. I would be fine with unzip, however this particular file I want to analyze is .tar.gz. I manually unpacked and it was tar.gz, unpacked to .tar file. Would that be the problem?
Full error: Error in untar2(tarfile, files, list, exdir) : unsupported entry type ‘’
Running Windows 10, 64 bit, R set to: [Default] [64-bit] C:\Program Files\R\R-3.2.2
Script notes one solution found (issues, lines 28-31), but I don't really understand it.
I did install 7-zip on my computer, restart and of course restart R:
`#DOWNLOADING AND UNZIPPING TAR FILE
#load required packages.
#If there is a load package error, use install.packages("[package]")
library(dplyr)
library(lubridate)
library(XML) # HTML processing
options(stringsAsFactors = FALSE)
#Set directory locations, data file and fetch data file from internet
#enter full url including file name between ' ' marks
mainDir<-"C:/R/BEES/"
subDir<-"C:/R/BEES/Killers"
Fetch<-'http://dds.cr.usgs.gov/pub/data/nationalatlas/afrbeep020_nt00218.tar.gz'
ArchFile<-basename(Fetch)
download.file<-(ArchFile)
#Check for file directories and create if directory if it doesn't exist
if(!file.exists(mainDir)){dir.create(mainDir)}
if(!file.exists(subDir)){dir.create(subDir)}
#set the working directory
setwd(file.path(subDir))
#check if file exists and download if it doesn't exist.
if(!file.exists(ArchFile))
{download.file (url=Fetch,destfile=ArchFile,method='auto')}
#unpack and view file list
untar(path.expand(ArchFile),list=TRUE,exdir=subDir,compressed="gzip")
list.files(subDir)
#Error: Error in untar2(tarfile, files, list, exdir) :
# unsupported entry type ‘’
#Need solution to use tar/untar app
#instructions here: https://stevemosher.wordpress.com/step-10-build/`
Appreciate feedback - I've been lurking around StackOverflow for some time to use other people's solutions.

"IOError: No egg-info directory found" with paster on Plone 4.3.3

The error occurs also when using zopeskel in Plone 4.3.3. This seem to be slightly different from this question. Under Plone 4.3.2 there is no error.
$ ../bin/paster create plone_basic
Selected and implied templates:
PasteScript#basic_package A basic setuptools-enabled package
Variables:
egg: plone_basic
package: plone_basic
project: plone_basic
Enter version (Version (like 0.1)) ['']:
Enter description (One-line description of the package) ['']:
Enter long_description (Multi-line description (in reST)) ['']:
Enter keywords (Space-separated keywords/tags) ['']:
Enter author (Author name) ['']:
Enter author_email (Author email) ['']:
Enter url (URL of homepage) ['']:
Enter license_name (License name) ['']:
Enter zip_safe (True/False: if the package can be distributed as a .zip file) [False]:
Creating template basic_package
Creating directory ./plone_basic
Recursing into +package+
Creating ./plone_basic/plone_basic/
Copying __init__.py to ./plone_basic/plone_basic/__init__.py
Copying setup.cfg to ./plone_basic/setup.cfg
Copying setup.py_tmpl to ./plone_basic/setup.py
Running /home/Plone-4.3.3/Python-2.7/bin/python setup.py egg_info
Traceback (most recent call last):
File "/home/Plone-4.3.3/zeocluster/bin/paster", line 259, in <module>
sys.exit(paste.script.command.run())
File "/home/Plone-4.3.3/buildout-cache/eggs/PasteScript-1.7.5-py2.7.egg/paste/script/command.py", line 104, in run
invoke(command, command_name, options, args[1:])
File "/home/Plone-4.3.3/buildout-cache/eggs/PasteScript-1.7.5-py2.7.egg/paste/script/command.py", line 143, in invoke
exit_code = runner.run(args)
File "/home/Plone-4.3.3/buildout-cache/eggs/PasteScript-1.7.5-py2.7.egg/paste/script/command.py", line 238, in run
result = self.command()
File "/home/Plone-4.3.3/buildout-cache/eggs/PasteScript-1.7.5-py2.7.egg/paste/script/create_distro.py", line 170, in command
egg_info_dir = pluginlib.egg_info_dir(output_dir, dist_name)
File "/home/Plone-4.3.3/buildout-cache/eggs/PasteScript-1.7.5-py2.7.egg/paste/script/pluginlib.py", line 135, in egg_info_dir
% ', '.join(all))
IOError: No egg-info directory found (looked in ./plone_basic/./plone_basic.egg-info, ./plone_basic/setup.py/plone_basic.egg-info, ./plone_basic/plone_basic/plone_basic.egg-info, ./plone_basic/setup.cfg/plone_basic.egg-info)
workaround 1:
The problem seems to be the missing setuptools. After installing setuptools, then paster (and all tools based on it) can run the generated setup.py. The following fixed the problem:
wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py -O - | sudo -u plone_buildout /usr/local/Plone-4.3.3/Python-2.7/bin/python
UnifiedInstaller-4.3.3 doesn't install setuptools. See this ticket.
As SteveM points out (see comments) this is not a recommended workaround.
(prefered) workaround 2:
The generated data is there (despite the thrown error!) but setup.py will not run. Thus the Paste* directories will not be generated. Later when buildout runs it will generate/download the Paste* directories etc.
If you want setup.py to be run. You could patch PasteScript (at your own risk!).
As for PasteScript-1.7.5 go to line #587 of /path/to/Plone-4.3.3/buildout-cache/eggs/PasteScript-1.7.5-py2.7.egg/paste/script/command.py and get the current sys.path and pass it to subprocess.Popen(). This way the setup.py will run with the zopeskel or paste environment.
current_env = os.environ.copy()
current_env['PYTHONPATH'] = ':'.join(sys.path)
proc = subprocess.Popen([cmd] + list(args),
cwd=cwd,
stderr=stderr_pipe,
stdout=subprocess.PIPE,
env=current_env) # <- pass the env here
I'll try to figure out situations where this workaround could cause problems. I've posted an issue on PasteScript: https://bitbucket.org/ianb/pastescript/issue/16/pass-the-syspath-to-the-subprocess-in
Update: without generating/adding the Paste* dirs (either running buildout or by workaround as above) localcommands won't be available.

Resources